0% found this document useful (0 votes)
51 views4 pages

St. Xavier'S College: Maitighar, Kathmandu

The document is a lab assignment submitted by Sheetal Giri to the Department of Computer Science at St. Xavier's College in Kathmandu. It includes the objective to plot a circle given a center point and radius, the algorithm to do so by calculating x and y coordinates using trigonometric functions, and the C source code implementing the algorithm by drawing pixels to form the circle.

Uploaded by

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

St. Xavier'S College: Maitighar, Kathmandu

The document is a lab assignment submitted by Sheetal Giri to the Department of Computer Science at St. Xavier's College in Kathmandu. It includes the objective to plot a circle given a center point and radius, the algorithm to do so by calculating x and y coordinates using trigonometric functions, and the C source code implementing the algorithm by drawing pixels to form the circle.

Uploaded by

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

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

You might also like