Está en la página 1de 43

Computer Graphics

Lab Manual
UNIVERSITY SYLLABUS FOR PRACTICALS
1. Implementation of line drawing , circle drawing & ellipse algorithm.

2. Programs to implement 2D transformation( Line , Cube , Rectangle)

 Scaling
 Translation
 Rotation

3. Program to implement simple clipping algorithm. Implementation of Bezier


Curve.
List Of Experiments
1. Write a program to draw the pixel(x,y) and display the color in which
pixel(x,y) is illuminated on the screen.
2. Write a program to implement DDA line drawing algorithm.
3. Write a program to implement Bresenham’s Line drawing algorithm.
4. Write a program to implement Bresenham’s Circle drawing algorithm.
5. Write a program to implement Bresenham’s Ellipse drawing algorithm.
6. Write a program to implement Boundary Fill algorithm.
7. Write a program to implement Flood Fill algorithm.
8. Write a program to draw Rectangle from (100,200) pixel to (400,500) pixel .
9. Write a program to draw a Circle with center (150,150) pixel and radius 25.
10. Write a program to draw a Hexagon on the screen.
11. Write a program to implement Composite Transformations.
12. Write a program to implement Basic Transformations (translation ,rotation ,
and scaling on a rectangle).
13. Write a program to implement Cohen Sutherland algorithm.
14. Write a program to implement Bezier Curve.
15. Write a program to implement B-Spline Curve.
16. Write a program to implement animation using C function.
17. Write a program to implement a cartoon using C function.
18. Write a program to draw a chain of circles.
19. Write a program to draw concentric circles.
20. Write a program to fill an ellipse by reducing the size of an ellipse.
EXPERIMENT No. 01

AIM : Write a program to draw the pixel(x,y) and display the color
in which pixel(x,y) is illuminated on the screen.

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gm,&gd,”\\tc\\bgi”);
putpixel(100,200,RED);
i=getpixel(100,200);
printf(“The color of pixel is : “);
printf(“%d”,i);
getch();
}

INPUT

100,200,RED

OUTPUT
.
The color of pixel is : 4 (RED)
EXPERIMENT No. 02

AIM :Write a program to implement DDA line drawing algorithm.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define Round(a) ((int) (a+0.5))

void main()
{
int xa,ya,xb,yb,dx,dy,steps,k,a;

float Xincr,Yincr,X,Y;

int i,gd=DETECT,gm;

initgraph(&gd,&gm,"d:\\tc\\bgi");

printf("Enter the value of (xa , ya ) & (xb , yb)");

scanf("%d%d%d%d",&xa,&ya,&xb,&yb);

dx=xb-xa;
dy=yb-ya ;

if(abs(dx)>abs(dy))

steps=abs(dx);

else

steps=abs(dy);

Xincr=(float)dx/steps;

Yincr=(float)dy/steps;
X=xa;Y=yb;

putpixel(X,Y,7);
for(i=1;i<steps;i++)

X=X+Xincr;

Y=Y+Yincr;

putpixel(Round(X),Round(Y),7);

}
getch();
closegraph();

INPUT

Enter the value of (xa , ya ) & (xb , yb) :-

190
42
25
200

OUTPUT
EXPERIMENT No. 03
AIM :Write a program to implement Bresenham’s line drawing

PROGRAM

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

void main()
{
int Xa,Ya,Xb,Yb;

int X,Y,dx,dy,p,Xend;

int gd=DETECT,gm;

initgraph(&gd,&gm, "d:\\tc\\bgi");

printf("Enter the value of (Xa , Ya ) & (Xb , Yb)");

scanf("%d%d%d%d",&Xa,&Ya,&Xb,&Yb);

dx=abs(Xa-Xb);
dy=abs(Ya-Yb);

p=2*dy-dx;

if(Xa>Xb)

X=Xb;Y=Ya;

Xend=Xa;

}
else

X=Xa;Y=Ya;

Xend=Xb;

}
putpixel(X,Y,7);
while(X<Xend)

X++;

if(p<0)

p+=2*dy;

else

Y++;

p+=2*(dy-dx);

putpixel(X,Y,7);

getch();

closegraph();

INPUT
Enter the value of (Xa , Ya ) & (Xb , Yb) :-
100
110
240
250
OUTPUT
EXPERIMENT No. 04
AIM :Write a program to implement Bresenham’s Circle algorithm.

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

