Last active
August 16, 2020 16:35
-
-
Save AakashCode12/76f7ff9819134a2d2794fb299bb13aa1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CG | |
#include<iostream.h> | |
#include<conio.h> | |
#include<math.h> | |
#include<stdlib.h> | |
#include<dos.h> | |
#include<graphics.h> | |
#include<ctype.h> | |
//function prototyping | |
void ellipseplotter(float rx,float ry,float cx,float cy); | |
//ellipse plotting function | |
void ellipseplotter(float rx,float ry,float cx, float cy){ | |
// Region 1 start here | |
float x=0.0; | |
float y=ry; | |
float p1=(ry*ry)-(rx*rx*ry)+((rx*rx)*0.25);// initialized the p1 | |
putpixel(cx,cy,WHITE); | |
while((2*ry*ry*x)<(2*rx*rx*y)){ | |
x++; | |
if(p1<0){ | |
p1=p1+(2*ry*ry*x)+(ry*ry); | |
} | |
else{ | |
y--; | |
p1=p1+(2*ry*ry*x)-(2*rx*rx*y)+(ry*ry); | |
} | |
putpixel(x+cx,y+cy,WHITE); | |
putpixel(-x+cx,y+cy,RED); | |
putpixel(-x+cx,-y+cy,BLUE); | |
putpixel(x+cx,-y+cy,GREEN); | |
} | |
// Region 2 start here | |
float p2=(ry*ry)*((x+(0.5))*(x+(0.5)))+(rx*rx*(y-1)*(y-1))-(rx*rx*ry*ry);// initialized the p2 | |
while(y>0){ | |
if(p2>0){ | |
//x=x; | |
y--; | |
p2=p2-(2*rx*rx*y)+(rx*rx); | |
} | |
else{ | |
x++; | |
y--; | |
p2=p2+(2*ry*ry*x)-(2*rx*rx*y)+(rx*rx); | |
} | |
putpixel(x+cx,y+cy,WHITE); | |
putpixel(-x+cx,y+cy,RED); | |
putpixel(-x+cx,-y+cy,BLUE); | |
putpixel(x+cx,-y+cy,GREEN); | |
} | |
} | |
//todo main function | |
void main(){ | |
clrscr(); | |
int gd=DETECT,gm; | |
float rx,ry,cx,cy; | |
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); | |
cleardevice(); | |
cout<<"\n--------------Ellipse Drawing Algorithm--------------"; | |
cout<<"\nEnter the coordinates of the centre of the Ellipse\n"; | |
cin>>cx>>cy; | |
cout<<"\nEnter the Length of the Rx of the circle\n"; | |
cin>>rx; | |
cout<<"\nEnter the Length of the Ry of the circle\n"; | |
cin>>ry; | |
ellipseplotter(rx,ry,cx,cy); | |
getch(); | |
closegraph(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment