here are both routines incorporated in to a single user friendly file:
'**********************************************************************************
'*
'* This draws an unfilled ellipse one pixel at a time And uses only integer math
'* To do it, except For one small part where two lines need To do a floating point
'* calculation. Even so, there is no trigonometry involved. The ellipse is Not
'* rotatable unless the output Method (ie Plot) can be drawn with rotated coordinates
'* as part of the Graphics system (ie rotating the camera, etc).
'*
'* xCenter = oval center X
'* yCenter = oval center Y
'* draw(integer width in pixels,integer height in pixels)
'*
'**********************************************************************************
Type Tobject
Field xCenter:Int
Field yCenter:Int
Global c$[]=["OVAL","CIRCLE"]
Method Draw(radiusX:Int,radiusY:Int=Null) Abstract
End Type
Type Toval Extends Tobject
Method Draw(radiusX:Int,radiusY:Int=Null)
Local Rx:Int,Ry:Int
Local p:Int,px:Int,py:Int,x:Int,y:Int
Local Rx2:Int,Ry2:Int,twoRx2:Int,twoRy2:Int
Local pFloat:Float
Rx=Abs(radiusX)
Ry=Abs(radiusY)
Rx2=Rx*Rx
Ry2=Ry*Ry
twoRx2=Rx2 Shl 1
twoRy2=Ry2 Shl 1
'Region 1
x=0
y=Ry
Plot xCenter+x,yCenter+y
Plot xCenter-x,yCenter+y
Plot xCenter+x,yCenter-y
Plot xCenter-x,yCenter-y
pFloat=(Ry2-(Rx2*Ry))+(0.25*Rx2)
p=Int(pFloat)
If pFloat Mod 1.0>=0.5 Then p:+1
px=0
py=twoRx2*y
While px<py
x:+1
px:+twoRy2
If p>=0
y:-1
py:-twoRx2
EndIf
If p<0 Then p:+Ry2+px Else p:+Ry2+px-py
Plot xCenter+x,yCenter+y
Plot xCenter-x,yCenter+y
Plot xCenter+x,yCenter-y
Plot xCenter-x,yCenter-y
Wend
'Region 2
pFloat=(Ry2*(x+0.5)*(x+0.5))+(Rx2*(y-1.0)*(y-1.0))-(Rx2*(Float(Ry2)))
p=Int(pFloat)
If pFloat Mod 1.0>=0.5 Then p:+1
While y>0
y:-1
py:-twoRx2
If p<=0
x:+1
px:+twoRy2
EndIf
If p>0 Then p:+Rx2-py Else p:+Rx2-py+px
Plot xCenter+x,yCenter+y
Plot xCenter-x,yCenter+y
Plot xCenter+x,yCenter-y
Plot xCenter-x,yCenter-y
Wend
End Method
End Type
'
' program : circle drawing lib using Bresenham algrorith
' using the circle draw int algorithm at:
' <a href="http://www.gamedev.net/reference/articles/article767.asp" target="_blank">www.gamedev.net/reference/articles/article767.asp</a>
' created by Jesse Perez 8/20/2006
'
' draws a circle with:
'
' xCenter = center x
' yCenter = center y
' circle(RadiusX,radiusY=Null) 'radiusx,radiusy = circle radius in pixels radius Y is optional
' but will calculate radius from the x axis only.
'
' note: no clipping is done so may become extremely slow if excessibly large circles are drawn.
' also: also if the screen resolution is not proportionally correct it will not look round.
Type Tcircle Extends Tobject
Method draw(radiusX:Int,radiusY:Int=Null)
Local radius=Sqr(radiusX*radiusX+radiusY*radiusY)
If (xCenter-radius) > GraphicsWidth() Return
If (yCenter-radius) > GraphicsHeight() Return
If (xCenter+radius) < 0 Then Return
If (yCenter+radius) < 0 Then Return
Local x = 0
Local d = (2*Radius)
Local y=Radius
While x<y
If d < 0 Then
d = d + (4 * x) + 6
Else
d = d + 4 * (x - y) + 10
y = y - 1
End If
Plot(xCenter + X, yCenter + Y)
Plot(xCenter + X, yCenter - Y)
Plot(xCenter - X, yCenter + Y)
Plot(xCenter - X, yCenter - Y)
Plot(xCenter + Y, yCenter + X)
Plot(xCenter + Y, yCenter - X)
Plot(xCenter - Y, yCenter + X)
Plot(xCenter - Y, yCenter - X)
x=x+1
Wend
End Method
End Type
Graphics 800,600
Local shape:Tobject[2]
Local index
shape[0]=New Toval
shape[1]=New tcircle
For index = 0 To 1
shape[index].xCenter = GraphicsWidth()/2
shape[index].yCenter = GraphicsHeight()/2
Next
index=0
Repeat
If MouseHit(2)Then
index = 1 - index
shape[index].xCenter=GraphicsWidth()/2
shape[index].yCenter=GraphicsHeight()/2
EndIf
DrawText "Press the Right mouse Button",10,10
DrawText "to switch from drawing "+shape[index].c$[index]+"S",10,25
DrawText "to drawing "+shape[index].c$[1-index]+"S",10,40
If MouseDown(1)
shape[index].xCenter=MouseX()
shape[index].YCenter=MouseY()
EndIf
shape[index].draw(shape[index].xCenter-MouseX(),shape[index].yCenter-MouseY())
Flip(1)
Cls
Until KeyHit(KEY_ESCAPE )