void circle_1 ( int , int ) ;

void main ( )
{

int x , y , p , r , i ;

int gd=DETECT , gm ;

initgraph ( &gd , &gm , "\\tc\\bgi") ;

setbkcolor (WHITE) ;

printf ( "Enter the radius = ") ;

scanf ( "%d" , &r) ;

x=0;y=r;

p=3-2*r;

putpixel ( x , y ,2 ) ;

while ( x <= y )

if (p < 0)

p+= 4 * x + 6;

else
{

p+= 4 * ( x - y) + 10 ;

y -- ;

x ++ ;

circle_1( x , y) ;

getch ( ) ;

closegraph ( ) ;

}
void circle_1 ( int a , int b)

int x , y ;

x=a;y=b;

putpixel ( 300 + x , 300 + y , 1 ) ;

putpixel ( 300 + y , 300 + x , 1 ) ;

putpixel ( 300 - x , 300 + y , 1 ) ;

putpixel ( 300 + x , 300 - y , 1 ) ;

putpixel ( 300 - x , 300 - y , 1 ) ;

putpixel ( 300 - y , 300 - x , 1 ) ;

putpixel ( 300 + y , 300 - x , 1 ) ;

putpixel ( 300 - y , 300 + x , 1 ) ;

INPUT
Enter the radius = 80
OUTPUT
EXPERIMENT No. 05
AIM :Write a program to implement Bresenham’s ellipse algorithm.

PROGRAM

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

void ellip(int ,int );

void main()
{

int a,b;

int x=0,y;

int aa,bb,aa2,bb2;

int fx=0,fy;

int p;

int gd=DETECT,gm;

initgraph(&gd,&gm,"d:\\tc\\bgi");

printf("\n Enter the value of a and b");

scanf("%d%d",&a,&b);

y=b;aa=a*a;

bb=b*b;aa2=aa*2;
bb2=bb*2;fy=aa2*b;

p=bb-(aa*b)+(0.25*aa);
setbkcolor(1);

while(fx<fy)

x++;

fx=fx+bb2;

if(p<0)

p+=fx+ bb;

else

y--;

fy=fy-aa2;

p+=fx+bb-fy;

x++ ;

ellip(x,y);
}

getch();

closegraph();

void ellip(int a,int b)

int x,y;

x=a;y=b;
putpixel(300+x,300+y,4);

putpixel(300+y,300+x,4);

putpixel(300-x,300+y,4);

putpixel(300+x,300-y,4);

putpixel(300-x,300-y,4);

putpixel(300-y,300-x,4);

putpixel(300+y,300-x,4);

putpixel(300-y,300+x,4);
}

INPUT

Enter the value of a and b =

16
25

OUTPUT
EXPERIMENT No. 06
AIM :Write a program to implement Boundary fill algorithm.
PROGRAM

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

void boundary_fill(int x,int y,int fill_color,int boundary_color);

void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"D:\\tc\\bgi");
setcolor(WHITE);
putpixel(310,230,RED);
circle(320,240,40);
boundary_fill(320,240,LIGHTGREEN,WHITE);
getch();
}
void boundary_fill(int x,int y,int fill_color,int boundary_color)
{

if(getpixel(x,y)!=boundary_color && getpixel(x,y)!=fill_color)


{
putpixel(x,y,fill_color);
boundary_fill(x+1,y,fill_color,boundary_color);
boundary_fill(x-1,y,fill_color,boundary_color);
boundary_fill(x,y+1,fill_color,boundary_color);
boundary_fill(x,y-1,fill_color,boundary_color);
}
}

OUTPUT
EXPERIMENT No. 07

AIM :Write a program to implement Flood fill algorithm.

PROGRAM

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

void ffill(int x,int y,int fill,int old);

void main()

int gd=DETECT,gm;
int old=BLACK;

initgraph(&gd,&gm,"D:\\tc\\bgi");

setcolor(YELLOW);

line(310,230,330,230);
setcolor(LIGHTGREEN);
line(330,230,330,250);
setcolor(MAGENTA);
line(330,250,310,250);
setcolor(CYAN);
line(310,250,310,230);
putpixel(321,241,GREEN);
ffill(320,240,LIGHTBLUE,old);

getch();

void ffill(int x,int y,int fill,int old)

