ST.
XAVIERS COLLEGE
MAITIGHAR, KATHMANDU
Computer Graphics
Lab Assignment #4
Submitted by:
Sheetal Giri
012BSCIT041
Submitted to:
Department of Computer Science
Mr. Ganesh Yogi
Er. Sanjay Kr. Yadav
Sheetal Giri
Objective: Plot a sample circle for given centre and radius.
Algorithm
1. Get the input centre (xc, yc) and radius of the circle.
2. Set i =0
3. x=xc+ rcos(i) , y=yc + rsin(i) , plot(x,y)
4. i = i+1
5. if (i<=360) , go to step 3 ,otherwise go to step 6
6. Stop
Source Code
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
#define SQUARE(x) ((x)*(x))
void drawcircle(int ,int,int);
void main()
{
int gd,gm,err;
int xc,yc,r;
gd=DETECT;
initgraph(&gd,&gm,"\\tc\\bgi");
err=graphresult();
if(err!=0)
{
012BSCIT041
Sheetal Giri
printf("ERROR:%s",grapherrormsg(err));
printf("\nPress a key..");
getch();
exit(1);
}
printf("Enter centre x,y:");
scanf("%d,%d",&xc,&yc);
printf("Enter Radius r:");
scanf("%d",&r);
drawcircle(xc,yc,r);
getch();
closegraph();
}//end main
void drawcircle(int xc,int yc,int r)
{
int i,x,y,y1;
for(i=0;i<=360;i++)
{
x= xc+(r*cos(i));
y= yc+(r*sin(i));
putpixel(x,y,WHITE);
putpixel(x,y1,WHITE);
}
}
Output
012BSCIT041
Sheetal Giri
012BSCIT041