Hi, I was using borland 5.5, and I tried introducing graphics using the followig code

#include<iostream.h>
#include<graphics.h>

$void main()
{
  int driver,mode;
  driver = DETECT;
  initgraph(&driver,&mode,"\\tc\\bgi);

  circle(25,35,12);

  closegraph();
}

But I get the error graphics not supported with windows. So I tried TURBO C++ 3.0. And it worked perfectly

But the problem is when I try using the floodfill function() it does not colour the circle but the color is spread out all over the screen. How can
I solve this problem.

And since I am a new programmer I don't want to go to windows API and stuff like that but rather stick to the grpahics.h

I don't mind using turbo c++ 3.0
but I certainly want to solve the problem of using the floodfill() function..

> So I tried TURBO C++ 3.0. And it worked perfectly
Basically, you have a choice.
- Stick with a 16 bit compiler, and low resolution graphics library from antiquity.
- Upgrade to a more modern 32 bit compiler, and learn a new graphical API (say OpenGL).

> it does not colour the circle but the color is spread out all over the screen
1. You didn't paste your attempt at using floodfill.
2. You set the seed point outside the circle?
3. Your circle has a hole in the perimeter - this is a bug in circle, if circles are meant to draw closed shapes which can be flood filled.

Oh, and main returns int, not void

>problem of using the floodfill() function
Could there be a possible bug in your floodfill() algorithm?

I don't get you. Do you think there is a bug in the function itself????

> So I tried TURBO C++ 3.0. And it worked perfectly
Basically, you have a choice.
- Stick with a 16 bit compiler, and low resolution graphics library from antiquity.
- Upgrade to a more modern 32 bit compiler, and learn a new graphical API (say OpenGL).

> it does not colour the circle but the color is spread out all over the screen
1. You didn't paste your attempt at using floodfill.
2. You set the seed point outside the circle?
3. Your circle has a hole in the perimeter - this is a bug in circle, if circles are meant to draw closed shapes which can be flood filled.

Oh, and main returns int, not void

I don't know what is OpenGL, could you brief me on that or give me a link which does that.

What compiler would I have to download then?????

The program I wrote was

int driver = DETECT,mode;
initgraph(&driver,&mode,"\\tc\\bgi");

floodfill(25,25,RED);
Setfillstyle(SOLID_FILL,RED);
circle(25,25,10);

I don't think there is a bug in the circle function.

You first need to draw the cirle and then do a flood fill, not after it. Swap the 'circle' and 'floodfill' statements.

You first need to draw the cirle and then do a flood fill, not after it. Swap the 'circle' and 'floodfill' statements.

Thanks it worked! The circle was full filled.

I tried it with rectangle(150,90,160,100);
what should the coordinates for floodfill(x,y,RED);

ie values of X any Y
Thanx in advance.

I tried rectangle(150,90,175,160);
setfillstyle(SOLID_FILL,RED);
floodfill(155,100,RED);

but I again got the same problem.. It filled the whole screen. But coordinates are within the ones of rectangle....

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

void main()
{
  int driver,mode;
  driver = DETECT;
  initgraph(&driver,&mode,"\\tc\\bgi");
  rectangle(105,90,125,110);
  setfillstyle(SOLID_FILL,RED);
  floodfill(115,100,RED);

But instead of filling the rectangle it fills the whole screen. But when I tried it for a circle it worked.
Below is the code.

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

void main()
{
  int driver,mode;
  driver = DETECT;
  initgraph(&driver,&mode,"\\tc\\bgi");
  circle(115,100,10);
  setfillstyle(SOLID_FILL,RED);
  floodfill(115,100,RED);
}

Please help.

This is happening because you are setting the fill color as well as the border color of the fill to the same color i.e. RED.

This is confusing the floodfill algorithm which checks the color of the neighboring pixels to determine when to stop. By making the border RED, the check is never unsuccessful and it fills up the entire screen. This seems to be a bug with the function since this is not expected but you have got to live with it. :-)

Choose different colors for floodfilling and its border and you should be fine. Oh and BTW, main returns an int and not void.

#include<stdio.h>
#include<graphics.h>
//you don't need conio

int main(void)
{
  int driver,mode;
  driver = DETECT;
  initgraph(&driver,&mode,"\\tc\\bgi");  
  rectangle(105,90,125,110);
  setfillstyle(SOLID_FILL, RED);
  floodfill(115, 100, WHITE);
  getchar();
  closegraph();
  return(0);
}

}

Thanks a lot.. I thought thewe have to mention the colour of the fill in the floodfill function.. I dint know that you have to specify the colour of the boundary of the shape.

Thanks a lot for your help....... I am actually creating a chess program. And I needed this badly.. Thanx

But why shouldn't we used

" Void main() "

Does it make a difference if we use int main???

Read this. Simple and short answer: As far as the standards are concerned, main() always has returned an int as its exit status.

class shape
            {
                public:  void set(int x,int y, int fillcolor)
                             {
                                 rectangle(x,y,x+20,y+20);
                                 floodfill(x+5,y+5,RED);
                                 setfillstyle(SOLID_FILL,WHITE);
                             }
            };

int main()
{
   int driver = DETECT,mode;
   initgraph(&driver,&mode,"\\tc\\bgi");    

   shape s1,s2;
   s1.set(100,120,15);
   s2.set(100,160,15);

   s1.set(140,140,15); 

   getch();
   closegraph();

}

The problem here is that when I set the coordinates of s1 again the shape s1 can still be seen in its orginal location and also at its new location.

How do I make it such that it appears only at its new coordinate???

I am afraid I don't know a lot about Turbo C graphics library and its specific functions. But for erasing the previous figure and redrawing it at a new location, consider erasing the particular part of the screen where s1 is present or clear the whole screen and draw a new s1 at the specified location.

You can find the function reference here.

> I need help in inputing text in graphics mode
Click on the link SOS posted.
Locate the getch() function, and follow the link.
Read up on what that function does, and study the example at the end.
Adapt the code to meet your needs.

getch(); does not work in graphics.h. I mean I need to input text.

To output text I know the function is outtext() or outtextxy().
I need a function like that to input text. And besides getch() is not used for that..

I saw the link SOS provided. There were many usefull function to draw shapes and outputting text but I couldn't find one to input text.

So you're telling me that calling getch() in a loop to build up a string, one character at a time doesn't work?

getch(); does not work in graphics.h. I mean I need to input text.

And what makes you think it doesn't? What happened when you tried it?

This question has already been answered. Start a new discussion instead.