954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help needed in graphics.h

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

graphics.h does not exist for Borland 5.5, so it won't work.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

So how do I introduce graphics in my programs????

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

> 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

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
>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????

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

> I don't know what is OpenGL
If you want to make it as a programmer, your first reaction to asking "what is foo" is to type in "foo" into a search engine, and see if you can't get some information for yourself.
http://www.opengl.org/

And to get you going
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01
Scroll down to the end for a partial list of the platforms which OpenGL can be used with.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
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.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

Any point inside any closed figure.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

Maybe posting the entire code in code tags would help your cause.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 
#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.

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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);
}

}

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

But why shouldn't we used

" Void main() "

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

krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 31
Solved Threads: 3
 

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

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You