You are on page 1of 43

Fairfield Institute of Management and Technology

Practical Lab File

Computer Graphics

Subject Code – BCA (373)

SUBMITTED TO: SUBMITTED BY:


Mr. Shashikant Tiwari BHAVYA PUROHIT
IT Head 00390102021
IT Department BCA (Sem-V)

1
Computer Graphics
Lab

2
INDEX

S.No. Content Sign

1. Drawing objects like circle, rectangle,


polygon etc using graphic function.
2. Graphics Inbuilt functions
3. Line Drawing Algorithms (DDA &
Bresenham‟s Algorithm)
4. Circle Algorithms
5. Translation in 2D
6. Rotation in 2D
7. Scaling in 2D
8. Reflection in 2D
9. Shearing in 2D
10. Cohen Sutherland's Algorithm
11. Program to rotate a circle outside another
circle
12. Program to draw Flying Balloons
13. Show Bouncing Ball Animation
14. Making an Analog Clock
15. Show changing radius of circle

3
PRACTICAL 1: Drawing objects like circle, rectangle,
polygon etc using graphic function.
CODE :
1) Circle
#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
circle(250, 200, 50);
getch();
closegraph();
return 0; }

OUTPUT :

2) Rectangle
#include <graphics.h>
int main() {
int gd = DETECT, gm;
int left = 150, top = 150;

4
int right = 450, bottom = 450;
initgraph(&gd, &gm, "");
rectangle(left, top, right, bottom);
getch();
closegraph();
return 0; }

OUTPUT:

3) Polygon
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main() {
int gdriver, gmode;
int poly[10];
gdriver = DETECT;
initgraph(&gdriver, &gmode, "D:\\TURBOC3\\BGI");
poly[0] = 20;
5
poly[1] = 100;
poly[2] = 120;
poly[3] = 140;
poly[4] = 240;
poly[5] = 260;
poly[6] = 120;
poly[7] = 320;
poly[8] = poly[0];
poly[9] = poly[1];
drawpoly(5, poly);
getch();
closegraph();
return 0; }

OUTPUT:

6
PRACTICAL 2: Graphics Inbuilt functions
CODE:
#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
circle(250, 200, 50);
getch();
closegraph();
return 0; }

OUTPUT:

7
PRACTICAL 3: Line Drawing Algorithms (DDA &
Bresenham‟s Algorithm)
CODE:
• DDA Algorithm
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main() {
intgd = DETECT ,gm, i;
float x, y,dx,dy,steps;
int x0, x1, y0, y1;
initgraph(&gd, &gm, "C:\\TC\\BGI");
setbkcolor(WHITE);
x0 = 100 , y0 = 200, x1 = 500, y1 = 300;
dx = (float)(x1 - x0);
dy = (float)(y1 - y0);
if(dx>=dy) {
steps = dx; }
else {
steps = dy; }
dx = dx/steps;
dy = dy/steps;
x = x0;
y = y0;
i = 1;

8
while(i<= steps) {
putpixel(x, y, RED);
x += dx;
y += dy;
i=i+1; }
getch();
closegraph(); }

OUTPUT:

• Bresenham‟s Algorithm
#include<stdio.h>
#include<graphics.h>
void drawline(int x0, int y0, int x1, int y1) {
int dx, dy, p, x, y;
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;

9
p=2*dy-dx;
while(x<x1) {
if(p>=0) {
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
}
else {
putpixel(x,y,7);
p=p+2*dy;}
x=x+1;
} }
int main() {
int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
printf("Enter co-ordinates of first point: ");
scanf("%d%d", &x0, &y0);
printf("Enter co-ordinates of second point: ");
scanf("%d%d", &x1, &y1);
drawline(x0, y0, x1, y1);
return 0; }

OUTPUT:

10
PRACTICAL 4: Circle Algorithms
CODE:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
void EightWaySymmetricPlot(int xc,int yc,int x,int y) {
putpixel(x+xc,y+yc,RED);
putpixel(x+xc,-y+yc,YELLOW);
putpixel(-x+xc,-y+yc,GREEN);
putpixel(-x+xc,y+yc,YELLOW);
putpixel(y+xc,x+yc,12);
putpixel(y+xc,-x+yc,14);
putpixel(-y+xc,-x+yc,15);
putpixel(-y+xc,x+yc,6); }
void BresenhamCircle(int xc,int yc,int r) {
int x=0,y=r,d=3-(2*r);
EightWaySymmetricPlot(xc,yc,x,y);
while(x<=y) {
if(d<=0) {
d=d+(4*x)+6; }
else {
d=d+(4*x)-(4*y)+10;
y=y-1; }
x=x+1;
11
EightWaySymmetricPlot(xc,yc,x,y); }
}
int main(void) {
int xc,yc,r,gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");
errorcode = graphresult();
if (errorcode != grOk) {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); }
printf("Enter the values of xc and yc :");
scanf("%d%d",&xc,&yc);
printf("Enter the value of radius :");
scanf("%d",&r);
BresenhamCircle(xc,yc,r);
getch();
closegraph();
return 0; }

