Final Jatin CG

Download as pdf or txt
Download as pdf or txt
You are on page 1of 56

Chaudhary Charan Singh University

Delhi institute of Higher Education (DIHE)


College Code: - 1214
Session: - 2023-2024

Subject: - Computer Laboratory and Practical Work of


Computer Graphics and Multimedia Application
Code: - BCA -405(P)

Submitted To: - Submitted By: -


Dr.Manjeet Ratan Jatin Kumar
B.C.A

Roll No: - R221214106054


Enrolment No: - 22415728
Course: - Bachelor of Computer Application

Page 1 of 56
Acknowledgement

I would Like to express my special thanks of gratitude to my Professors


Dr.Manjeet Ratan and Ms.Hemlata Rauthan for their guidance and
support in completing my project file. I would like to extend my
gratitude to them for providing me with all the facility that was
required.

Student Name:-Jatin Kumar


Course: - BCA
Semester: - IV
Enrolment No: -22415728

Page 2 of 56
Student Declaration

I Jatin Kumar Roll No. R221214106054 student of “BCA” Semester- IV


hereby declare that the project report & assignment has been
submitted by me to Delhi Institute of Higher Education (DIHE) for
fulfillment of Degree of Bachelor of Computer Application.

Dr. Manjeet Ratan Student Name:-Jatin Kumar


Course: - BCA
Semester: - IV
Enrolment No: -22415728

Page 3 of 56
CERTIFICATE OF COMPLETION

This is to certify that Mr. Jatin Kumar of BCA Fourth semester has completed his

file of “Computer Laboratory and Practical Work of CGMA” (BCA-405P) on own.

His work is up to my satisfaction.

Dr. Manjeet Ratan


BCA

Page 4 of 56
INDEX
S no Program Topics P no Remarks
1 Program to Display Pixel and create a Line, 7-8
Rectangle and Circle on the screen.

2 Graphics functions like ellipse, delay, rectangle, 9-11


sector& polygon.

3 Program to create Ellipse and fill it with Red color. 12-13

4 Graphics functions like setcolor, setfillstyle, 14-15


floodfill, arc, bar and bar3d.

5 Program to create Ellipse. 16-17

6 Program to print a car on the screen. 18-20

7 Program to create a smiley face. 21-22

8 Program to create bar and bar3d. 23-24

9 Program to make a Flag. 25-26

10 Program to make a Hut. 27-28

11 Program to create chart on screen. 29-30

12 Program to create Line using DDA. 31-32

13 Program to create Line Using Bresenham’s Line 33-36


Algorithm.

14 Program to create Circle using Bresenham’s Circle 37-39


Algorithm.

Page 5 of 56
15 Program to create Circle using Midpoint Circle 40-42
Algorithm.
16 Program of Road Animation. 43-45

17 Program to create Cake on screen 46-48

18 Program to create Flying kite on screen. 49-51

19 Program to make a Fish. 52-54

20 Program to generate random circle. 55-56

Page 6 of 56
1. Program to display Pixel and create a line,rectangle, and Circle on
the screen.
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#define WIDTH 800 #define HEIGHT 600
int main() { int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
putpixel(WIDTH/2, HEIGHT/2, WHITE);
line(100, 100, 400, 300);
rectangle(200, 200, 500, 400);
circle(600, 300, 100); delay(5000);
closegraph(); return 0;
}

Page 7 of 56
Output

Page 8 of 56
2. Graphics functions like ellipse, delay, ractangle, sector & polygon.

#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <time.h>
#define WIDTH 800 #define
HEIGHT 600
int randomInRange(int min, int max) {
return min + rand() % (max - min + 1);
}
int main() { int gd = DETECT,
gm; initgraph(&gd, &gm,
NULL); srand(time(NULL));
int centerX = randomInRange(100, WIDTH - 100); int
centerY = randomInRange(100, HEIGHT - 100); int xRadius =
randomInRange(50, 200); int yRadius = randomInRange(50,
200); ellipse(centerX, centerY, 0, 360, xRadius, yRadius);
int left = randomInRange(50, WIDTH - 150); int top =
randomInRange(50, HEIGHT - 150); int right = left +
randomInRange(50, 200); int bottom = top +
randomInRange(50, 200); rectangle(left, top, right, bottom);
int startAngle = randomInRange(0, 360); int endAngle =
startAngle + randomInRange(30, 300); sector(WIDTH/2,
HEIGHT/2, startAngle, endAngle, 150, 100); int poly[10];
for (int i = 0; i < 6; ++i) {
poly[i] = randomInRange(100, WIDTH - 100);
}
Page 9 of 56
poly[6] = poly[0];
poly[7] = poly[1];
poly[8] = poly[2];
poly[9] = poly[3];
drawpoly(5, poly);
delay(5000);
closegraph(); return
0;
}

