Page 1 of 1

fill polygon

Posted: Thu Mar 08, 2007 7:03 pm
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...

Re: fill polygon

Posted: Thu Mar 08, 2007 9:11 pm
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?

Posted: Fri Mar 09, 2007 2:21 pm
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?

Posted: Fri Mar 09, 2007 3:47 pm
by asif_rahman0
beloni wrote:On gcc and allegro.h
On Turbo C, it will be "graphics.h".

See PM for link.