Sometimes, computers do things that are completely counter-intuitive to us, and we find ourselves having to step back as programmers and simply say, "WOW!!" Here's a perfect example of that:

`DIM SHARED Radius AS INTEGER: Radius = 1000`

DIM SHARED CP(Radius, Radius) AS INTEGER 'CirclePoints

SCREEN _NEWIMAGE(800, 600, 256)

COLOR 15

PreCalcCircles

x = _WIDTH / 2

y = _HEIGHT / 2

k = 15

TestLoopLimit = 10000

t1 = TIMER(0.001)

FOR i = 1 TO TestLoopLimit

CircleFillFast x, y, 300, k

NEXT

t2 = TIMER(0.001)

FOR i = 1 TO TestLoopLimit

CircleFill x, y, 300, k

NEXT

t3 = TIMER(0.001)

PRINT USING "##.#### seconds with CircleFillFast"; t2 - t1

PRINT USING "##.#### seconds with CircleFill"; t3 - t2

SUB PreCalcCircles

FOR i = 0 TO Radius 'each circle, for all radius sizes from 1 to limit

FOR j = 0 TO i 'get the points for each line of those circles

CP(i, j) = SQR(i * i - j * j)

NEXT

NEXT

END SUB

SUB CircleFillFast (x, y, Radius, k)

FOR j = 0 TO Radius 'get the points for each line of those circles

LINE (x - CP(Radius, j), y + j)-(x + CP(Radius, j), y + j), k, BF

LINE (x - CP(Radius, j), y - j)-(x + CP(Radius, j), y - j), k, BF

NEXT

END SUB

SUB CircleFill (CX AS LONG, CY AS LONG, R AS LONG, C AS LONG)

DIM Radius AS LONG, RadiusError AS LONG

DIM X AS LONG, Y AS LONG

Radius = ABS(R)

RadiusError = -Radius

X = Radius

Y = 0

IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB

' Draw the middle span here so we don't draw it twice in the main loop,

' which would be a problem with blending turned on.

LINE (CX - X, CY)-(CX + X, CY), C, BF

WHILE X > Y

RadiusError = RadiusError + Y * 2 + 1

IF RadiusError >= 0 THEN

IF X <> Y + 1 THEN

LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF

LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF

END IF

X = X - 1

RadiusError = RadiusError - X * 2

END IF

Y = Y + 1

LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF

LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF

WEND

END SUB

Here we look at two different circle fill routines -- one, which I'd assume to be faster, which precalculates the offset needed to find the endpoints for each line which composes a circle, and another, which is the same old CircleFill program which I've shared countless times over the years with people on various QB64 forums.

When all is said and done though, CircleFill is STILL even faster than CircleFillFast, which pregenerates those end-points for us!

I've got to admit, I find these results rather shocking! (Thus the name I chose when naming the CircleFill-NotSoFastAfterall routine.) Apparently, in this case, the integer math used in CircleFill is faster than the time it takes for QB64 to look up those internal values from a preset array.

Who woulda thunk it?!!

Anywho, I thought I'd share, just so others could look over the two routines and compare. Maybe there's a way to improve the CircleFillFast so that it'd be faster than CircleFill, but if it is, I'm not seeing it at the moment.

It looks like CircleFill is still the fastest routine to use to rapidly fill a circle for us. :D