Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AakashCode12/f36d54da9ce1f56bc31b541f83890c74 to your computer and use it in GitHub Desktop.
Save AakashCode12/f36d54da9ce1f56bc31b541f83890c74 to your computer and use it in GitHub Desktop.
Practical-3 || Computer Graphics
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>
#include<ctype.h>
void circleplot(int r,int cx,int cy){
int x=0;
int y=r;
int p=1-r;
putpixel(cx,cy,WHITE);
putpixel(x,y,WHITE);
while(x<y){
x=x+1;
if(p<0){
p=p+2*x+1;
}
else{
y=y-1;
p=p+2*x+10-2*y;
}
putpixel(x+cx,y+cy,WHITE);
putpixel(-x+cx,y+cy,RED);
putpixel(-x+cx,-y+cy,BLUE);
putpixel(x+cx,-y+cy,GREEN);
putpixel(y+cx,x+cy,CYAN);
putpixel(-y+cx,x+cy,WHITE);
putpixel(-y+cx,-x+cy,MAGENTA);
putpixel(y+cx,-x+cy,YELLOW);
}
}
//todo main function
void main(){
clrscr();
int gd=DETECT,gm;
int r,cx,cy;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
cleardevice();
cout<<"\n--------------Midpoint Circle Drawing Algorithm--------------";
cout<<"\nEnter the radius of the circle\n";
cin>>r;
cout<<"\nEnter the coordinates of the centre of the circle\n";
cin>>cx>>cy;
circleplot(r,cx,cy);
getch();
closegraph();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment