Re: semicircle

Search this archive.

From: ivan (ivan@svgalib.org)
Date: Tue 30 Nov 1999 - 13:49:17 IST


At 08:36 30/11/99 +0200, Emilian URSU wrote:
>
>
>
>What you said draws a semicircle and it's good
>but I need to fill it with another color than background...
>what can you tell me about that ?

the -easiest- way to fill any shape is to start at a point that is just
outside of the maximum dimensions of the shape and from that point search
for the start of the bounding line.

having found the bounding line, skip over the pixels that make up the
boundary and then fill every pixel after that until you reach the next
boundary. go back to your starting point and move one pixel away and start
again.

so, for a circle of 150 pixel diameter located at (100,100), for example,
the pseudo-code would be something like:

y = 20

while y < 180

	x = 20

	while pixel color at point (x,y) != boundary color
		increment x
	end while

	while pixel color at point (x,y) == boundary color
		increment x
	end while

	while pixel color at point (x,y) != boundary color AND x < screen width
		fill pixel at point (x,y)
	end while

	increment y

end while

note that if you have -any- gaps in your boundary line then the fill will
leak out !!!

this algorithm will fill any completely closed shape. to apply this to your
semi-circle you can either check for y > (origin + ( diameter/2)) or draw
your own boundary line to close the semi-circle.

hth

ivan.

========================================================================
This random collection of pixels proudly presented by ...
 _____                  __  __      _____                          _     
|_   _|                |  \/  |    |  __ \                        | |    
  | |_   ____ _ _ __   | \  / | ___| |  | | ___  _ __   __ _  __ _| |__  
  | \ \ / / _` | '_ \  | |\/| |/ __| |  | |/ _ \| '_ \ / _` |/ _` | '_ \ 
 _| |\ V / (_| | | | | | |  | | (__| |__| | (_) | | | | (_| | (_| | | | |
|_____\_/ \__,_|_| |_| |_|  |_|\___|_____/ \___/|_| |_|\__,_|\__, |_| |_|
My daily exercise consists of stretching friendships          __/ |      
jumping to conclusions and running away from problems        |___/      

=========================================================================


This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:22 IST