Andy Amaya has brought to my attention Bresenham which saves time by avoiding SQR so here are 3 circle algo's and results in SmallBASIC.
'3 fill circle tests.bas for SmallBASIC 0.12.9 (B+=MGA) 2017-05-27 post
' MIT license info below for fCirc2 algo
' Andy Amaya has brought to my attention the Bresenham Circle Fill ago
' from Andy Amaya at The QB64 Edition post is in Blitz
';Source:
'; http://homepage.smc.edu/kennedy_john/papers.htm
'; http://homepage.smc.edu/kennedy_john/bcircle.pdf
'
'; A Fast Bresenham Type Algorithm For Drawing Circles
'; by
'; John Kennedy
'
'; Blitzplus/Blitz 3D port by Andy_A
' Thanks Andy! best one yet! see fCircB(x, y, r)
const sqr12 = sqr(.5)
radius = 350
ox = xmax/2
oy = ymax/2
t0 = ticks
for i = 1 to 100
color (i mod 15 + 1)
fCirc ox, oy, radius
next
t = ticks - t0
? t;" ms to draw 100 of these filled circles (r =350) my old fastest algo."
delay 4000
t0 = ticks
for i = 1 to 100
color (i mod 15 + 1)
fCirc2 ox, oy, radius
next
t = ticks - t0
? t;" ms for same circle test with new fastest algo."
delay 4000
t0 = ticks
for i = 1 to 100
color (i mod 15 + 1)
fCircB ox, oy, radius
next
t = ticks - t0
? t;" ms for same circle test with Bresenham algo."
pause
sub fCirc(xx, yy, r)
local r2, x, y
r2 = r * r
for x = 0 to r
y = sqr(r2-x*x)
line xx-x, yy+y, xx-x, yy-y
line xx+x, yy+y, xx+x, yy-y
next
end sub
sub fCirc2(xx, yy, r)
local r2, sqr12r, x, y
'const sqr12 = sqr(.5) 'in main const section
r2 = r * r
sqr12r = sqr12*r
rect xx-sqr12r, yy-sqr12r, xx + sqr12r, yy+sqr12r filled
for x = 0 to sqr12r
y = sqr(r2-x*x)
line xx-x, yy+sqr12r, xx-x, yy+y
line xx-x, yy-sqr12r, xx-x, yy-y
line xx+x, yy+sqr12r, xx+x, yy+y
line xx+x, yy-sqr12r, xx+x, yy-y
next
for x = sqr12*r to r
y = sqr(r2-x*x)
line xx-x, yy+y, xx-x, yy-y
line xx+x, yy+y, xx+x, yy-y
next
end sub
'Bresenham see Source notes above
sub fCircB(CX, CY, R) 'thanks Andy Amaya for heads up
Local X, Y
Local XChange, YChange
Local RadiusError
X = R
Y = 0
XChange = 1 - (R Lshift 1)
YChange = 1
RadiusError = 0
While X >= Y
Line CX-X, CY+Y, CX+X, CY+Y ';used calc'd values to draw
Line CX-X, CY-Y, CX+X, CY-Y ';scan lines from points
Line CX-Y, CY+X, CX+Y, CY+X ';in opposite octants
Line CX-Y, CY-X, CX+Y, CY-X
Y = Y + 1
RadiusError = RadiusError + YChange
YChange = YChange + 2
if (RadiusError Lshift 1) + XChange > 0 then
X = X - 1
RadiusError = RadiusError + XChange
XChange = XChange + 2
End If
Wend
End
##################################################################################
# The MIT License (MIT)
# Copyright (c) 2016-2017 B+=MGA
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##################################################################################
Thanks Andy Amaya best time yet!