Bitmap/Midpoint circle algorithm: Difference between revisions

m
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations, simplified some code.)
m (→‎{{header|FreeBASIC}}: minor change)
Line 844:
end subroutine draw_circle_sc</lang>
=={{header|FreeBASIC}}==
<lang FreeBASIC>' version 0615-0710-20152016
' compile with: fbc -s consolegui
' OR compile with: fbc -s gui
 
' Variant with Integer-Based Arithmetic from Wikipedia page: Midpoint circle algorithm
' Midpoint circle algorithm
Sub circle_(x0 As Integer, y0 As Integer , radius As Integer, Col As Integer)
 
Dim As Integer x = radius
Dim As Integer y
Dim As Integer decisionOver2 = 1 - x ' Decision criterion divided by 2 evaluated at x=r, y=0
Dim As IfInteger decisionOver2 <= 01 - Thenx
 
While(x >= y)
PSet(x0 + x, y0 + y), col
PSet(x0 - x, y0 + y), col
PSet(x0 + x, y0 - y), col
PSet(x0 - x, y0 - y), col
PSet(x0 + y, y0 + x), col
PSet(x0 - y, y0 + x), col
PSet(x0 + y, y0 - x), col
PSet(x0 - y, y0 - x), col
y = y + 1
If decisionOver2 <= 0 Then
decisionOver2 += y * 2 + 1 ' Change in decision criterion for y -> y +1
Else
x = x - 1
decisionOver2 += (y - x) * 2 + 1 ' Change for y -> y +1, x -> x -1
End If
Wend
 
While(x >= y)
PSet(x0 + x, y0 + y), col
PSet(x0 - x, y0 + y), col
PSet(x0 + x, y0 - y), col
PSet(x0 - x, y0 - y), col
PSet(x0 + y, y0 + x), col
PSet(x0 - y, y0 + x), col
PSet(x0 + y, y0 - x), col
PSet(x0 - y, y0 - x), col
y = y + 1
If decisionOver2 <= 0 Then
decisionOver2 += y * 2 + 1 ' Change in decision criterion for y -> y+1
Else
x = x - 1
decisionOver2 += (y - x) * 2 + 1 ' Change for y -> y+1, x -> x-1
End If
Wend
End Sub
 
' ------=< MAIN >=------
 
ScreenRes 800600, 800600, 32
Dim As Integer w, h, depth
Randomize Timer
Line 882 ⟶ 884:
ScreenInfo w, h
 
For i As Integer = 01 To 5010
circle_(Rnd * w, Rnd * h , Rnd * i * 4200 , Int(Rnd * &hFFFFFF))
Next
 
 
'save screen to BMP file
BsaveBSave "Name.BMP", 0
 
 
' empty keyboard buffer
While InKeyInkey <> "" : Wend
Print : PrintWindowTitle "hit any key to end program"
Sleep
End</lang>
457

edits