It would be nice to add ellipse capability. (Draw & Fill)
It would be better to fold/merge this in with the circle and rounded
rectangle code rather than a single separate routine.
Code for it is below. It does work:
void Plot4EllipsePoints(long CX,long CY, long X, long Y, uint8_t 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}
#ifdef TOFILL
// to fill rather than draw a line, plot between the points
GLCD.DrawLine(CX+X, CY+Y, CX-X, CY+Y, color);
GLCD.DrawLine(CX-X, CY-Y, CX+X, CY-Y, color);
#endif
}
void glcd::DrawEllipse(long CX, long CY, long XRadius,long YRadius, uint8_t
color) {
// 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}
Original issue reported on code.google.com by bperry...@gmail.com on 24 Mar 2011 at 7:02
Original issue reported on code.google.com by
bperry...@gmail.com
on 24 Mar 2011 at 7:02