![]() | Circle Drawing |
This method is really easy to use, you probably remember it from geometry in High School. Here's the code!
void se::SlowCircle(long xcenter,long ycenter, long radius)
{ long x,y;
for(float theta=0;theta < (2*M_PI);theta+=.01)
{ x=xcenter+(long)(radius*sin(theta));
y=ycenter+(long)(radius*cos(theta));
video->quickpixel(x,y,15);
}
} |

void se::SlowCircle(long xcenter,long ycenter, long radius)
{ long x,y,r2=radius*radius;
for(long x=-radius;x<=radius;x++)
{ y=(short)sqrt(r2-(x*x));
video->quickpixel(xcenter+x,ycenter+y,15);
video->quickpixel(xcenter+x,ycenter-y,15);
}
}
|
void se::SlowCircle(long xcenter,long ycenter, long radius)
{ long x,y,r2=radius*radius;
for(long x=0;x<=radius;x++)
{ y=(short)sqrt(r2-(x*x));
video->quickpixel(xcenter+x,ycenter+y,15);
video->quickpixel(xcenter+x,ycenter-y,15);
video->quickpixel(xcenter-x,ycenter+y,15);
video->quickpixel(xcenter-x,ycenter-y,15);
}
} |
void se::SlowCircle(long xcenter,long ycenter, long radius)
{ long x,y,r2=radius*radius;
for(long x=0;x<=radius;x++)
{ y=(short)sqrt(r2-(x*x));
video->quickpixel(xcenter+x,ycenter+y,15);
video->quickpixel(xcenter+x,ycenter-y,15);
video->quickpixel(xcenter-x,ycenter+y,15);
video->quickpixel(xcenter-x,ycenter-y,15);
video->quickpixel(xcenter+y,ycenter+x,15);
video->quickpixel(xcenter+y,ycenter-x,15);
video->quickpixel(xcenter-y,ycenter+x,15);
video->quickpixel(xcenter-y,ycenter-x,15);
}
} |
(+x,+y)(+x,-y)(-x,+y)(-x,-y)(+y,+x)(+y,-x)(-y,+x)(-y,-x)Suddenly, the circle is complete!! By using the symmetry inherent in the circle we have made a routine that will always create a complete circle no matter what the radius is! The only big problem is that it uses the sqrt function which is really a cycle sucker! Luckily we DO have other methods at our disposal!
void Circle(long xcenter,long ycenter,long radius)
{ long x=0;
long y=radius;
long p=(5-radius*4)/4;
CirclePoint(xcenter,ycenter,x,y,4);
while(x<y)
{ x++;
if(p<0)
{p+=2*x+1;
}
else{y--;p+=2*(x-y)+1;}
CirclePoint(xcenter,ycenter,x,y,x);
}
}
void CirclePoint(long cx,long cy,long x,long y,char c)
{ if(x==0)
{ video->quickpixel(cx,cy+y,c);
video->quickpixel(cx,cy-y,c);
video->quickpixel(cx+y,cy,c);
video->quickpixel(cx-y,cy,c);
}
else if(x==y)
{video->quickpixel(cx+x,cy+y,c);
video->quickpixel(cx-x,cy+y,c);
video->quickpixel(cx+x,cy-y,c);
video->quickpixel(cx-x,cy-y,c);
}
else if(x<y)
{video->quickpixel(cx+x,cy+y,c);
video->quickpixel(cx-x,cy+y,c);
video->quickpixel(cx+x,cy-y,c);
video->quickpixel(cx-x,cy-y,c);
video->quickpixel(cx+y,cy+x,c);
video->quickpixel(cx-y,cy+x,c);
video->quickpixel(cx+y,cy-x,c);
video->quickpixel(cx-y,cy-x,c);
}
} |
