Open RedCali opened 2 months ago
// portted the algorithm found at // http://homepage.smc.edu/kennedy_john/belipse.pdf // by John Kennedy long X, Y; long XChange, YChange; long EllipseError; long TwoASquare,TwoBSquare; long StoppingX, StoppingY; TwoASquare = 2*XRadius*XRadius; TwoBSquare = 2*YRadius*YRadius; X = XRadius; Y = 0; XChange = YRadius*YRadius*(1-2*XRadius); YChange = XRadius*XRadius; EllipseError = 0; StoppingX = TwoBSquare*XRadius; StoppingY = 0; while ( StoppingX >=StoppingY ) //first set of points,y'>-1 { Plot4EllipsePoints(CX,CY,X,Y,color); Y++; StoppingY=StoppingY+ TwoASquare; EllipseError = EllipseError+ YChange; YChange=YChange+TwoASquare; if ((2*EllipseError + XChange) > 0 ) { X--; StoppingX=StoppingX- TwoBSquare; EllipseError=EllipseError+ XChange; XChange=XChange+TwoBSquare; } } //{ first point set is done; start the 2nd set of points } Y = YRadius; X = 0; YChange = XRadius*XRadius*(1-2*YRadius); XChange = YRadius*YRadius; EllipseError = 0; StoppingY = TwoASquare*YRadius; StoppingX = 0; while ( StoppingY >=StoppingX ) //{2nd set of points, y'< -1} { Plot4EllipsePoints(CX,CY,X,Y,color); X++; StoppingX=StoppingX + TwoBSquare; EllipseError=EllipseError+ XChange; XChange=XChange+TwoBSquare; if ((2*EllipseError + YChange) > 0 ) { Y--; StoppingY=StoppingY- TwoASquare; EllipseError=EllipseError+ YChange; YChange=YChange+TwoASquare; } } }; //{procedure PlotEllipse} void Plot4EllipsePoints(long CX,long CY, long X, long Y, int color){ GLCD.SetDot(CX+X, CY+Y, color); //{point in quadrant 1} GLCD.SetDot(CX-X, CY+Y, color); //{point in quadrant 2} GLCD.SetDot(CX-X, CY-Y, color); //{point in quadrant 3} GLCD.SetDot(CX+X, CY-Y, color); //{point in quadrant 4} }
https://github.com/thegeek82000/openGLCD/blob/master/glcd.cpp