Computer Graphics 1
Computer Graphics 1
Section1
Introduction to Turbo C Graphics
Table of contents
1. Introduction to Graphics
2. What is Turbo C?
3. Advantages and Disadvantages
4. History
5. Setting up
6. Structure of code
7. Basic graphics function
8. Assignment 1
Introduction to Graphics
● https://www.mediafire.com/file/x6jhtoes5pdl6dz/Setup_TurboC_
7_v2.1.rar/file
graphicMode
It specifies the graphic mode to be used. If graphicDriver is set to DETECT,
Then graphicMode is set to the highest resolution available for the
detected driver.
driverPath
It specifies the directory path where graphics driver files (BGI files) are located.
Closing the graphics
● After work done with “Graphics mode”, it must be closed using a
pre-defined function closegraph().
● closegraph() → it deallocates all memory allocated by graphics
system and restores the screen to text mode.
void closegraph();
(X,Y)
Y – axis
Printing text
1. outtext(“Hello World”);
2. outtextxy(100,100,”Hello World”);
3. char str[] = “Hello World”;
outtextxy(100,100,str);
Drawing a straight line
1. line(50,50,100,100);
2. line(50,50,100,50); → Horizontal line.
3. line(50,20,50,100); → Vertical line
Drawing a Rectangle
y1 (top)
y2 (bottom)
Y – axis void rectangle(int left, int top, int right, int bottom);
Example
1. rectangle(50,50,100,100);
2. rectangle(100,50,100,50); → point.
3. rectangle(100,50,200,50); → line.
Drawing a Circle
1. circle(100,100,50);
2. circle(50,50,100);
50
50
(100,100)
Drawing an Arc
1. arc(100,100,0,90,50); 90
50
50 0
180 360
(100,100)
270
1. arc(50,50,90,360,30);
2. arc(100,100,0,135,50);
Drawing an Ellipse
void ellipse(int x, int y, int stangle, int endangle, int xrad, int yrad);
Example
1. ellipse(100,100,0,360,50,25);
90
25
0
180
(100,100) 50 360
270
2. ellipse(100,100,90,270,50,25);
Drawing filled Ellipse
1. fillellipse(100,100,50,25);
25
(100,100) 50
Set color
● circle(100,100,50);
● setcolor(RED);
● circle(200,200,50);
Set Background color
void cleardevice( );
Thanks!