OUTPUT:

12
PRACTICAL 5: Translation in 2D
CODE:
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main() {
int gd=DETECT,gm;
int l[2][2],v[2]={10,15},i=0,j;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("Enter the initial and final coordinates of a line ");
while(i<2) {
printf("x%d and y%d = ",i,i);
j=0;
scanf("%d",&l[i][j]);
scanf("%d",&l[i][j+1]);
i++; }
line(l[0][0],l[0][1],l[1][0],l[1][1]);
setcolor(BLUE);
line(l[0][0]+v[0],l[0][1]+v[1],l[1][0]+v[0],l[1][1]+v[1]); // Adding Translation
vector in it to change the position
getch();
closegraph(); }

13
OUTPUT:

14
PRACTICAL 6: Rotation in 2D
CODE:
#include<stdio.h>
#include<graphics.h>
#include<math.h>
int main() {
intgd=0,gm,x1,y1,x2,y2;
double s,c, angle;
initgraph(&gd, &gm, "C:\\TC\\BGI");
setcolor(RED);
printf("Enter coordinates of line: ");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
cleardevice();
setbkcolor(WHITE);
line(x1,y1,x2,y2);
getch();
setbkcolor(BLACK);
printf("Enter rotation angle: ");
scanf("%lf", &angle);
setbkcolor(WHITE);
c = cos(angle *3.14/180);
s = sin(angle *3.14/180);
x1 = floor(x1 * c + y1 * s);
y1 = floor(-x1 * s + y1 * c);
x2 = floor(x2 * c + y2 * s);
y2 = floor(-x2 * s + y2 * c);
15
cleardevice();
line(x1, y1 ,x2, y2);
getch();
closegraph();
return 0; }

OUTPUT:

16
PRACTICAL 7: Scaling in 2D
CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main(){
int x,y,x1,y1,x2,y2;
int scl_fctr_x,scl_fctr_y;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\n\t\t\t Please enter first coordinate of Triangle = ");
scanf("%d %d",&x,&y);
printf("\n\t\t\t Please enter second coordinate of Triangle = ");
scanf("%d %d",&x1,&y1);
printf("\n\t\t\t Please enter third coordinate of Triangle = ");
scanf("%d %d",&x2,&y2);
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
printf("\n\t\t\t Now Enter Scaling factor x and y = ");
scanf("%d %d",&scl_fctr_x,&scl_fctr_y);
x = x* scl_fctr_x;
x1 = x1* scl_fctr_x;
x2 = x2* scl_fctr_x;
y = y* scl_fctr_y;
y1 = y1* scl_fctr_y;
17
y2= y2 * scl_fctr_y ;
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
getch();
closegraph(); }

OUTPUT:

18
PRACTICAL 8: Reflection in 2D
CODE:
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
void main() {
int gm, gd = DETECT, ax, x1 = 100;
int x2 = 100, x3 = 200, y1 = 100;
int y2 = 200, y3 = 100;
initgraph(&gd, &gm, "");
cleardevice();
line(getmaxx() / 2, 0, getmaxx() / 2,
getmaxy());
line(0, getmaxy() / 2, getmaxx(),
getmaxy() / 2);
printf("Before Reflection Object" " in 2nd Quadrant");
setcolor(14);
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
getch();
printf("\nAfter Reflection");
setcolor(4);
line(getmaxx() - x1, getmaxy() - y1,
getmaxx() - x2, getmaxy() - y2);
line(getmaxx() - x2, getmaxy() - y2,
19
getmaxx() - x3, getmaxy() - y3);
line(getmaxx() - x3, getmaxy() - y3,
getmaxx() - x1, getmaxy() - y1);
setcolor(3);
line(getmaxx() - x1, y1,
getmaxx() - x2, y2);
line(getmaxx() - x2, y2,
getmaxx() - x3, y3);
line(getmaxx() - x3, y3,
getmaxx() - x1, y1);
setcolor(2);
line(x1, getmaxy() - y1, x2,
getmaxy() - y2);
line(x2, getmaxy() - y2, x3,
getmaxy() - y3);
line(x3, getmaxy() - y3, x1,
getmaxy() - y1);
getch();
closegraph(); }