if(getpixel(x,y)==old)
{
putpixel(x,y,fill);
ffill(x+1,y,fill,old);

ffill(x-1,y,fill,old);

ffill(x,y+1,fill,old);

ffill(x,y-1,fill,old);

ffill(x-1,y-1,fill,old);
ffill(x+1,y-1,fill,old);
ffill(x+1,y-1,fill,old);
ffill(x-1,y+1,fill,old);

OUTPUT
EXPERIMENT No. 08
AIM :Write a program to draw Rectangle from (100,200) pixel to
(400,500) pixel.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"\\tc\\bgi");
setpalette(0,3);
moveto(100,200);
lineto(100,400);
lineto(400,400);
lineto(400,200);
lineto(100,200);
getch();
restorecrtmode();
return;
getch();
}

OUTPUT
EXPERIMENT No. 09

AIM :Write a program to draw a Circle with center (150,150) pixel and
radius 25.

DESCRIPTION: With the help of this program ,we are going to draw a Circle having
a center (150,150) pixel. And radius of the circle is 25.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
float x1,y1,r;
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"\\tc\\bgi");
printf("Enter the center 'x1','y1' and radius 'r':\n");
scanf("%f%f%f",&x1,&y1,&r);
setpalette(0,12);
/*background will change from 0-block to 12*/
getch();
setcolor(3);
/*circle will be drawn in 3-green color*/
circle(x1,y1,r);
getch();
restorecrtmode();
return;
}

OUTPUT
EXPERIMENT No. 10

AIM :Write a program to draw a Hexagon on the screen.

DESCRIPTION: In this program , we are going to draw a hexagon on the screen


using line(),moveto() & lineto().

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(RED);
moveto(100,100);
lineto(75,120);
lineto(100,140);
lineto(140,140);
lineto(165,120);
lineto(140,100);
lineto(100,100);
setfillstyle(SOLID_FILL,GREEN);
floodfill(150,120,RED);
getch();
}

OUTPUT
EXPERIMENT No. 11

AIM :Write a program to implement Composite Transformation .

PROGRAM

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

void main( )

int gd = DETECT , gm ;

int x1 , y1 , x4 , y4 , tx1 , ty1 , tx2 , ty2 ;

clrscr ( ) ;

initgraph (&gd , &gm ,”\\tc\\bgi”) ;

rectangle ( 250 , 250 , 250 , 250 ) ;

printf ( “ Enter the End Points”) ;

scanf ( “ %d %d”, &tx1 , &ty1 ) ;

x1 = 250 ; x4 = 300 ;

y1 = 250 ; y4 = 300 ;

x1 = x1 + tx1 ;

y1 = y1 + ty1 ;

x4 = x4 + tx1 ;

y4 = y4 + ty1 ;

rectangle ( x1 , y1 , x4 , y4 ) ;

getch ( ) ;

printf ( “ Enter the value ” ) ;

scanf ( “ %d %d” , &tx2 , &ty2 ) ;


x1 = x1 + tx2 ; x4 = x4 + tx2 ;

y1 = y1 + ty2 ; y4 = y4 + ty2 ;

rectangle ( x1 , y1 , x4 , y4 ) ;

getch ( ) ;

closegraph ( ) ;

INPUT

Enter the End Points

90
80
OUTPUT

INPUT

Enter the value 30 40

OUTPUT
EXPERIMENT No. 12

AIM :Write a program to implement Basic Transformations


( translation , rotation, and scaling on a Rectangle).

PROGRAM

// (A) SCALING//

# include < stdio.h >


# include < conio.h >
# include < graphics.h >

void main ( )

float t ;

int gd = DETECT , gm ;

int x1 ,y1, x4, y4, sx1, sy1 ;

initgraph ( &gd , &gm , “\\tc\\bgi” ) ;

x1 = 50 ; y1 = 50 ;

x4 = 130 ; y4 = 130 ;

rectangle ( x1, y1, x4, y4 ) ;

getch ( ) ;

cleardevice ( ) ;

printf ( “ \n Enter The Scaling Vector :” ) ;

scanf ( “ %d %d ”, &sx1, &sy1 ) ;

x1 =x1 * sx1 ;

y1 = y1 * sy1 ;

x4 = x4 * sx1 ;

y4 = y4 * sy1 ;
rectangle ( x1 , y1 , x4 , y4 ) ;

getch ( ) ;

