05-08-2022, 06:18 PM
Here is the integer circle drawing routine including a small demo -
Doros.BAS
TR
Doros.BAS
Code: (Select All)
Screen 12 'square pixels
_FullScreen _SquarePixels
CC% = 1
For Radius% = 50 To 190 Step 10
DrawCircle 320, 240, Radius%, CC%
CC% = CC% + 1
_Delay 0.125
Next Radius%
End
Sub DrawCircle (XCenter%, YCenter%, Radius%, Colour%)
S% = Radius%
X% = S%
Y% = 0
For Octant% = 1 To 8
If (Octant% And 1) = 0 Then
S% = S% + X% * 2
Do While Y% >= 0
S% = S% - Y% * 2 + 1
Y% = Y% - 1
If S% < 0 Then
S% = S% + X% * 2 + 2
X% = X% + 1
End If
If X% <> Y% Then
Select Case Octant%
Case 1
ActualX% = XCenter% + X%
ActualY% = YCenter% + Y%
Case 2
ActualX% = XCenter% + Y%
ActualY% = YCenter% + X%
Case 3
ActualX% = XCenter% - Y%
ActualY% = YCenter% + X%
Case 4
ActualX% = XCenter% - X%
ActualY% = YCenter% + Y%
Case 5
ActualX% = XCenter% - X%
ActualY% = YCenter% - Y%
Case 6
ActualX% = XCenter% - Y%
ActualY% = YCenter% - X%
Case 7
ActualX% = XCenter% + Y%
ActualY% = YCenter% - X%
Case 8
ActualX% = XCenter% + X%
ActualY% = YCenter% - Y%
End Select
PSet (ActualX%, ActualY%), Colour%
End If
Loop
Else
S% = S% - X% * 2
Do While Y% <= X%
Select Case Octant%
Case 1
ActualX% = XCenter% + X%
ActualY% = YCenter% + Y%
Case 2
ActualX% = XCenter% + Y%
ActualY% = YCenter% + X%
Case 3
ActualX% = XCenter% - Y%
ActualY% = YCenter% + X%
Case 4
ActualX% = XCenter% - X%
ActualY% = YCenter% + Y%
Case 5
ActualX% = XCenter% - X%
ActualY% = YCenter% - Y%
Case 6
ActualX% = XCenter% - Y%
ActualY% = YCenter% - X%
Case 7
ActualX% = XCenter% + Y%
ActualY% = YCenter% - X%
Case 8
ActualX% = XCenter% + X%
ActualY% = YCenter% - Y%
End Select
PSet (ActualX%, ActualY%), Colour%
S% = S% + Y% * 2 + 1
Y% = Y% + 1
If S% >= 0 Then
S% = S% - X% * 2 + 2
X% = X% - 1
End If
Loop
End If
Next Octant%
End Sub
TR