OUTPUT:

20
PRACTICAL 9: Shearing in 2D
CODE:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main() {
int gd=DETECT,gm;
int x,y,x1,y1,x2,y2,x3,y3,shear_f;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\n please enter first coordinate = ");
scanf("%d %d",&x,&y);
printf("\n please enter second coordinate = ");
scanf("%d %d",&x1,&y1);
printf("\n please enter third coordinate = ");
scanf("%d %d",&x2,&y2);
printf("\n please enter last coordinate = ");
scanf("%d %d",&x3,&y3);
printf("\n please enter shearing factor x = ");
scanf("%d",&shear_f);
cleardevice();
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x,y);
setcolor(RED);
x=x+ y*shear_f;
21
x1=x1+ y1*shear_f;
x2=x2+ y2*shear_f;
x3=x3+ y3*shear_f;
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x,y);
getch();
closegraph(); }

OUTPUT:

22
PRACTICAL 10: Cohen Sutherland's Algorithm
CODE:
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
class data {
int gd, gmode, x, y, xmin,ymin,ymax,xmax;
int a1,a2;
float x1, y1,x2,y2,x3,y3;
int xs, ys, xe, ye;
float maxx,maxy;
public:
void getdata ();
void find ();
void clip ();
void display (float, float,float,float);
void checkonof (int);
void showbit (int); };
void data :: getdata () {
cout<<"Enter the minimum and maximum coordinate of window (x, y) ";
cin >>xmin>>ymin>>xmax>>ymax;
cout<<"Enter the end points of the line to be clipped";
cin >>xs>>ys>>xe>>ye;
display (xs, ys, xe,ye); }
void data :: display (float, xs, float, ys,float xe, float ye) {

23
int gd=DETECT;
initgraph (&gd,&gmode, "");
maxx=getmaxx();
maxy=getmaxy();
line (maxx/2,0,maxx/2,maxy);
line (0, maxy/2,maxx,maxy/2);
rectangle (maxx/2+xmin,maxy/2-ymax,maxx/2+xmax,maxy/2-ymin);
line (maxx/2+xs,maxy/2-ys,maxx/2+xe,maxy/2-ye);
getch(); }
void data :: find () {
a1=0;
a2=0;
if ((ys-ymax)>0)
a1+=8;
if ((ymin-ys)>0)
a1+=4;
if ((xs-xmax)>0)
a1+=2;
if ((xmin-xs)>0)
a1+=1;
if ((ye-ymax)>0)
a2+=8;
if ((ymin-ye)>0)
a2+=4;
if ((xe-xmax)>0)
a2+=2;

24
if ((xmin-xe)>0)
a2+=1;
cout<<"\nThe area code of Ist point is ";
showbit (a1);
getch ();
cout <<"\nThe area code of 2nd point is ";
showbit (a2);
getch (); }
void data :: showbit (int n) {
int i,k, and;
for (i=3;i>=0;i--) {
and =1<<i;
k = n?
k ==0?cout<<"0": cout<<"1\""; } }
void data ::clip() {
int j=a1&a2;
if (j==0) {
cout<<"\nLine is perfect candidate for clipping";
if (a1==0) {
else {
checkonof(a1);
x2=x1;y2=y1; }
if (a2=0) {
x3=xe; y3=ye; }
else {
checkonof (a2);

25
x3=x1; y3=y1; }
xs=x2; ys=y2;xe=x3;ye=y3;
cout << endl;
display (xs,ys,xe,ye);
cout<<"Line after clipping";
getch () }
else if ((a1==0) && (a2=0)) {
cout <<"\n Line is in the visible region";
getch (); } }
void data :: checkonof (int i) {
int j, k,l,m;
1=i&1;
x1=0;y1=0;
if (1==1) {
x1=xmin;
y1=ys+ ((x1-xs)/ (xe-xs))*(ye-ys); }
j=i&8;
if (j>0) {
y1=ymax;
x1=xs+(y1-ys)/(ye-ys))*(xe-xs); }
k=i & 4;
if (k==1) {
y1=ymin;
x1=xs+((y1-ys)/(ye-ys))*(xe-xs); }
m= i&2;
if (m==1) {

26
x1=xmax;
y1=ys+ ((x1-xs)/ (xe-xs))*(ye-ys); }
main () {
data s;
clrscr();
s.getdata();
s.find();
getch();
closegraph ();
return (); }

OUTPUT:

27
PRACTICAL 11: Program to rotate a circle outside
another circle
CODE:
#include <conio.h>
#include <graphics.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void drawEllipse(int xc, int yc, int a, int b,
float alpha, int color) {
float t = 3.14 / 180;
alpha = 360 - alpha;
setcolor(color);
int theta;
for (int i = 0; i < 360; i += 1) {
theta = i;
int x = a * cos(t * theta) * cos(t * alpha) + b * sin(t * theta) * sin(t * alpha);
int y = b * sin(t * theta) * cos(t * alpha) - a * cos(t * theta) * sin(t * alpha);
putpixel(xc + x, yc - y, color); } }
void slidePattern(int xc, int yc, int r, int a, int b, int alpha, float p, int color) {
setcolor(color);
float t = 3.14 / 180;
float t1, t2, d;
float angle = (p * alpha);
28
t1 = cos(t * fmod(angle, 360));
t2 = sin(t * fmod(angle, 360));
t1 *= t1;
t2 *= t2;
t1 = t1 / (a * a);
t2 = t2 / (b * b);
d = sqrt(t1 + t2);
d = 1 / d;
int draw_x = xc + (r + d) * cos(t * alpha);
int draw_y = yc - (r + d) * sin(t * alpha);
int draw_ang = angle + alpha;
drawEllipse(draw_x, draw_y, a, b, draw_ang, color); }
void ellipseovercircle(int xc, int yc, int r, int a, int b) {
float theta = 0;
double h, p1;
h = (a * a) + (b * b);
h /= 2;
p1 = sqrt(h);
p1 /= r;
p1 = 1 / (p1);
for (;; theta -= 1) {
slidePattern(xc, yc, r, a, b, theta, p1, WHITE);
circle(xc, yc, r);
delay(25);
slidePattern(xc, yc, r, a, b, theta, p1, BLACK); } }
int main() {

29
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int maxx = getmaxx();
int maxy = getmaxy();
ellipseovercircle(maxx / 2, maxy / 2, 100, 40, 28);
closegraph();
return 0; }