closegraph ( ) ;

}
OUTPUT

INPUT

Enter The Scaling Vector :- 2 3

OUTPUT

PROGRAM

// (B) TRANSLATION//

# include < stdio.h >


# include < conio.h >
# include < graphics.h >

void main ( )

float t ;

int gd = DETECT , gm ;
int x1 ,y1, x4, y4, tx1, ty1 ,ty2 ;

initgraph ( &gd , &gm , “\\tc\\bgi” ) ;

printf ( “ Enter The Four Co-ordinate For Rectangle :”) ;

scanf ( “ %d %d %d %d ” , &x1 , &y1 , &x4 , &y4 ) ;

rectangle ( x1, y1, x4, y4 ) ;

getch ( ) ;

cleardevice ( ) ;

printf ( “ \n Enter The Translation Vector :” ) ;

scanf ( “ %d %d ”, &tx1, &ty1 ) ;

x1 =x1 * tx1 ;

y1 = y1 * ty1 ;

x4 = x4 * tx1 ;

y4 = y4 * ty1 ;

rectangle ( x1 , y1 , x4 , y4 ) ;

getch ( ) ;

closegraph ( ) ;

INPUT

Enter The Four Co-ordinate For Rectangle : 50 50 100 100

OUTPUT
INPUT

Enter The Translation Vector : - 70 70

OUTPUT

PROGRAM

// (C) ROTATION//

# include < stdio.h >


# include < conio.h >
# include < graphics.h >
# include < math.h >

void main ( )

{
float t ;

int gd = DETECT , gm ;

int x1 ,y1, x4, y4 ;

initgraph ( &gd , &gm , “\\tc\\bgi” ) ;

printf ( “ Enter Four Co-ordinates ” ) ;

scanf ( “ %d 5d %d %d ” , &x1 , &y1 , &x4 , &y4 ) ;

rectangle ( x1, y1, x4, y4 ) ;

getch ( ) ;
cleardevice ( ) ;

printf ( “ \n Enter Angle For Rotation :” ) ;

scanf ( “ %f ”, &t ) ;

t = ( t * 2 * 3.14 ) / 360 ;

x1 = ( x1 * cos ( t ) + y1 * sin ( t ) ) ;

y1 = ( - x1 * sin ( t ) + y1 * cos ( t ) ) ;

x4 = ( x4 * cos ( t ) + y4 * sin ( t ) ) ;

y4 = ( - x4 * sin ( t ) + y4 * cos ( t ) ) ;

rectangle ( x1 , y1 , x4 , y4 ) ;

getch ( ) ;

closegraph ( ) ;

}
INPUT

Enter Four Co-ordinates : - 50 50 110 110

OUTPUT

INPUT

Enter Angle For Rotation : - 30

OUTPUT
EXPERIMENT No. 13
AIM : Write a program to implement Cohen Sutherland line Clipping

PROGRAM

#include < stdio.h>


#include < conio.h>
#include < graphics.h>
#define ROUND ( a ) ( ( int ) ( a + 0.5 ))
#define LEFT_EDGE ox1
#define RIGHT_EDGE ox2
#define BOTTOM_EDGE ox4
#define TOP_EDGE ox8

unsigned char encode ( wcpt2 pt, dept winmin, dept winmax)

unsigned char code = ox00 ;

if ( pt.x < winmin.x)

code = code | LEFT_EDGE ;

if ( pt.x > winmax.x)

code = code | RIGHT_EDGE ;

if ( pt.y < winmin.y)

code = code | BOTTOM_EDGE ;

if ( pt.y > winmax.y)

code = code | TOP_EDGE ;

return ( code ) ;

void swappts ( unsigned char *c1, unsigned char *c2)

unsigned char temp ;


temp = *c1 ;

*c1 = *c2 ;

*c2 = temp ;

void dipline ( dept winmin, dept winmax, wept2 p1, wept 2 p2)

unsigned char code1,code2 ;

int done = FALSE, draw = FALSE ;

float m ;

while ( ! done )

code1 = emode ( p1, winmin, winmax) ;

code2 = emode ( p2, winmin, winmax) ;

if ( ACCEPT ( code1,code2 ))

done = FALSE ;

else

if ( REJECT ( code1, code2))

done = TRUE ;

else

if ( INSIDE ( code1))

swappts ( &p1, &p2) ;