Page 10 of 56
Output

Page 11 of 56
3. Program to create Ellipse and fill it with Red color.
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <time.h>
#define WIDTH 800 #define HEIGHT 600
int randomInRange(int min, int max) {
return min + rand() % (max - min + 1);
}
int main() { int gd = DETECT,
gm; initgraph(&gd, &gm,
NULL); srand(time(NULL));
int centerX = randomInRange(50, WIDTH - 50);
int centerY = randomInRange(50, HEIGHT - 50);
int xRadius = randomInRange(20, 100); int
yRadius = randomInRange(20, 100);
setcolor(RED);
ellipse(centerX, centerY, 0, 360, xRadius, yRadius);
setfillstyle(SOLID_FILL, RED); floodfill(centerX,
centerY, RED); delay(5000); closegraph();
return 0;
}

Page 12 of 56
Output

Page 13 of 56
4. Graphics functions like setcolor, setfillstyle, floodfill, arc, bar and bar3d.
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>
#include <time.h>
#define WIDTH 800 #define
HEIGHT 600
int randomInRange(int min, int max) {
return min + rand() % (max - min + 1);
}
int main() { int gd = DETECT,
gm; initgraph(&gd, &gm,
NULL); srand(time(NULL));
int centerX = randomInRange(50, WIDTH - 50);
int centerY = randomInRange(50, HEIGHT - 50);
int radius = randomInRange(20, 100);
setcolor(GREEN);
circle(centerX, centerY, radius);
setfillstyle(SOLID_FILL, BLUE); floodfill(centerX,
centerY, GREEN); int startAngle = randomInRange(0,
360); int endAngle = startAngle + randomInRange(30,
300); arc(centerX, centerY, startAngle, endAngle,
radius/2); delay(5000); closegraph(); return 0; }

Page 14 of 56
Output

