Hmm... I can't figure out the best way to cater for the second run-through of the arc-drawing function. I need to swap x and y for the arc calculations, but I need to keep them the same for the draw_pixel calls. I can't figure out a simple way to do this without ugly hacks. Code below uses drawArc to draw the first arc, but the second is still drawn the old way. Is there a better way to make drawArc work for both arcs than adding a boolean parameter to the function and having two sets of draw_pixel calls, one with x and y swapped?
Sub draw_ellipse (ByVal xc As integer, ByVal yc As Integer, ByVal a As integer, ByVal b As Integer)
Dim As Integer x, y, sigma, xd
Dim As Integer a2 = a*a, b2 = b*b, fa2 = 4*a2, fb2 = 4*b2
Dim As Integer cr,cg,cb
cr=255:cg=0:cb=0
x=0
y=b
drawArc (x, y, a, b, xc, yc, cr, cg, cb) ***** First call to drawArc, second call needs to be 'drawArc (y, x, b, a, xc, yc, cr, cg, cb)
***** but part of drawArc needs x & y not to be flipped (draw_pixel calls)
cr=0:cg=255:cb=0
x=a
y=0
sigma = 2*a2+b2*(1-2*a)
While ((a2*y <= b2*x) and a>0)
draw_pixel(xc+x, yc+y, cr, cg, cb) : Rem I. Quadrant
draw_pixel(xc-x, yc+y, cr, cg, cb) : Rem II. Quadrant
draw_pixel(xc+x, yc-y, cr, cg, cb) : Rem III. Quadrant
draw_pixel(xc-x, yc-y, cr, cg, cb) : Rem IV. Quadrant
If (sigma>= 0) Then
sigma += fb2*(1-x)
x=x-1
EndIf
sigma = sigma + a2*(4*y+6)
y=y+1
Wend
Rem Finish line if X hasn't landed on 0
If x<=1 Then
x=0
For y=y to b
draw_pixel(xc+x, yc+y, cr, cg, cb) : Rem I. Quadrant
draw_pixel(xc-x, yc+y, cr, cg, cb) : Rem II. Quadrant
draw_pixel(xc+x, yc-y, cr, cg, cb) : Rem III. Quadrant
draw_pixel(xc-x, yc-y, cr, cg, cb) : Rem IV. Quadrant
Next y
EndIf
End Sub
Sub drawArc (ByVal x As Integer, ByVal y As Integer, ByVal a As Integer, ByVal b As Integer, ByVal xc As Integer, ByVal yc As Integer, ByVal cr As Integer, ByVal cg As Integer, ByVal cb As Integer)
Dim As Integer sigma
Dim As Integer a2 = a*a, b2 = b*b, fa2 = 4*a2, fb2 = 4*b2
sigma = 2*b2+a2*(1-2*b)
While ((b2*x <= a2*y) and b>0)
draw_pixel(xc+x, yc+y, cr, cg, cb) : Rem I. Quadrant
draw_pixel(xc-x, yc+y, cr, cg, cb) : Rem II. Quadrant
draw_pixel(xc+x, yc-y, cr, cg, cb) : Rem III. Quadrant
draw_pixel(xc-x, yc-y, cr, cg, cb) : Rem IV. Quadrant
If (sigma>= 0) Then
sigma += fa2*(1-y)
y=y-1
EndIf
sigma = sigma + b2*(4*x+6)
x=x+1
Wend
REM Finish line if y hasn't landed on 0
If y<=1 Then
y=0
For x=x to a
draw_pixel(xc+x, yc+y, cr, cg, cb) : Rem I. Quadrant
draw_pixel(xc-x, yc+y, cr, cg, cb) : Rem II. Quadrant
draw_pixel(xc+x, yc-y, cr, cg, cb) : Rem III. Quadrant
draw_pixel(xc-x, yc-y, cr, cg, cb) : Rem IV. Quadrant
Next x
EndIf
End Sub