swapcodes ( &code1, &code2) ;

if ( p2.x ! = p1.x)

{
m = ( p2.y – p1.y) / ( p2.x – p1.x) ;

if ( code1 & LEFT_EDGE)

p1.y + = ( winmin.x – p1.x ) * m ;

p1.x + = winmin.x ;

else

if ( code & RIGHT_EDGE)

p1.y + = ( winmax.x – p1.x) * m ;

p1.x = winmax.x ;
}

else

if ( code & BOTTOM_EDGE)

if ( p2.x ! = p1.x)

p1.x + = ( winmin.y – p1.y) / m ;


p1.y = winmin.y ;

else

if( code & TOP_EDGE)

if ( p2.x ! = p1.x)

{
p1.x + = ( winmax.y – p1.y) / m ;

p1.y = winmax.y ;

if ( draw)

lineDDA ( ROUND ( p1.x), ROUND ( p1.y), ROUND ( p2.x), ROUND ( p2.y)) ;

OUTPUT
EXPERIMENT No. 14

AIM: Write a program to implement Bezier Curve.

PROGRAM

#include < stdio.h >


# include < conio.h >
# include < graphicd.h >

void main ( )

double numsteps , i , t ;

float stepsize ;

int x0 , y0 , x1 , y1 , x2 , y2 , x3 , y3 , x , y ;

int ax , ay , bx , by , cx , cy , dx , dy ;

int gd = DETECT , gm ;

initgraph ( &gd ,&gm , “ \\tc\\bgi ” ) ;

printf ( “ \n Enter The Value of x0 & y0 ” ) ;

scanf ( “ %d %d ” , &x0 , &y0 ) ;

printf ( “ \n Enter The Value of x1 & y1 ” ) ;

scanf ( “ %d %d ” , &x1 , &y1 ) ;

printf ( “ \n Enter The Value of x2 & y2 ” ) ;

scanf ( “ %d %d ” , &x2 , &y2 ) ;

printf ( “ \n Enter The Value of x3 & y3 ” ) ;

scanf ( “ %d %d ” , &x3 , &y3 ) ;

ax = - x0 + 3 * x1 + ( - 3 * x2 ) + x3 ;

ay = - y0 + 3 * y1 + ( - 3 * y2 ) + y3 ;
bx = 3 * x0 + ( -6 * x1 ) + 3 * x2 ;

by = 3 * y0 + ( -6 * y1 ) + 3 * y2 ;

cx = 3 * x0 + 3 * x1 ;

cy = 3 * y0 + 3 * y1 ;

dx = x0 ;

dy = y0 ;

setcolor ( MAGENDA ) ;

numstep = 100 ;

stepsize = 1.0 / ( double ) numsteps ;

moveto ( dx , dy ) ;

for ( i = 1 ; i < numsteps ; i ++)

t = stepsize * ( double ) i ;

x = ax * ( t * t * t ) + by * ( t * t ) + cy * t + dy ;

lineto ( x , y ) ;

getch ( ) ;

closegraph () ;

OUTPUT
EXPERIMENT No. 15

AIM : Write a program to implement B-Spline Curve.

PROGRAM

#include < stdio.h >


#include < conio.h >
#include < graphics.h >

void SplinePoint(int *u,int n,int t,double v,XYZ *control,XYZ *output)

{
int k;

double b;

output->x = 0;

output->y = 0;

output->z = 0;

for (k=0; k<=n; k++)

b = SplineBlend(k,t,u,v);

output->x + = control[k].x * b;

output->y + = control[k].y * b;

output->z + = control[k].z * b;

}
double SplineBlend(int k,int t,int *u,double v)

{
double value;

if (t == 1)

if ((u[k] <= v) && (v < u[k+1]))

value = 1;

else

value = 0;

else

if ((u[k+t-1] == u[k]) && (u[k+t] == u[k+1]))

value = 0;

else if (u[k+t-1] == u[k])

value = (u[k + t] - v) / (u[k+t] - u[k+1]) * SplineBlend(k+1,t-1,u,v);

else if (u[k+t] == u[k+1])

value = (v - u[k]) / (u[k+t-1] - u[k]) * SplineBlend(k,t-1,u,v);

else

value = (v - u[k]) / (u[k+t-1] - u[k]) * SplineBlend(k,t-1,u,v) +

(u[k+t] - v) / (u[k+t] - u[k+1]) * SplineBlend(k+1,t-1,u,v);

}
return(value);

}
void SplineKnots(int *u,int n,int t)

