fill polygon

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
beloni
Learning poster
Posts: 66
Joined: Thu Jan 05, 2006 1:41 pm
Location: Pelotas, RS, Brazil

fill polygon

Post by beloni »

Hello,
I need some help to fill any polygon (concave or convex).
The function must receive one point (x,y) inside the shape.
I've tried the recurse solution:

Code: Select all

void fillpoly(int x, int y, int color)
{
 putpixel(x,y,color);

 if (getpixel(x-1,y) == BLACK)
    fillpoly(x-1,y,color);

 if (getpixel(x+1,y) == BLACK)
    fillpoly(x+1,y,color);

 if (getpixel(x,y-1) == BLACK)
    fillpoly(x,y-1,color);

  if (getpixel(x,y+1) == BLACK)
    fillpoly(x,y+1,color);
}
but it overflows the stack!
So if you know any solution for that...
Last edited by beloni on Fri Mar 09, 2007 2:14 pm, edited 3 times in total.
"A machine can do the work of fifty ordinary men, but no machine can do the work of one extraordinary man.", Shahriar Manzoor
asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Re: fill polygon

Post by asif_rahman0 »

beloni wrote: pintor(x-1,y,color);
why did you use it here? Can you tell me?
To fill polygon you must first define poly[] arrays, then the following:

Code: Select all

setfillstyle(...)
fillpoly(...)
it overflows the stack
When this message shows?

I made a small paint project 2yrs ago, that time we made similiar Paint's Polygon tool.
Would you interested to know that?

Btw, what compiler are you using? Turbo C?
beloni
Learning poster
Posts: 66
Joined: Thu Jan 05, 2006 1:41 pm
Location: Pelotas, RS, Brazil

Post by beloni »

I am sorry.
This code was from my friend and it was wrote in Portuguese, so I translated it to English for post here, but as you could see, I forgot some functions...

The message "overflows the recurse stack" does not occurs, but the program craches...

My friend did use TurboC, so he paints just little polygons. On gcc and allegro.h, the painted polygons are greater, but a "Segmentation fault" occurs.

Can you shom me your paint project?
"A machine can do the work of fifty ordinary men, but no machine can do the work of one extraordinary man.", Shahriar Manzoor
asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post by asif_rahman0 »

beloni wrote:On gcc and allegro.h
On Turbo C, it will be "graphics.h".

See PM for link.
Post Reply

Return to “Algorithms”