OUTPUT:

30
PRACTICAL 12: Program to draw Flying Balloons
CODE:
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\" "turboc3\\bgi");
setfillstyle(SOLID_FILL, BLUE);
floodfill(100, 100, 15);
setfillstyle(SOLID_FILL, RED);
circle(550, 200, 100);
floodfill(552, 202, 15);
setfillstyle(SOLID_FILL, WHITE);
line(650, 200, 630, 400);
line(650, 200, 620, 400);
line(620, 400, 630, 400);
floodfill(625, 398, 15);
line(450, 200, 470, 400);
line(450, 200, 480, 400);
line(470, 400, 480, 400);
floodfill(475, 398, 15);
setfillstyle(SOLID_FILL, BROWN);
rectangle(450, 400, 650, 500);
floodfill(452, 402, 15);

31
setfillstyle(XHATCH_FILL, YELLOW);
line(450, 430, 650, 430);
floodfill(452, 498, 15);
getch();
closegraph(); }

OUTPUT:

32
PRACTICAL 13: Show Bouncing Ball Animation
CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
void main() {
int gd = DETECT, gm;
int i, x, y, flag=0;
initgraph(&gd, &gm, "C:\\TC\\BGI");
x = getmaxx()/2;
y = 30;
while(!kbhit()) {
if(y >= getmaxy()-30 || y <= 30)
flag = !flag;
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
circle(x, y, 30);
floodfill(x, y, RED);
delay(25);
cleardevice();
if(flag) {
y = y + 2; }
else {

33
y = y - 2; } }
getch();
closegraph(); }

OUTPUT:

