473,703 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.han d 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(col num); - || - || -

-draw a line -line(x1,y1,x2,y 2); 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,48 0); - 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,y 2)

-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(&gdri ver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
printf("Graphic s error: %s\n", grapherrormsg(e rrorcode));
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 15345
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.han d 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 probably a couple of other IE and NS versions I can't get to right now) don't want to play nice unless I hard code the image height. (Yes, I'm one of those who insists on still coding for NS4.)
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, i know the journey is far from over and i'm using this mock-up as a learning process. the problem stumping me at the moment can be seen here:
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 pathfinding routine working fine, but drawing it out on a grid is proving difficult. Since I can't just draw a line segment, I made a set of graphics to use: a bit of horizontal line, vertical line, and two diagonals. I just take a few copies of each and
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: 123px; height: 456px;" alt="">
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 we work with. If somebody wants to access the time of the system then he has to use the interrupt 1A in the real mode or access the timer chip (port id 70-70h) pmode but that is off-topic in this group. I concluded that it is because of the...
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 timer to set the image of a label from an ImageList every 100ms or so. This is what was being used when I inherited this piece of code, and I thought it was OK, until I changed the size of the label to do animation on a larger piece of screen...
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^ sender, System::EventArgs^ e) { // Create a Graphics object for the Control. Graphics* g = this->CreateGraphics() ;
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: ---------------------------------------------------------------- I'm changing my page but nothing is changing on the screen. Why? ---------------------------------------------------------------- You may be experiencing the repaint delay problem. All existing browsers do not update...
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.