473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

HOW TO DRAW STUFF USING <graphics.h> ?

Hi there,
I just want to give some sudgestions on how to draw some plain things
only using the header file <graphics.hand of course the standart
files <stdio.h<conio.h<stdlib.h>.

First of All you have to load drivers for the graphic.
-You must have the file EGAVGA.BGI to be in the same directory where
your code is.
-with this driver you will have 640/480 resolution with 16 colors 1
page or you can choose 320/280 16col with 2 video pages.
- to load the graphic driver we use the function -initgraph(int
gdriver, int gmode, const char *path);
gdriver is the type of driver we'll use ( VGA ) gmode is the mode
(VGAMID - 640/480) and path is a string with the path to the file
EGAVGA.BGI ("" usualy).
At the end : initgraph(VGA, VGAMID, "");
to check for errors you can use the function -graphresult(); it
returns int; if its != from grOK then there is an error.

Now you can draw something:
-to choose color type: setcolor(colnum); where "colnum" is the number
of a color between 0 and 15
-background color setbkgcolor(colnum); - || - || -

-draw a line -line(x1,y1,x2,y2); x1,x2, coordinates of the first and
second point of the line - how left or right to be (between 0 and 640),
y1,y2 how up or down to be (between 0 and 480)
EX: line(0,0,640,480); - diagonal line from the up left corner to the
down right corner.

-rectangle -rectangle(x1,y1,x2,y2); like line but draws a rectangle
witch diagonal is the line(x1,y1,x2,y2)

-a dot(pixel) -putpixel(int x,int y, unsigned col); x,y - the
coordinates of the pixel, col - the color

- text -outtextxy(int x,int y,const char *Text); x,y - the
coordinates and Text-the string to be printed
At the end we close the graphic mode with the function closegraph();

-----------------------------------------------------------------------------------------------------------------------------------------------
a simple Program

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
int gdriver = VGA, gmode=VGAMID, errorcode;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}

for(int i=0; i<100; i++)
{
setcolor((i % 15) +1);
line(i*6, 0, 640-i*3, 480);
}

/* clean up */
getch();
closegraph();
return 0;
}
www.pegashometour.com

yours Ivo

Oct 4 '06 #1
1 15310
Iv*******@gmail.com wrote:
Hi there,
I just want to give some sudgestions on how to draw some plain things
only using the header file <graphics.hand of course the standart
files <stdio.h<conio.h<stdlib.h>.
<conio.his not a standard header.
First of All you have to load drivers for the graphic.
-You must have the file EGAVGA.BGI to be in the same directory where
your code is.
You need a newsgroup dedicated to your platform. That looks like
Borland stuff to me, so one of their newsgroups would be a possibility.

Brian
Oct 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: MyndPhlyp | last post by:
I've been busting my head trying to figure this out for quite some time. With IE6 and NS7, no problems. I can simply code the HTML <img height="100%"> and be done with it. But NS4 and NS6 (and...
14
by: slim | last post by:
hi all, whilst creating a mock-up site, i am trying to follow the rules and guidelines i have been digesting over the last few months with regards to css positioning and accessibility. well,...
2
by: ThePsudo | last post by:
# SIMPLE VERSION # Is there a way I can create a new <img> tag onClick? # DETAILED VERSON # I'm making a game that involves drawing a path between two points on a grid. I've got the...
15
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width:...
5
by: sathyashrayan | last post by:
Friends, As I was going through the standard draft of C (C99) I come across the header file <time.h>. I wonder why the standard has included the header file since it depends on the hardware that...
8
by: Beam_Us_Up_Scotty | last post by:
Hello all, I am trying to write a "simple" animation using C#, and I've tried many things but nothing seems to work for me without leaking memory. Here's a very simple piece of code that uses a...
6
by: saunderl | last post by:
Hello Everyone, I'm trying to just play with managed VC++. I just want to draw a box on the form when it is clicked. Here is my click event handler System::Void Test_Click(System::Object^ ...
4
by: VK | last post by:
As per discussion in the thread http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/117e4f3a30f4d1c3 I'm proposing to add new FAQ entry: ...
3
by: birensubudhi | last post by:
hey guys it is easy to do programming in graphics in 16bit TURBO C compiler,but how to work in graphics in 32bit TCWIN4.5 compiler/MS VC+ +.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.