473,378 Members | 1,510 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,378 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:");

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

/* clean up */
return 0;

yours Ivo

Oct 4 '06 #1
1 15305
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.

Oct 4 '06 #2

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

Similar topics

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...
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,...
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...
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:...
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...
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...
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^ ...
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: ...
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+ +.
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.