Page 15 of 56
5. Program to create Ellipse .
#include <graphics.h>
#include<stdio.h>
#include<conio.h> int
main()
{
int gd = DETECT, gm;

int x = 250, y = 200; int

start_angle = 0; int

end_angle = 360; int x_rad =

100; int y_rad = 50;


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

ellipse(x, y, start_angle,

end_angle, x_rad, y_rad);

getch(); closegraph();
return 0;

Page 16 of 56
Output

Page 17 of 56
6. Program to print a Car on the screen.
#include <graphics.h> #include
<stdio.h> void
draw_moving_car(void) { int i, j
= 0, gd = DETECT, gm;
initgraph(&gd, &gm, "");

for (i = 0; i <= 420; i = i + 10) {


setcolor(RED);
line(0 + i, 300, 210 + i, 300);
line(50 + i, 300, 75 + i, 270);

line(75 + i, 270, 150 + i, 270);

line(150 + i, 270, 165 + i, 300);

line(0 + i, 300, 0 + i, 330); line(210

+ i, 300, 210 + i, 330); circle(65

+ i, 330, 15); circle(65 + i, 330, 2);

circle(145 + i, 330, 15);

circle(145 + i, 330, 2); line(0 + i,

330, 50 + i, 330); line(80 + i, 330,

130 + i, 330); line(210 + i,

330, 160 + i, 330); delay(100);

setcolor(BLACK);

line(0 + i, 300, 210 + i, 300);

line(50 + i, 300, 75 + i, 270);

line(75 + i, 270, 150 + i, 270);

line(150 + i, 270, 165 + i, 300);

line(0 + i, 300, 0 + i, 330); line(210

Page 18 of 56
+ i, 300, 210 + i, 330); circle(65

+ i, 330, 15); circle(65 + i, 330, 2);

circle(145 + i, 330, 15);

circle(145 + i, 330, 2); line(0 + i,

330, 50 + i, 330); line(80 + i, 330,


130 + i, 330); line(210 + i,

330, 160 + i, 330);

}
getch();

closegraph();

}
int main()
{
draw_moving_car();

return 0;

Page 19 of 56
Output

Page 20 of 56
7. program to create a smiley face
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <stdio.h>

// Driver Code int


main()
{
int gr = DETECT, gm; initgraph(&gr,

&gm, "C:\\Turboc3\\BGI");
setcolor(YELLOW); circle(300, 100, 40);

setfillstyle(SOLID_FILL, YELLOW); floodfill(300,

100, YELLOW); setcolor(BLACK);

setfillstyle(SOLID_FILL, BLACK);

fillellipse(310, 85, 2, 6); fillellipse(290, 85, 2,

6); ellipse(300, 100, 205, 335, 20, 9);

ellipse(300, 100, 205, 335, 20, 10);

ellipse(300, 100, 205, 335, 20, 11);

getch(); closegraph();

return 0;
}

Page 21 of 56
Output

Page 22 of 56
8. Program to create bar and bar3d.

#include <graphics.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, ""); int
left, top, right, bottom; int
depth; int topflag;
bar3d(left = 150, top = 250,
right = 190, bottom = 350,
depth = 20, topflag = 1);
bar3d(left = 220, top = 150,
right = 260, bottom = 350,
depth = 20, topflag = 0);
bar3d(left = 290, top = 200,
right = 330, bottom = 350,
depth = 20, topflag = 1);
line(100, 50, 100, 350);
line(100, 350, 400, 350);
getch(); closegraph();
return 0;
}

Page 23 of 56
Output

Page 24 of 56
9. Program to Make a Flag.

#include <stdio.h> #include


<graphics.h> int main() { int gd =
DETECT, gm; initgraph(&gd,
&gm, ""); setfillstyle(SOLID_FILL,
YELLOW); bar(100, 100, 500,
200); setfillstyle(SOLID_FILL,
WHITE); bar(100, 200, 500, 300);
setfillstyle(SOLID_FILL, GREEN);
bar(100, 300, 500, 400);
setcolor(BLUE); circle(300, 250,
50);
int i;
for (i = 0; i < 360; i += 15)
line(300, 250, 300 + 50 * cos(i * 3.14 / 180), 250 + 50 * sin(i * 3.14 / 180));
delay(5000); closegraph(); return 0;
}

Page 25 of 56
Output

Page 26 of 56
10. Program to Make a Hut.
#include <stdio.h> #include
<graphics.h> int main() { int gd =
DETECT, gm; initgraph(&gd, &gm,
""); setfillstyle(SOLID_FILL,
LIGHTBLUE); bar(100, 250, 300,
400); setfillstyle(SOLID_FILL, RED);
line(100, 250, 200, 150); line(300,
250, 200, 150); line(100, 250, 300,
250); floodfill(200, 200, WHITE);
setfillstyle(SOLID_FILL, YELLOW);
bar(120, 300, 150, 350);
setfillstyle(SOLID_FILL, CYAN);
bar(250, 300, 280, 350);
setfillstyle(SOLID_FILL, GREEN);
bar(180, 300, 220, 400);

delay(5000);
closegraph(); return
0;
}

Page 27 of 56
Output

Page 28 of 56
11. Program to create chart on screen.

#include<graphics.h> #include<stdio.h>
int main() { int gd = DETECT, gm, x,
y; initgraph(&gd, &gm,
"C:\\TC\\BGI");
settextstyle(BOLD_FONT,HORIZ_DIR,2);
outtextxy(220,10,"PIE CHART"); x =
getmaxx()/2; y = getmaxy()/2;
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1);
setfillstyle(SOLID_FILL, RED); pieslice(x,
y, 0, 60, 120); outtextxy(x + 140, y - 70,
"FOOD"); setfillstyle(SOLID_FILL, YELLOW);
pieslice(x, y, 60, 160, 120); outtextxy(x
- 30, y - 170, "RENT");
setfillstyle(SOLID_FILL, GREEN);
pieslice(x, y, 160, 220, 120); outtextxy(x
- 250, y, "ELECTRICITY");
setfillstyle(SOLID_FILL, BROWN);
pieslice(x, y, 220, 360, 120);
outtextxy(x, y + 150, "SAVINGS");
closegraph(); return 0; }

Page 29 of 56
Output

Page 30 of 56
12. Program to create Line using DDA.

#include <graphics.h>
#include <stdio.h>
#include <math.h>
#include <dos.h>

