Author Topic: Mars rotation only with using MEM  (Read 516 times)

Re: Mars rotation only with using MEM
« Reply #15 on: June 24, 2018, 11:42:17 AM »
BTW, Vince it looks like you are using my MODIFICATION of Steve's Circle Fill because those are my comments and I had removed Color parameter and renamed radius... I hope I did not change something essential to the shape (or time) with radius name change!

Also, I wonder if removing Color parameter could possibly slow it down in some goofy unintuitive way?
« Last Edit: June 24, 2018, 11:43:37 AM by bplus »
B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 2018 0228/86 git b30af92
QB64 v1.1 2017 1106/82

Re: Mars rotation only with using MEM
« Reply #16 on: June 24, 2018, 11:46:49 AM »
Here is code Steve had posted:
Code: [Select]
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
B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 2018 0228/86 git b30af92
QB64 v1.1 2017 1106/82

Re: Mars rotation only with using MEM
« Reply #17 on: June 25, 2018, 07:35:19 PM »
Wait... Vince, yours is faster and better than Steve's?

Wow I've got to check it out! Thanks

No, not at all.  I just prefer to use my own code in my programs.

Steve's is the absolute gold standard.

Re: Mars rotation only with using MEM
« Reply #18 on: June 26, 2018, 04:27:54 PM »
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:

Code: [Select]
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

Re: Mars rotation only with using MEM
« Reply #19 on: June 26, 2018, 04:35:41 PM »
Ignore the above post, and perhaps a nice mod will remove it for us.  It wasn't intended for this topic, and only goes to show the goofs which can happen when you sit around with multiple tabs open in your browser all the time.  /blush

Re: Mars rotation only with using MEM
« Reply #20 on: June 27, 2018, 12:17:03 AM »
Wow!  Thanks for the analysis on the paradoxical nature of programming.