34
PRACTICAL 14: Making an Analog Clock
CODE:
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
int main(void) {
int xmax, ymax, x, y, i = 0, j = 0, k = 0, m = 0, s = 0, h = 0, m1 = 0;
float l = 0.0;
int graphic_driver = DETECT, graphic_mode;
initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
xmax = getmaxx();
ymax = getmaxy();
x = xmax / 2;
y = ymax / 2;
setcolor(15);
setbkcolor(0);
rectangle(x + 150, y - 200, x + 300, y - 170);
line(x + 200, y - 200, x + 200, y - 170);
line(x + 250, y - 200, x + 250, y - 170);
circle(x, y, 179);
circle(x, y, 180);
setfillstyle(0, 0);
floodfill(x, y, 0);
settextstyle(1, 0, 4);
outtextxy(x - 200, y - 25, "9");
35
outtextxy(x + 186, y - 25, "3");
outtextxy(x - 20, y - 220, "12");
outtextxy(x - 10, y + 176, "6");
outtextxy(x + 90, y - 195, "1");
outtextxy(x + 165, y - 120, "2");
outtextxy(x + 155, y + 80, "4");
outtextxy(x + 86, y + 152, "5");
outtextxy(x - 109, y + 148, "7");
outtextxy(x - 180, y + 72, "8");
outtextxy(x - 195, y - 120, "10");
outtextxy(x - 120, y - 195, "11");
settextstyle(1, 0, 3);
outtextxy(0, ymax - 30, "PRESS ANY KEY FOR STOP");
outtextxy(x + 150, y + 210, "PUSKAR JASU");
settextstyle(1, 0, 6);
outtextxy(0, 0, "CLOCK");
while (!kbhit()) {
setcolor(14);
if (m == 60) {
if (k <= 90) {
setcolor(14);
pieslice(x, y, 91 - k, 90 - k, 175);
sound(440);
delay(10);
nosound();
setcolor(0);

36
pieslice(x, y, 97 - k, 96 - k, 175); }
if (k > 90) {
setcolor(14);
pieslice(x, y, 451 - k, 450 - k, 175);
sound(440);
delay(10);
nosound();
setcolor(0);
pieslice(x, y, 457 - k, 456 - k, 175); }
if (k == 360)
k = 0;
k = k + 6; }
else {
if (k <= 90) {
pieslice(x, y, 91 - k, 90 - k, 175);
setcolor(0);
pieslice(x, y, 97 - k, 96 - k, 175); }
if (k > 90) {
setcolor(14);
pieslice(x, y, 451 - k, 450 - k, 175);
setcolor(0);
pieslice(x, y, 457 - k, 456 - k, 175); } }
setcolor(4);
if (j == 60 * 5) {
if (l <= 90) {
setcolor(4);

37
pieslice(x, y, 91 - l, 90 - l, 175);
sound(880);
delay(20);
nosound();
setcolor(0);
pieslice(x, y, 93.5 - l, 92.5 - l, 175); }
if (l > 90) {
setcolor(4);
pieslice(x, y, 451 - l, 450 - l, 175);
sound(880);
delay(20);
nosound();
setcolor(0);
pieslice(x, y, 453.5 - l, 452.5 - l, 175); }
if (l == 360)
l = 0;
l = l + 2.5; }
else {
if (l <= 90) {
setcolor(4);
pieslice(x, y, 91 - l, 90 - l, 175);
setcolor(0);
pieslice(x, y, 93.5 - l, 92.5 - l, 175); }
if (l > 90) {
setcolor(4);
pieslice(x, y, 451 - l, 450 - l, 175);

38
setcolor(0);
pieslice(x, y, 453.5 - l, 452.5 - l, 175); } }
if (i <= 90) {
setcolor(10);
pieslice(x, y, 91 - i, 90 - i, 175);
delay(1000);
sound(220);
delay(5);
nosound();
setcolor(0);
pieslice(x, y, 91 - i, 90 - i, 175); }
if (i > 90) {
setcolor(10);
pieslice(x, y, 451 - i, 450 - i, 175);
delay(1000);
sound(220);
delay(5);
nosound();
setcolor(0);
pieslice(x, y, 451 - i, 450 - i, 175); }
if (i == 360)
i = 0;
i = i + 6;
s = i / 6;
if (j == 60 * 5)
j = 0;

39
j++;
if (m == 60)
m = 0;
m++;
if (s == 60) {
m1++;
s = 0; }
if (h == 24)
h = 0;
if (m1 == 60) {
h++;
m1 = 0; }
gotoxy(62, 4);
printf("%02d", h);
gotoxy(68, 4);
printf("%02d", m1);
gotoxy(74, 4);
printf("%02d", s);
s++; }
getch();
closegraph();
return 0; }

40
OUTPUT:

41
PRACTICAL 15: Show changing radius of circle
CODE:
#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;
drawCircle(xc, yc, x, y);
42
delay(50); } }
int main() {
int xc = 50, yc = 50, r = 30;
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
circleBres(xc, yc, r);
return 0; }

OUTPUT:

43

You might also like