{
int j;

for (j=0;j<=n+t;j++) {

if (j < t)

u[j] = 0;

else if (j <= n)

u[j] = j - t + 1;

else if (j > n)

u[j] = n - t + 2;
}
}

OUTPUT
EXPERIMENT No. 16

AIM :Write a program to implement Animation using C function.

PROGRAM

#include < stdio.h >


# include < conio.h >
# include < graphicd.h >

void main ( )

int x , y , a , b , i ;

int gd = DETECT , gm ;

initgraph ( &gd ,&gm , “ \\tc\\bgi ” ) ;

for ( i = 0 ; i < 320 ; i ++ )

rectangle ( 325 , 440 , 330 , 50 ) ;

rectangle ( 325 , 440 , 440 , 455 ) ;

rectangle ( 325 , 440 - i , 450 , 370 - i ) ;

circle ( 387 , 410 – i , 10 ) ;

line ( 325 , 399 – i , 450 , 399 – i ) ;

line ( 325 , 420 – i , 450 , 420 – i ) ;

delay ( 15 ) ;

clear device ( ) ;

}
rectangle ( 325 , 410 , 330 , 50 ) ;

rectangle ( 325 , 440 , 440 , 455 ) ;

rectangle ( 325 , 120 , 450 , 50 ) ;

circle ( 387 , 90 , 10 ) ;

line ( 325 , 79 , 450 , 79 ) ;

line ( 325 , 100 , 450 , 100 ) ;

outtextxy ( x , y , “ * ” ) ;

getch ( ) ;

closegraph ( ) ;
}
}

OUTPUT
EXPERIMENT No. 17

AIM :Write a program to implement a cartoon using C function.

PROGRAM

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

void main()

int gd = DETECT , gm, i, a ;

clrscr( ) ;

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

for (i = (- 80 ) ; i< = 300 ; i + = 5 )

circle ( 200 + i, 200,100 ) ;

setfillstyle(SOLID_FILL,i) ;

floodfill ( 200 + i, 200, WHITE ) ;

circle ( 160 + i, 160, 10 ) ;

setfillstyle ( SOLID_FILL, i + 1 ) ;

floodfill (160 + i, 160, WHITE ) ;

circle ( 240 + i, 160, 10 ) ;

setfillstyle ( SOLID_FILL, i + 1 ) ;
floodfill ( 240 + i, 160, WHITE ) ;

arc (200 + i, 200, 200, 340, 60 ) ;

delay ( 200 ) ;

clrscr( ) ;
}

getch( ) ;

OUTPUT
EXPERIMENT No. 18

AIM :Write a program to draw a chain of Circle.

PROGRAM

# include<graphics.h>
# include<conio.h>
# include<stdio.h>
#include<math.h>
void main()
{

int gd = DETECT, gm , i ;

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

for(i=50;i<200;i=i+30)
{
circle(i,i+30,50);
getch();
restorcrtmode();
}

OUTPUT
EXPERIMENT No. 19

AIM :Write a program to display concentric circles.

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&d,&m,"c:\\tc\\bgi");
setcolor(4);
for(i=50;i<150;i+=50)
{
circle(150,150,i);
getch();
/*draw concentric circle of radius i pixels and center at 50,50,I in color 3*/
restorcrtmode();
}

OUTPUT
EXPERIMENT No. 20

AIM :Write a program to fill an ellipse by reduce the size of ellipse.

PROGRAM

#include<graphics.h>
include<stdio.h>
#include<conio.h>
#include<math.h>
elli_R(xc,yc,rx,ry)
float xc,yc,rx,ry;
{
while(rx>0.0 && ry>0.0)
{
ellipse(xc,yc,0,360,rx,ry);
--rx;
++ry;
getch();
}
return;
}

void main()
{
float xc,yc,rx,ry;
int gd=DETECT,gm,i;
initgraph(&gd,&gm,”c:\\tc\\bgi”);
setpalette(0,23);
for(i=0;i<=7;++i)
{
setcolor(1);
getch();
ellipse(250,250,0,360,140,80);
getch();
elli_R(250.0,250.0,140.0,80.0);
}
restorecrtmode();
return;
}

OUTPUT

También podría gustarte