0% found this document useful (0 votes)
21 views8 pages

CG 7

The document provides an overview of basic graphics functions in the graphics.h library, specifically focusing on the rectangle and bar functions for drawing shapes. It includes function declarations, descriptions of parameters, and example code snippets demonstrating how to use these functions. Additionally, it shows how to use the setfillstyle function to fill shapes and provides an example of animating a moving car using rectangles and circles.

Uploaded by

Fazil Nasrat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views8 pages

CG 7

The document provides an overview of basic graphics functions in the graphics.h library, specifically focusing on the rectangle and bar functions for drawing shapes. It includes function declarations, descriptions of parameters, and example code snippets demonstrating how to use these functions. Additionally, it shows how to use the setfillstyle function to fill shapes and provides an example of animating a moving car using rectangles and circles.

Uploaded by

Fazil Nasrat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Computer Graphics

Rectangle
rectangle function in graphics.h
 Declaration :-
void rectangle(int left, int top, int right, int bottom);
 rectangle function is used to draw a rectangle.
Coordinates of left top and right bottom corner are
required to draw the rectangle.
 left specifies the X-coordinate of top left corner, top
specifies the Y-coordinate of top left corner, right
specifies the X-coordinate of right bottom corner,
bottom specifies the Y-coordinate of right bottom
corner. The code given below draws a rectangle.
Example-1
#include<graphics.h> #include<conio.h>
main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm,”");
rectangle(100,100,200,200);
getch();
closegraph();
return 0;
}
bar function
 Bar function is used to draw a 2-dimensional,
rectangular filled in bar.
void bar(int left, int top, int right, int bottom).
 Coordinates of left top and right bottom corner are
required to draw the bar. Left specifies the X-
coordinate of top left corner, top specifies the Y-
coordinate of top left corner, right specifies the X-
coordinate of right bottom corner, bottom specifies
the Y-coordinate of right bottom corner. Current fill
pattern and fill color is used to fill the bar. To
change fill pattern and fill color use setfillstyle.
setfillstyle( , )
 Setfillstyle function is using to fill the
surface of any graphics objects when
create after the function.
 There is two arguments

1. Fill style
2. Color
Setfillstyle (pattern, color);
Example
#include<graphics.h>
#include<conio.h>
main()
{

int i, j = 0, gd = DETECT, gm;

initgraph(&gd,&gm,"");

settextstyle(1,0,2);
setfillstyle(1, 4);
bar(100, 100, 200, 200);
rectangle(100,100,200,200);
getch();
closegraph();
return 0;

}
Example Move a car
#include<graphics.h>
#include<conio.h>
main()
{

int i, j = 0, d = DETECT, m;

initgraph(&d,&m,"");

settextstyle(1,0,2);
outtextxy(25,240,"Press any key to view the moving car");

getch();
for( i = 0 ; i <= 420 ; i = i + 10, j++ )
{
rectangle(50+i,275,150+i,400);
rectangle(150+i,350,200+i,400);
circle(75+i,410,10);
circle(175+i,410,10);
setcolor(j);
delay(100);
if( i == 420 )
break;
if ( j == 15 )
j = 2;
cleardevice(); // clear screen
}
getch();
closegraph();
return 0;
}

You might also like