void main( )
{
float x,y,x1,y1,x2,y2,dx,dy,step;
int i,gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

printf("Enter the value of x1 and y1 : ");


scanf("%f%f",&x1,&y1); printf("Enter
the value of x2 and y2: ");
scanf("%f%f",&x2,&y2);

dx=abs(x2-x1); dy=abs(y2-y1);

if(dx>=dy)
step=dx; else
step=dy;

dx=dx/step; dy=dy/step;

x=x1; y=y1;

i=1; while(i<=step)
{
putpixel(x,y,5);
x=x+dx;
y=y+dy; i=i+1;
delay(100);
}

closegraph(); }

Page 31 of 56
Output

Page 32 of 56
13. Program to create Line using Bresenham's Line Algorithm.

#include<stdio.h>
2#include<graphics.h>
3
4void drawline(int x0, int y0, int x1, int y1)
5{
6 int dx, dy, p, x, y;
7
8dx=x1-x0;
9dy=y1-y0;
10
11x=x0;
12y=y0;
13
14p=2*dy-dx;
15
16while(x<x1)
17{
18if(p>=0)
19{
20putpixel(x,y,7); y=y+1;
21p=p+2*dy-2*dx;
22}
23{else
24
putpixel(x,y,7);
25
p=p+2*dy;
26}
27
x=x+1;
28}
29
}
30
31int main()
32{
33int gdriver=DETECT, gmode, error, x0, y0, x1, y1; initgraph(&gdriver,
34&gmode, "c:\\turboc3\\bgi");
35
36printf("Enter co-ordinates of first point: ");
37scanf("%d%d", &x0, &y0);
38
39printf("Enter co-ordinates of second point: "); scanf("%d%d",
40&x1, &y1);

Page 33 of 56
41
42

Page 34 of 56
43drawline(x0, y0, x1, y1);
44
45return 0;
46}

Page 35 of 56
Output

Page 36 of 56
14. Program to create Circle using Bresenham's Circle Algorithm.

#include <stdio.h>
#include <dos.h>
#include <graphics.h>
void drawCircle(int xc, int yc, int x, int y)
{
putpixel(xc+x, yc+y, RED);
putpixel(xc-x, yc+y, RED);
putpixel(xc+x, yc-y, RED); putpixel(xc-
x, yc-y, RED); putpixel(xc+y, yc+x, RED);
putpixel(xc-y, yc+x, RED);
putpixel(xc+y, yc-x, RED); putpixel(xc-y,
yc-x, RED);
}
void circleBres(int xc, int yc, int r)
{
int x = 0, y = r; int d
= 3 - 2 * r;
drawCircle(xc, yc, x, y);
while (y >= x)
{ x++;
if (d > 0)
{
y--;
d = d + 4 * (x - y) + 10;
} else d=d
+ 4 * x + 6;

Page 37 of 56
drawCircle(xc, yc, x, y);
delay(50);
}
}
int main()
{
int xc = 50, yc = 50, r = 30;
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
circleBres(xc, yc, r); return
0;
}

Page 38 of 56
Output

Page 39 of 56
15. Program to create Circle using Midpoint Circle Algorithm.

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

void drawcircle(int x0, int y0, int radius)


{
int x = radius;
int y = 0; int
err = 0;

while (x >= y)
{
putpixel(x0 + x, y0 + y, 7);
putpixel(x0 + y, y0 + x, 7);
putpixel(x0 - y, y0 + x, 7);
putpixel(x0 - x, y0 + y, 7);
putpixel(x0 - x, y0 - y, 7);
putpixel(x0 - y, y0 - x, 7);
putpixel(x0 + y, y0 - x, 7);
putpixel(x0 + x, y0 - y, 7);

if (err <= 0)
{
y += 1; err
+= 2*y + 1;
}
if (err > 0)
{
x -= 1; err -
= 2*x + 1;
}
}
}
int main()
{
int gdriver=DETECT, gmode, error, x, y, r; initgraph(&gdriver,
&gmode, "c:\\turboc3\\bgi");

printf("Enter radius of circle: "); scanf("%d",


&r);

Page 40 of 56
printf("Enter co-ordinates of center(x and y): ");
scanf("%d%d", &x, &y);
drawcircle(x, y, r);

return 0;
}

Page 41 of 56
Output

Page 42 of 56
16. Program of Road Animation

#include <stdio.h>
#include <graphics.h>
#include <dos.h>
int main() { int
gd = DETECT, gm; int
i, maxx, midy;

/* initialize graphic mode */


initgraph(&gd, &gm, "X:\\TC\\BGI"); /*
maximum pixel in horizontal axis */
maxx = getmaxx();
/* mid pixel in vertical axis */
midy = getmaxy()/2;
for (i=0; i < maxx-150; i=i+5)
{ /* clears screen */
cleardevice();

/* draw a white road */


setcolor(WHITE);
line(0, midy + 37, maxx, midy + 37);

/* Draw Car */
setcolor(YELLOW);
setfillstyle(SOLID_FILL, RED);
line(i, midy + 23, i, midy);
line(i, midy, 40 + i, midy - 20); line(40 +
i, midy - 20, 80 + i, midy - 20); line(80 +
i, midy - 20, 100 + i, midy); line(100 + i,
midy, 120 + i, midy); line(120 + i, midy, 120
+ i, midy + 23); line(0 + i, midy + 23, 18 +
i, midy + 23); arc(30 + i, midy + 23, 0, 180,
12); line(42 + i, midy + 23, 78 + i, midy +
23); arc(90 + i, midy + 23, 0, 180, 12);
line(102 + i, midy + 23, 120 + i, midy + 23);
line(28 + i, midy, 43 + i, midy - 15);
line(43 + i, midy - 15, 57 + i, midy - 15);
line(57 + i, midy - 15, 57 + i, midy);
line(57 + i, midy, 28 + i, midy);
line(62 + i, midy - 15, 77 + i, midy - 15);
line(77 + i, midy - 15, 92 + i, midy);
line(92 + i, midy, 62 + i, midy); line(62 +

Page 43 of 56
i, midy, 62 + i, midy - 15); floodfill(5 +
i, midy + 22, YELLOW); setcolor(BLUE);
setfillstyle(SOLID_FILL, DARKGRAY);
/* Draw Wheels */ circle(30
+ i, midy + 25, 9); circle(90 + i,
midy + 25, 9); floodfill(30 + i,
midy + 25, BLUE); floodfill(90 + i,
midy + 25, BLUE); /* Add delay of
0.1 milli seconds */ delay(100);
}
closegraph();
return 0;
}

Page 44 of 56
Output

Page 45 of 56
17. Program to create Cake on screen.
#include<conio.h>
#include<graphics.h>
#include<stdio.h> void
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
setbkcolor(LIGHTBLUE);
setcolor(MAGENTA);
outtextxy(80,80,"WISH YOU A VERY HAPPY BIRTHDAY DEAR !!!");
outtextxy(90,90,"HAVE A GREAT DAY AND A WONDERFUL YEAR AHEAD!!!");
outtextxy(100,400,"MAY YOUR BIRTHDAY BE FULL OF SUNSHINE AND RAINBOWS
AND HAPPINESS"); outtextxy(400,420,"FROM "); setcolor(RED);
rectangle(150,250,450,350); setcolor(BROWN); rectangle(200,175,400,250);
setcolor(WHITE) rectangle(250,150,260,175); rectangle(300,150,310,175);
rectangle(350,150,360,175); rectangle(175,225,185,250);
rectangle(425,225,435,250); setcolor(YELLOW);
setfillstyle(SOLID_FILL,LIGHTRED);
fillellipse(255,144,3,6);
fillellipse(305,144,3,6);
fillellipse(355,144,3,6);
fillellipse(180,219,3,6);
fillellipse(430,219,3,6);
setcolor(BROWN);
setfillstyle(HATCH_FILL,LIGHTGREEN);
fillellipse(160,210,6,6);
fillellipse(200,375,7,7);

Page 46 of 56
fillellipse(400,380,7,7);
fillellipse(475,325,6,6);
fillellipse(100,275,6,6);
fillellipse(425,150,7,7);
fillellipse(75,120,6,6); getch();
closegraph();
}

Page 47 of 56
Output

Page 48 of 56
18. Program to create Flying kite on screen.
#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<stdlib.h> void

main()

{ int gm,gd=DETECT; int i=

0,j=0,rnd_x=0,rnd_y,stop_me=0;

initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");

srand(time()); while(stop_me<=1000)

{ if(i>=180 &&j>=100

{ rnd_x=rand()%4 -

3; rnd_y=rand()%5

-4;

} else{

rnd_x=rand()%3;

rnd_y=rand()%3;

} line(200+i,200-j,250+i,250-j);

Page 49 of 56
line(200+i,200-j,150+i,250-j);

line(150+i,250-j,200+i,350-j);

line(200+i,350-j,250+i,250-j);

line(200+i,200-j,200+i,350-j);

arc(200+i,275-j,25,155,50);

line(0,500,200+i,225-j);

i=i+rnd_x; j=j+rnd_y;

stop_me=5+stop_me; delay(100);

clearviewport();

} getch();

closegraph();

Page 50 of 56
Output

Page 51 of 56
19. Program to Make a Fish.
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h> int
main() {
int gdriver = DETECT, gmode;
int errcode, i;
initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
errcode = graphresult();
if (errcode != grOk) {
getch();
printf("Error in graphics!!\n");
return 0;
}
for (i = 0; i <= 300; i = i + 3) {
delay(30); cleardevice();
setcolor(DARKGRAY); setfillstyle(SLASH_FILL,
DARKGRAY); pieslice(90 + i, getmaxy()/2,
135, 225, 50); floodfill(90 + i, getmaxy()/2,
DARKGRAY); setcolor(LIGHTGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
ellipse(150 + i, getmaxy()/2, 0, 360, 80, 25);
floodfill(150 + i, getmaxy()/2, 7);
setcolor(DARKGRAY); setfillstyle(SLASH_FILL,
DARKGRAY); pieslice(170 + i, getmaxy()/2,
205, 250, 40); floodfill(170 + i, getmaxy()/2,
DARKGRAY);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
circle(210 + i, getmaxy()/2 - 1, 2);
floodfill(210 + i, getmaxy()/2 - 1, BLACK);

setcolor(BLACK);
arc(210 + i, getmaxy()/2 - 1, 70, 225, 6);
delay(120); cleardevice();
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
pieslice(90 + i, getmaxy()/2, 135, 225, 50);
floodfill(90 + i, getmaxy()/2, DARKGRAY);
setcolor(LIGHTGRAY);
Page 52 of 56
setfillstyle(SOLID_FILL, LIGHTGRAY);
ellipse(150 + i, getmaxy()/2, 0, 360, 80, 25);
floodfill(150 + i, getmaxy()/2, LIGHTGRAY);
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
pieslice(170 + i, getmaxy()/2, 180, 210, 40);
floodfill(170 + i, getmaxy()/2, DARKGRAY);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
circle(210 + i, getmaxy()/2 - 1, 2);
floodfill(210 + i, getmaxy()/2 - 1, BLACK);
setcolor(BLACK);
arc(210 + i, getmaxy()/2 - 1, 70, 225, 6);
delay(120); cleardevice();
setcolor(DARKGRAY); setfillstyle(SLASH_FILL,
DARKGRAY); pieslice(90 + i, getmaxy()/2,
135, 225, 50); floodfill(90 + i, getmaxy()/2,
DARKGRAY); setcolor(LIGHTGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
ellipse(150 + i, getmaxy()/2, 0, 360, 80, 25);
floodfill(150 + i, getmaxy()/2, LIGHTGRAY);
setcolor(DARKGRAY); setfillstyle(SLASH_FILL,
DARKGRAY); pieslice(170 + i, getmaxy()/2,
125, 170, 40); floodfill(170 +i, getmaxy()/2,
DARKGRAY);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
circle(210 + i, getmaxy()/2 - 1, 2);
floodfill(210 + i, getmaxy()/2 - 1, BLACK);

setcolor(BLACK);
arc(210 + i, getmaxy()/2 - 1, 70, 225, 6);
}
cleardevice();
closegraph();
return 0; }

Page 53 of 56
Output

Page 54 of 56
20. Program to generate random circle.

#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>
#include <time.h>
#define WIDTH 800 #define HEIGHT
600 int randomInRange(int min, int
max) { return min + rand() % (max -
min + 1);
}
int main() { int gd = DETECT,
gm; initgraph(&gd, &gm,
NULL); srand(time(NULL));
int centerX = randomInRange(50, WIDTH - 50);
int centerY = randomInRange(50, HEIGHT - 50);
int radius = randomInRange(20, 100);
circle(centerX, centerY, radius); delay(5000); //
Display for 5 seconds closegraph(); return 0;
}

Page 55 of 56
Output

Page 56 of 56

You might also like