Drew a sun, can't figure out how to remove outer black shadow

Posted by Wuggly on Sat 07 May 2016 02:49 PM — 5 posts, 21,423 views.

USA #0
Hello again,

Recently, I've tried drawing a Sun using this thread as a reference.
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=9303

However, I can't seem to figure out how to get rid of the black shadow around the outer edge of it.

I want to be able to keep the inner shadow part of it.

Reason I need it like this is because I have it transparent and it looks a bit funky with that shadow on the outer part.

I've tried quite a few things to fix this, but can't seem to figure it out. Or maybe I've been at this for too long and my brain is scrambled stuck thinking down one direction.


-- main result window
win5 = GetPluginID () .. ".5" 
WindowCreate (win5, 0, 0, 20, 20, 7, 4, 0x000000)  -- create window
 

-- gradient window
win6 = GetPluginID ()  .. ".6"
WindowCreate (win6, 0, 0, 20, 20, 7, 4, ColourNameToRGB("white"))  -- create window

WindowGradient (win6, 0, 0, 0, 0, 
                ColourNameToRGB ("yellow"), 
                ColourNameToRGB ("red"), 
                2)  -- top to bottom
				
-- mask window
win7 = GetPluginID ()  .. ".7"
WindowCreate (win7, 0, 0, 20, 20, 7, 4, ColourNameToRGB("black"))  -- create window


-- chord
WindowCircleOp (win7, 4, 0, 0, 20, 20, 
                ColourNameToRGB("black"), 5, 0,  -- no pen
                ColourNameToRGB("white"), 0,  -- brush
                0, 0)

-- convert to images
WindowImageFromWindow (win5, "gradient", win6)
WindowImageFromWindow (win5, "mask", win7)

-- do the merge
WindowMergeImageAlpha (win5, "gradient", "mask", 0, 1, 20, 20, 0, 1, 0, 0, 0, 0)

WindowFilter (win5, 0, 0, 0, 0, 3, 0) -- blur both directions
WindowShow (win5,  true)  -- show it
Australia Forum Administrator #1
I can't see what you mean. When I tried that code (my background is normally black) the sun looks fine.

Amended on Sat 07 May 2016 10:20 PM by Nick Gammon
USA #2
Yes, it looks fine on a black background, but I have an image for my background that is not a solid black. Here's a screenshot so you can see what I mean.

http://i.imgur.com/5ZdKcqx.png

It's a little squished in that as I was trying to cut off the outer shadow parts.

I'm thinking maybe make another mini-window with a circleop, inside being transparent, and just putting it over top of it, but I feel like there is a better way.

EDIT: Oh by the way, that isn't a star next to it, it's a compass rose I'm also working on building. I still have yet to add 4 more small diagonal arrows and a couple skinny circles. That's going to be what shows my room exits. So say there is a north and east exit, the north and east arrows will change colour to show those directions are open. It's functional, but my end game goal on it is to make it glow instead of changing colours.
Amended on Sat 07 May 2016 10:33 PM by Wuggly
Australia Forum Administrator #3
I got a better result using this:



-- main result window
win5 = GetPluginID () .. ".5" 
WindowCreate (win5, 0, 0, 40, 40, miniwin.pos_center_right, miniwin.create_transparent, ColourNameToRGB("darkgray"))  -- create window
 

-- gradient window
win6 = GetPluginID ()  .. ".6"
WindowCreate (win6, 0, 0, 40, 40, miniwin.pos_center_right, miniwin.create_transparent, 0)  -- create window

WindowGradient (win6, 0, 0, 0, 0, 
                ColourNameToRGB ("yellow"), 
                ColourNameToRGB ("red"), 
                miniwin.gradient_vertical)  -- top to bottom
				
-- mask window
win7 = GetPluginID ()  .. ".7"
WindowCreate (win7, 0, 0, 40, 40, miniwin.pos_center_right, miniwin.create_transparent, 0)  -- create window


-- ellipse
WindowCircleOp (win7, miniwin.circle_ellipse, 5, 5, 25, 25, 
                ColourNameToRGB("black"), miniwin.pen_null, 0,  -- no pen
                ColourNameToRGB("white"), miniwin.brush_solid)  -- brush

-- blur ellipse
WindowFilter (win7, 0, 0, 0, 0, miniwin.filter_blur, 0) -- blur both directions

-- convert to images
WindowImageFromWindow (win5, "gradient", win6)
WindowImageFromWindow (win5, "mask", win7)

-- do the merge
WindowMergeImageAlpha (win5, "gradient", "mask", miniwin.merge_straight, 1, 40, 40, 0, 1)

WindowFilter (win5, 0, 0, 0, 0, miniwin.filter_blur, 0) -- blur both directions
WindowShow (win5,  true)  -- show it


The important part was making the background not black, but matching the output window (in my case, darkgray). You seem to be using an image, but if you get something that is close to the underlying colour it should look better.

Also I would use the symbolic constants (as I have above) rather than sprinking lots of "magic numbers" in the code, which you will always have to look up to see what they mean.
Amended on Sun 08 May 2016 06:08 AM by Nick Gammon
Australia Forum Administrator #4
Just to explain a bit more...

When you make a miniwindow with transparent mode, all that does is allow it to be merged with the main output window with an on/off test: Does a pixel in the miniwindow equal the background colour? Yes/No.

This lets you have odd-shaped windows, but you can't blend (smoothly) from a miniwindow to the main window because it isn't an alpha channel with 256 levels of blending. It's on/off.

So even if you make a nice smooth alpha transition in the miniwindow from the sun to the background, when that is copied to the main window (they way you did it) then pure black becomes transparent, and anything else (even slightly less black) becomes opaque. Thus you got the hard edges.