08-26-2022, 05:34 PM
rcircle is now the leader of the pack:
Code: (Select All)
'Draw_that_circle
'
'By James D. Jarvis
'
'an alternate subroutine to draw a filled circle.
'the basic sub is rcircle, rcircle find X while stepping through Y for -radius to the radius
'dcircle, references the precalculated table in the array nsqr() to otherwise drae as rcircle
'dmcircle, references the precalculated table in the array nsqr() as dcircle but makes uses of _mem for access.
Screen _NewImage(800, 500, 256)
Randomize Timer
Dim Shared nsqr(-32000 To 32000) As Long 'table holds the square values
Dim Shared nsq As _MEM 'let's access the memblock of the table
For n = -32000 To 32000 'precaluclaitng the square values of -32000 to 32000
nsqr(n) = Abs(n) ^ 2
Next
nsq = _Mem(nsqr())
Input "press enter to start"; any$
'draw without look up table
t1 = Timer
For n = 1 To 64000
' r = Int(1 + Rnd * 60) 'comment this out in each l0op to see the difference with a fixed radius
r = 30 'chanign the size certainyl crerates a speed difference
rcircle Int(Rnd * 800), Int(Rnd * 500), r, Int(Rnd * 256)
Next n
t2 = Timer
Print "that was"; t2 - t1; " seconds for 64,000 circles"
'draw with look up table
Input "Press enter to continue"; A$
t3 = Timer
For n = 1 To 64000
'r = Int(1 + Rnd * 60)
r = 30
dmcircle Int(Rnd * 800), Int(Rnd * 500), r, Int(Rnd * 256)
Next n
t4 = Timer
Print "that was"; t4 - t3; " seconds for 64,000 circles"
Input "press enter to continue"; ask$
'draw with look up table and using mem offset
t5 = Timer
For n = 1 To 64000
'r = Int(1 + Rnd * 60)
r = 30
dmcircle Int(Rnd * 800), Int(Rnd * 500), r, Int(Rnd * 256)
Next n
t6 = Timer
Print "that was"; t6 - t5; " seconds for 64,000 circles"
Print
Print "Analysis"
Print "rcircle took "; t2 - t1; " seconds"
Print "dcircle took "; t4 - t3; " seconds"
Print "dmcircle took "; t6 - t5; " seconds"
_MemFree nsq
Sub dcircle (cx, cy, r, klr)
'simple routine to draw a circle using a look up table to speed up calculations
y = -r
Do
x = Sqr(nsqr(r) - nsqr(y))
Line (cx - x, cy + y)-(cx + x, cy + y), klr
y = y + 1
Loop Until y > r
End Sub
Sub dmcircle (cx, cy, r, klr)
'simple routine to draw a circle using a look up table to speed up calculations
y = -r
Do
x = Sqr(_MemGet(nsq, nsq.OFFSET + (r + 32000) * 4, Long) - _MemGet(nsq, nsq.OFFSET + (y + 32000) * 4, Long))
Line (cx - x, cy + y)-(cx + x, cy + y), klr
y = y + 1
Loop Until y > r
End Sub
Sub wcircle (cx, cy, r, klr)
'was testing if there was a notable difference between using a do loop or a while loop, left it here if anyone else wanted to try it
y = -r
While y <= r
x = Sqr(nsqr(r) - nsqr(y))
Line (cx - x, cy + y)-(cx + x, cy + y), klr
y = y + 1
Wend
End Sub
Sub rcircle (cx As Long, cy As Long, r As Long, klr As _Unsigned Long)
rsqrd = r * r
For y = 0 To r
x = Sqr(rsqrd - y * y)
Line (cx - x, cy + y)-(cx + x, cy + y), klr
Line (cx - x, cy - y)-(cx + x, cy - y), klr
' Print x
Next
End Sub
b = b + ...