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..