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

bplus

Re: Mars rotation only with using MEM
« Reply #15 on: June 24, 2018, 10: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, 10:43:37 AM by bplus »
B = B + ...

bplus

Re: Mars rotation only with using MEM
« Reply #16 on: June 24, 2018, 10: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 LONGDIM X AS LONG, Y AS LONGRadius = ABS(R)RadiusError = -RadiusX = RadiusY = 0IF 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, BFWHILE 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, BFWENDEND SUB`
B = B + ...

_vince

Re: Mars rotation only with using MEM
« Reply #17 on: June 25, 2018, 06: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.

SMcNeill

• QB64 Developer
Re: Mars rotation only with using MEM
« Reply #18 on: June 26, 2018, 03: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 = 1000DIM SHARED CP(Radius, Radius) AS INTEGER 'CirclePointsSCREEN _NEWIMAGE(800, 600, 256)COLOR 15PreCalcCirclesx = _WIDTH / 2y = _HEIGHT / 2k = 15TestLoopLimit = 10000t1 = TIMER(0.001)FOR i = 1 TO TestLoopLimit    CircleFillFast x, y, 300, kNEXTt2 = TIMER(0.001)FOR i = 1 TO TestLoopLimit    CircleFill x, y, 300, kNEXTt3 = TIMER(0.001)PRINT USING "##.#### seconds with CircleFillFast"; t2 - t1PRINT USING "##.#### seconds with CircleFill"; t3 - t2SUB 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    NEXTEND SUBSUB 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    NEXTEND SUBSUB 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    WENDEND 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

SMcNeill

• QB64 Developer
Re: Mars rotation only with using MEM
« Reply #19 on: June 26, 2018, 03: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

_vince

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