Enviorment is TC.
using grapphics.h .
I am developing the board game LUDO as project in C++ Using OOP methodology.
Right now I am drawing the Board. Now I want to draw various cells, of 30 pixels X 30 pixels at various places on the screen. I am drawing a rectangle, I circle inside rectangle and a STAR inside that circle.
Now I want to color the area outside circle (inside rectangle) and the star with the same color. Leaving the area inside circle and outside star white.
So I wrote this function stop_cell() with x, y as co ordinates and last argument as color (As I want cells to be drawn with various colors.). But the problem is that whenever the difference b/w x and y is >15 picels the drawing is not of appropriate (i-e the circle inside gets black from white) and when x-y is greater the whole screen gets white colored or of different color.
The Floodfill is creating alot of problem.. I have to use many colors for drawing the board.. Cells of different colors on various places..
Here is my code:-
(It is only for drawing cell, not the whole proj.. with a minor section of main() caller program. )

#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <MATH.H>

struct point
{
int x, y; } ;

int stop_cell(int x, int y, int c)
{
point p[5] ; //five points for the corner of star.

setlinestyle(0, 1, 3) ;   //sets line width to 3 for drawing cell.
setfillstyle(1, WHITE) ;
setcolor(c) ;
rectangle(x, y, x+31, y+31) ;

setcolor(c) ;
setlinestyle(0, 1, 1) ;
floodfill(x+5, x+10, c);
circle(x+15, y+15, 14) ;

p[0].x=(x+15)+14*0.951;                   //using theta = 72 degree.
p[0].y=(y+15)+14*(-0.309);               //translated x and y from theta as x=rcos(theta)
p[1].x=(x+15)+14*0;                          //and y =rsin(theta) for angles 90-18=18, 90
p[1].y=(y+15)-14*1;                           // 162, 234 and 306 for five corners of star.
p[2].x=(x+15)+14*(-0.951);
p[2].y=(y+15)+14*(-0.309);
p[3].x=(x+15)+14*(-0.587);
p[3].y=(y+15)+14*(0.809);
p[4].x=(x+15)+14*(0.587);
p[4].y=(y+15)+14*(0.809);

line(p[0].x, p[0].y, p[2].x, p[2].y) ;   //Drawn the five lines for making star.
line(p[2].x, p[2].y, p[4].x, p[4].y) ;
line(p[4].x, p[4].y, p[1].x, p[1].y) ;
line(p[1].x, p[1].y, p[3].x, p[3].y) ;
line(p[3].x, p[3].y, p[0].x, p[0].y) ;

setcolor(c) ;
setfillstyle(1, c) ;

floodfill(x+5, x+10, c);                                    //filled the star with the color 'c'.
floodfill(p[0].x-3, p[0].y+1, c );       
floodfill(p[1].x, p[1].y+3 , c );
floodfill(p[2].x+3, p[2].y+1, c );
floodfill(p[3].x+2, p[3].y-3, c );
floodfill(p[4].x-2, p[4].y-3, c );
floodfill(x+15, y+15, c);
floodfill(x+4,y+4, c) ;
floodfill(x+4,y+27, c) ;
floodfill(x+27, y+27, c) ;
floodfill(x+27, y+4, c) ;
return 0 ;
}

int main()
{
int gd=DETECT, gm ;
initgraph (&gd, &gm, "C:\\TC\\BGI") ;
int i=14, j=2, k=1 ;
for (int n=0; n<=14; n++)
stop_cell(250, 235, 2) ;
stop_cell(350, 345, 4) ;   //the diff b/w x and y is <6 and the color spread out of 
              //star. May be problem with translation for such close values of x and y.
stop_cell(420, 405, 6) ;
//run this line when difference is > 15 b/w x and y .
//stop_cell(220, 185) ;
getch() ;
closegraph() ;
return 0 ;
}

Plz help me.. Is there any other approach except floodfill I can use..

You mean like using a decent 32-bit compiler on your 32-bit OS, complete with a wide range of graphics libraries.

floodfill() is recursive, massively so.
Unless you do something, your default stack size of a few KB will disappear all too rapidly.

Even if you increase the size of the stack to it's max of 64K, you're not going to fix the underlying problem.

http://en.wikipedia.org/wiki/Floodfill

Hmm the problem is that I am a student and limited to these compilers only for learning purpose by the college.

Although I can talk to instructor for this problem but sticking with TC is preferred.
So please.. why the stack is filling so soon when floofill() is successfully working for x-y<15 but not for x-y>15 ??

There's a whole bunch of free compilers available, so cost is not the issue.

The problem is your tutor refuses to leave their comfort zone of teaching the only compiler they know. Very comfortable for them, but increasingly useless to the students who have a hell of a lot of catchup in the real world.

> So please.. why the stack is filling so soon when floofill() is successfully
> working for x-y<15 but not for x-y>15 ??
Put a counter in the function and see how many recursive calls you get.
The larger the counter gets, the more stack it eats.

Used Fillpoly instead Floodfill, Calculated 10 points of star instead of 5 (in case of floodfill(). ) and then made 32 cells with circle and star at different points on the screen and it did marvelous job for me..
Thumbs up for fillpoly(), down with Floodfill() .

You are drawing circle from the center(cx,cy) of the square so to fill color outside the circle and in side the square you should use in this way floodfill(cx+radius + 2, cy + radius + 2 , color);

where radius: radius of the inside circle
and color: color to be filled

Thanks for ur reply.. but I reached at the conclusion that floodfill should be used at minimum, only then when necessary. Fillpolly is alot better then it..

Marked this thread as SOLVED, please

Can u please send me the code to draw a ludo board at my hotmail id????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.