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

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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 »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mars rotation only with using MEM
« Reply #16 on: June 24, 2018, 10:46:49 am »
Here is code Steve had posted:
Code: QB64: [Select]
  1. SUB CircleFill (CX AS LONG, CY AS LONG, R AS LONG, C AS LONG)
  2. DIM Radius AS LONG, RadiusError AS LONG
  3.  
  4. Radius = ABS(R)
  5. RadiusError = -Radius
  6. X = Radius
  7. Y = 0
  8.  
  9. IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  10.  
  11. ' Draw the middle span here so we don't draw it twice in the main loop,
  12. ' which would be a problem with blending turned on.
  13. LINE (CX - X, CY)-(CX + X, CY), C, BF
  14.  
  15. WHILE X > Y
  16.     RadiusError = RadiusError + Y * 2 + 1
  17.     IF RadiusError >= 0 THEN
  18.         IF X <> Y + 1 THEN
  19.             LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  20.             LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  21.         END IF
  22.         X = X - 1
  23.         RadiusError = RadiusError - X * 2
  24.     END IF
  25.     Y = Y + 1
  26.     LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  27.     LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  28.  
  29.  

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
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.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
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: QB64: [Select]
  1. DIM SHARED Radius AS INTEGER: Radius = 1000
  2. DIM SHARED CP(Radius, Radius) AS INTEGER 'CirclePoints
  3.  
  4.  
  5. SCREEN _NEWIMAGE(800, 600, 256)
  6.  
  7.  
  8. PreCalcCircles
  9.  
  10. x = _WIDTH / 2
  11. y = _HEIGHT / 2
  12. k = 15
  13. TestLoopLimit = 10000
  14.  
  15. t1 = TIMER(0.001)
  16. FOR i = 1 TO TestLoopLimit
  17.     CircleFillFast x, y, 300, k
  18.  
  19. t2 = TIMER(0.001)
  20. FOR i = 1 TO TestLoopLimit
  21.     CircleFill x, y, 300, k
  22. t3 = TIMER(0.001)
  23.  
  24. PRINT USING "##.#### seconds with CircleFillFast"; t2 - t1
  25. PRINT USING "##.#### seconds with CircleFill"; t3 - t2
  26.  
  27.  
  28. SUB PreCalcCircles
  29.     FOR i = 0 TO Radius 'each circle, for all radius sizes from 1 to limit
  30.         FOR j = 0 TO i 'get the points for each line of those circles
  31.             CP(i, j) = SQR(i * i - j * j)
  32.         NEXT
  33.     NEXT
  34.  
  35.  
  36. SUB CircleFillFast (x, y, Radius, k)
  37.     FOR j = 0 TO Radius 'get the points for each line of those circles
  38.         LINE (x - CP(Radius, j), y + j)-(x + CP(Radius, j), y + j), k, BF
  39.         LINE (x - CP(Radius, j), y - j)-(x + CP(Radius, j), y - j), k, BF
  40.     NEXT
  41.  
  42. SUB CircleFill (CX AS LONG, CY AS LONG, R AS LONG, C AS LONG)
  43.     DIM Radius AS LONG, RadiusError AS LONG
  44.     DIM X AS LONG, Y AS LONG
  45.  
  46.     Radius = ABS(R)
  47.     RadiusError = -Radius
  48.     X = Radius
  49.     Y = 0
  50.  
  51.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  52.  
  53.     ' Draw the middle span here so we don't draw it twice in the main loop,
  54.     ' which would be a problem with blending turned on.
  55.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  56.  
  57.     WHILE X > Y
  58.         RadiusError = RadiusError + Y * 2 + 1
  59.         IF RadiusError >= 0 THEN
  60.             IF X <> Y + 1 THEN
  61.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  62.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  63.             END IF
  64.             X = X - 1
  65.             RadiusError = RadiusError - X * 2
  66.         END IF
  67.         Y = Y + 1
  68.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  69.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  70.     WEND
  71.  

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
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
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
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
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.