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

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Mars rotation only with using MEM
« on: June 19, 2018, 04:35:23 pm »
The source code shows, among other things, how to get a full circle - another option instead of Fcirc

Code: QB64: [Select]
  1.  
  2. SCREEN _NEWIMAGE(800, 600, 32) '                                                                                            my screen
  3. DIM SHARED mars AS LONG, d AS _MEM, S AS _MEM '                                                                             Mars as long is shared for accessible it in sub P_Circle, d and S are memory images
  4. mar& = _LOADIMAGE("mars.png", 32) '                                                                                         load Mars picture
  5. mars& = _NEWIMAGE(800, 600, 32) '                                                                                           create new screen wit the same resolution as my screen
  6. _PUTIMAGE , mar&, mars& '                                                                                                   insert AND RESIZE Mars picture, so now use the same resolution as My screen,
  7. _FREEIMAGE mar& '                                                                                                           this is important because of the same offset shift in memory. This row delete original Mars picture from memory
  8.  
  9.  
  10.  
  11.     P_Circle 400, 300, 99, mars&, _DEST 'radius can not be > 299 or memory region error occur.
  12.     _DISPLAY
  13.     _LIMIT 15
  14.  
  15. SUB P_Circle (CX AS LONG, CY AS LONG, R AS LONG, source AS LONG, dest AS LONG) '               CX = center X, CY = center Y, R = radius, Source - in this case mars&, Dest - in this case My screen, also _DEST
  16.     DIM d AS _MEM, s AS _MEM, clr AS LONG, Smax AS _OFFSET, PreS AS _OFFSET '                  d is for dest(My screen) memory image, S is for mars& memory image, Clr is for pixel color in RGB32 format, Smax is maximum Offset value for S and Pres is as pre - s (before is offset used, for test if is in valid range)
  17.     SHARED Shift
  18.     Shift = Shift + 15 '                                                                       image shift. The same as X = X + 15 if you use Pset(x+shift,y)
  19.     d = _MEMIMAGE(dest&): s = _MEMIMAGE(source&) '                                             create from d pointer to memory area, to begin My screen and from s pointer to memory area to begin mars& screen
  20.     Smax = s.OFFSET + (_WIDTH(mars&) * _HEIGHT(mars&) * 4) - 1 '                               calculate LAST valid offset for memory area with mars&. Its 32 bit (4 byte) screen, so * 4. For 256 color screen it is 8 bit (1 byte), so * 1. - 1, because is none offset zero.
  21.     DD = 0
  22.     FOR y& = CY& - R& TO CY& + R& '                                                            draw only in valid quad - for axis Y, from Center Y - Radius to Center Y + Radius
  23.         FOR x& = CX& - R& TO CX& + R& '                                                        the same condition for X axis
  24.             xy& = ((x& - CX&) ^ 2) + ((y& - CY&) ^ 2) '
  25.             IF R& ^ 2 >= xy& THEN '                                                            if point is on valid position in circle CX, CY, R, then
  26.                 PreS = s.OFFSET + in&(x& + Shift, y&) '                                        first calculate new offset for mars& screen (but not use it)
  27.                 IF PreS < s.OFFSET OR PreS > Smax THEN PreS = s.OFFSET '                       if calculated offset is out of range, skip to memory block contains mars& image begin
  28.                 _MEMGET s, PreS, clr& '                                                        read one pixel color info in RGBA32
  29.                 SELECT CASE ABS(xy& - R& ^ 2) '                                                select radius from end
  30.                     CASE IS < 2000: v = 10
  31.                     CASE 4000 TO 2000: v = 30
  32.                     CASE 6000 TO 4000: v = 20
  33.                     CASE 8000 TO 6000: v = 10
  34.                 END SELECT
  35.                 IF xy& - R& ^ 2 < 8000 THEN
  36.                     clr& = _RGB32(_RED32(clr&) + v, _GREEN32(clr&) - v, _BLUE32(clr&) - v) '   set different this one pixel read on line 29 in this radius with selected color
  37.                 END IF
  38.                 _MEMPUT d, d.OFFSET + in&(x&, y&), clr& '                                      draw it to myscreen (write this pixel to this block DEST, it is my screen)
  39.             END IF
  40.     NEXT x&, y&
  41.     _MEMFREE d '                                                                                delete memory pointer to my screen from memory
  42.     _MEMFREE s '                                                                                delete memory pointer to mars& screen from memory
  43.  
  44. FUNCTION in& (x AS LONG, y AS LONG)
  45.     in& = 4 * ((800 * y&) + x&) '                                                              calculate on screen positon as offset:
  46.  
  47. 'if you draw point to X = 130 and Y = 100 on screen 320 x 200, then this memory offset is: Your pointer.offset (start value which give you MEM) + width (320) * 100 + 130, also 32130 + begin for 256 colors.
  48. 'if you use _MEMPUT yourMEM, yourMEM.offset + 321, it is the same as PSET (2,1) on screen 320 x 200, 256 colors. But for 32 bit it is yourMEM.offset + 4 * 321, beacuse 32 bit use LONG 4 byte values.
  49.  
  50.  
« Last Edit: June 20, 2018, 04:32:34 pm by Petr »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Mars rotation only with using MEM
« Reply #1 on: June 19, 2018, 06:00:25 pm »
Very cool indeed. Modifying 'shift' to a lower number would 'slow' the rotation and changing it to a negative number would reverse the rotation... Cool

Great job!

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mars rotation only with using MEM
« Reply #2 on: June 19, 2018, 08:06:03 pm »
Man! got to love the speed this thing loads.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Mars rotation only with using MEM
« Reply #3 on: June 20, 2018, 12:14:05 pm »
Great work Petr! Can you comment out the code about how is it doing that?
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Mars rotation only with using MEM
« Reply #4 on: June 20, 2018, 04:31:40 pm »
Hi Ashish. Yes, i upgrade previous post. Here is alternative for Fcirc - easyest without MEM

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 256)
  2. CLS , 14
  3.  
  4. P_Circle2 320, 240, 199, 1, 15 'X, Y, radius, color 1, color 2
  5.  
  6. SUB P_Circle2 (CX AS LONG, CY AS LONG, R AS LONG, ClrIn AS LONG, ClrOut AS LONG)
  7.     FOR y& = CY& - R& TO CY& + R&
  8.         FOR x& = CX& - R& TO CX& + R&
  9.             xy& = ((x& - CX&) ^ 2) + ((y& - CY&) ^ 2)
  10.             IF R& ^ 2 >= xy& THEN
  11.                 SELECT CASE ABS(xy& - R& ^ 2)
  12.                     CASE IS <= 2 * _PI * R&: clr& = ClrIn
  13.                     CASE ELSE: clr& = ClrOut
  14.                 END SELECT
  15.                 PSET (x&, y&), clr&
  16.             END IF
  17.     NEXT x&, y&
  18.  

and faster alternative with MEM:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 256)
  2. CLS , 14
  3.  
  4. P_Circle3 320, 240, 199, 1, 15 'X, Y, radius, color 1, color 2                  
  5. SUB P_Circle3 (CX AS LONG, CY AS LONG, R AS LONG, ClrIn AS LONG, ClrOut AS LONG)
  6.     DIM m AS _MEM, Test AS _OFFSET
  7.     m = _MEMIMAGE(_DEST)
  8.     W = _WIDTH(_DEST)
  9.     H = _HEIGHT(_DEST)
  10.     Dpth = _PIXELSIZE(_DEST)
  11.     FOR y& = CY& - R& TO CY& + R&
  12.         FOR x& = CX& - R& TO CX& + R&
  13.             xy& = ((x& - CX&) ^ 2) + ((y& - CY&) ^ 2)
  14.             IF R& ^ 2 >= xy& THEN
  15.                 SELECT CASE ABS(xy& - R& ^ 2)
  16.                     CASE IS <= 2 * _PI * R&: clr& = ClrIn
  17.                     CASE ELSE: clr& = ClrOut
  18.                 END SELECT
  19.                 Test = m.OFFSET + ((y& * W) + x&) * Dpth
  20.                 IF Test > m.OFFSET + ((W * H) * Dpth) OR Test < m.OFFSET THEN EXIT SUB
  21.                 _MEMPUT m, Test, clr&
  22.             END IF
  23.     NEXT x&, y&
  24.     _MEMFREE m
  25.  
« Last Edit: June 20, 2018, 05:58:44 pm by Petr »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Mars rotation only with using MEM
« Reply #5 on: June 21, 2018, 09:34:54 am »
Thanks Petr!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

FellippeHeitor

  • Guest
Re: Mars rotation only with using MEM
« Reply #6 on: June 21, 2018, 12:40:29 pm »
Hi Petr. There's Steve's traditional circle fill sub and there's Vince's, which you may not have seen yet. Yours must become a bit faster to stack against it:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2.  
  3. green~& = _RGB32(0, 0, 255)
  4. blue~& = _RGB32(0, 0, 255)
  5.  
  6. PRINT "Vince's filled circle routine, drawing 1000 circles"
  7. t1 = TIMER
  8. FOR i = 1 TO 1000
  9.     vinceCircleFill 320, 240, 199, green~& 'X, Y, radius, color 1, color 2
  10. t2 = TIMER
  11. PRINT "Done! Time elapsed: "; t2 - t1
  12.  
  13. PRINT "Petr's filled circle routine, drawing 1000 circles"
  14. t1 = TIMER
  15. FOR i = 1 TO 1000
  16.     PetrCircle2 320, 240, 199, blue~&, blue~& 'X, Y, radius, color 1, color 2
  17. t2 = TIMER
  18. PRINT "Done! Time elapsed: "; t2 - t1
  19.  
  20.  
  21. SUB PetrCircle2 (CX AS LONG, CY AS LONG, R AS LONG, ClrIn AS LONG, ClrOut AS LONG)
  22.     FOR y& = CY& - R& TO CY& + R&
  23.         FOR x& = CX& - R& TO CX& + R&
  24.             xy& = ((x& - CX&) ^ 2) + ((y& - CY&) ^ 2)
  25.             IF R& ^ 2 >= xy& THEN
  26.                 SELECT CASE ABS(xy& - R& ^ 2)
  27.                     CASE IS <= 2 * _PI * R&: clr& = ClrIn
  28.                     CASE ELSE: clr& = ClrOut
  29.                 END SELECT
  30.                 PSET (x&, y&), clr&
  31.             END IF
  32.     NEXT x&, y&
  33.  
  34. SUB vinceCircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  35.     x0 = R
  36.     y0 = 0
  37.     e = 0
  38.     DO WHILE y0 < x0
  39.         IF e <= 0 THEN
  40.             y0 = y0 + 1
  41.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  42.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  43.             e = e + 2 * y0
  44.         ELSE
  45.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  46.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  47.             x0 = x0 - 1
  48.             e = e - 2 * x0
  49.         END IF
  50.     LOOP
  51.     LINE (x - R, y)-(x + R, y), C, BF
  52.  
  53.  

FellippeHeitor

  • Guest
Re: Mars rotation only with using MEM
« Reply #7 on: June 21, 2018, 12:42:32 pm »
BTW, Vince's is the one we use for p5js.bas.

FellippeHeitor

  • Guest
Re: Mars rotation only with using MEM
« Reply #8 on: June 21, 2018, 12:51:51 pm »
BTW, Here's the three routines doing 10000 circles:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2.  
  3. red~& = _RGB32(255, 0, 0)
  4. green~& = _RGB32(0, 0, 255)
  5. blue~& = _RGB32(0, 0, 255)
  6.  
  7. PRINT "Vince's filled circle routine, drawing 10000 circles"
  8. t1 = TIMER
  9. FOR i = 1 TO 10000
  10.     vinceCircleFill 320, 240, 199, green~& 'X, Y, radius, color
  11. t2 = TIMER
  12. PRINT "Done! Time elapsed: "; t2 - t1
  13.  
  14. PRINT "Steve's filled circle routine, drawing 10000 circles"
  15. t1 = TIMER
  16. FOR i = 1 TO 10000
  17.     steveCircleFill 320, 240, 199, red~& 'X, Y, radius, color
  18. t2 = TIMER
  19. PRINT "Done! Time elapsed: "; t2 - t1
  20.  
  21. PRINT "Petr's filled circle routine, drawing 10000 circles"
  22. t1 = TIMER
  23. FOR i = 1 TO 10000
  24.     PetrCircle2 320, 240, 199, blue~&, blue~& 'X, Y, radius, color 1, color 2
  25. t2 = TIMER
  26. PRINT "Done! Time elapsed: "; t2 - t1
  27.  
  28.  
  29. SUB PetrCircle2 (CX AS LONG, CY AS LONG, R AS LONG, ClrIn AS LONG, ClrOut AS LONG)
  30.     FOR y& = CY& - R& TO CY& + R&
  31.         FOR x& = CX& - R& TO CX& + R&
  32.             xy& = ((x& - CX&) ^ 2) + ((y& - CY&) ^ 2)
  33.             IF R& ^ 2 >= xy& THEN
  34.                 SELECT CASE ABS(xy& - R& ^ 2)
  35.                     CASE IS <= 2 * _PI * R&: clr& = ClrIn
  36.                     CASE ELSE: clr& = ClrOut
  37.                 END SELECT
  38.                 PSET (x&, y&), clr&
  39.             END IF
  40.     NEXT x&, y&
  41.  
  42. SUB vinceCircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  43.     x0 = R
  44.     y0 = 0
  45.     e = 0
  46.     DO WHILE y0 < x0
  47.         IF e <= 0 THEN
  48.             y0 = y0 + 1
  49.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  50.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  51.             e = e + 2 * y0
  52.         ELSE
  53.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  54.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  55.             x0 = x0 - 1
  56.             e = e - 2 * x0
  57.         END IF
  58.     LOOP
  59.     LINE (x - R, y)-(x + R, y), C, BF
  60.  
  61. SUB steveCircleFill (CX AS LONG, CY AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  62.     'This sub from here: http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=1848.msg17254#msg17254
  63.     DIM Radius AS LONG
  64.     DIM RadiusError AS LONG
  65.     DIM X AS LONG
  66.     DIM Y AS LONG
  67.  
  68.     Radius = ABS(R)
  69.     RadiusError = -Radius
  70.     X = Radius
  71.     Y = 0
  72.  
  73.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  74.  
  75.     ' Draw the middle span here so we don't draw it twice in the main loop,
  76.     ' which would be a problem with blending turned on.
  77.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  78.  
  79.     WHILE X > Y
  80.  
  81.         RadiusError = RadiusError + Y * 2 + 1
  82.  
  83.         IF RadiusError >= 0 THEN
  84.  
  85.             IF X <> Y + 1 THEN
  86.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  87.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  88.             END IF
  89.  
  90.             X = X - 1
  91.             RadiusError = RadiusError - X * 2
  92.  
  93.         END IF
  94.  
  95.         Y = Y + 1
  96.  
  97.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  98.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  99.  
  100.     WEND
  101.  
  102.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Mars rotation only with using MEM
« Reply #9 on: June 21, 2018, 01:28:15 pm »
I not test speed. The laziness of my program is totally terrible. Well, I'm still learning. Hats down before the authors of both much faster programs. The error is in my concept. It requires a deep reflection.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Mars rotation only with using MEM
« Reply #10 on: June 21, 2018, 02:29:57 pm »
Fellippe, when you started with comparing time, which is very beneficial to all, I give this code here. I made the analogy of the LINE command via MEMPUT. Even though I expected great speed, but  the result is to cry. It's a terrible lemur lazy. Could you tell me what I was doing here bad again? Thank you.

Code: QB64: [Select]
  1.  
  2. J& = _NEWIMAGE(800, 600, 32)
  3. m = _MEMIMAGE(J&)
  4.  
  5. T = TIMER
  6.  
  7. FOR test = 1 TO 10000
  8.     vinceCircleFill 400, 300, 200, _RGB32(0, 255, 0)
  9. NEXT test
  10.  
  11.  
  12. SUB vinceCircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  13.     x0 = R
  14.     y0 = 0
  15.     e = 0
  16.     DO WHILE y0 < x0
  17.         IF e <= 0 THEN
  18.             y0 = y0 + 1
  19.             MEM_LINE x - x0, y + y0, x + x0, y + y0, C
  20.             MEM_LINE x - x0, y - y0, x + x0, y - y0, C
  21.             e = e + 2 * y0
  22.         ELSE
  23.             MEM_LINE x - y0, y - x0, x + y0, y - x0, C
  24.             MEM_LINE x - y0, y + x0, x + y0, y + x0, C
  25.             x0 = x0 - 1
  26.             e = e - 2 * x0
  27.         END IF
  28.     LOOP
  29.     MEM_LINE x - R, y, x + R, y, C
  30.  
  31. SUB MEM_LINE (x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER, clr AS LONG)
  32.     DEFLNG A-Z
  33.     dX = x2 - x1
  34.     dY = y2 - y1
  35.     IF dX > dY OR dX = dY THEN
  36.         x = x1: y = y1
  37.         DO WHILE x <> x2
  38.             x = x + 1
  39.             y = y + (dY / dX)
  40.             _MEMPUT m, m.OFFSET + IN&(x, y), clr&
  41.         LOOP
  42.     END IF
  43.     IF dY > dX THEN
  44.         x = x1: y = y1
  45.         DO WHILE y <> y2
  46.             x = x + (dX / dY)
  47.             y = y + 1
  48.             _MEMPUT m, m.OFFSET + IN&(x, y), clr&
  49.         LOOP
  50.     END IF
  51.     IF x1 = x2 THEN
  52.         FOR d = y1 TO y2
  53.             _MEMPUT m, m.OFFSET + IN&(x1, d), clr&
  54.         NEXT d
  55.     END IF
  56.     IF y1 = y2 THEN
  57.         FOR d = x1 TO x2
  58.             _MEMPUT m, m.OFFSET + IN&(d, y1), clr&
  59.         NEXT d
  60.     END IF
  61.  
  62.     IN& = (_WIDTH * y + x) * 4
  63.  
  64.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Mars rotation only with using MEM
« Reply #11 on: June 21, 2018, 03:35:32 pm »
So, this code return 10.000 circles in 0.7 seconds. Its neverest sub which write now.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. I& = _COPYIMAGE(J&, 33) '                                                             use hardware acceleration
  3. T = TIMER
  4. FOR x = 1 TO 10000
  5.     Rectangle 320, 240, 45, 199, I& 'X axis, Y axis, Vertex number, Radius, Texture&
  6.  
  7.  
  8.  
  9. SUB Rectangle (X AS INTEGER, Y AS INTEGER, N AS INTEGER, Radius AS INTEGER, Source AS LONG)
  10.     bod = 628 / N
  11.     FOR g! = 0 TO 6.48 STEP 0.01
  12.         IF h MOD bod = 0 THEN
  13.             IF oldx = 0 THEN oldx = X: oldy = Y
  14.             _MAPTRIANGLE (oldx, oldy)-(X + SIN(g!) * Radius, Y + COS(g!) * Radius)-(X, Y), Source& TO(oldx, oldy)-(X + SIN(g!) * Radius, Y + COS(g!) * Radius)-(X, Y)
  15.             oldx = X + SIN(g!) * Radius: oldy = Y + COS(g!) * Radius
  16.         END IF
  17.         h = h + 1
  18.     NEXT g!
  19.  
  20.  

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Mars rotation only with using MEM
« Reply #12 on: June 23, 2018, 10:59:52 pm »
I'm no steve but I've noticed that both mine and steve's seem a little off of QB64's CIRCLE, mine is slightly larger while steve's is slightly smaller.  Also, steve's is slightly asymmetrical. It's barely noticeable but worth investigating.

Code: QB64: [Select]
  1. defint a-z
  2. screen _newimage(640,480,32)
  3.  
  4. circle (320,240),50,_rgb(255,0,0),,,1
  5. color _rgba(0,255,0,100)
  6. stevecf 320,240,50
  7.  
  8. circle (320,350),50,_rgb(255,0,0),,,1
  9. circlef 320,350,50,_rgba(0,255,0,100)
  10.  
  11.  
  12. 'vince's circle fill
  13. sub circlef (x, y, r, c as long)
  14.         x0 = r
  15.         y0 = 0
  16.         e = -r
  17.         do while y0 < x0
  18.                 if e <= 0 then
  19.                         y0 = y0 + 1
  20.                         line (x-x0, y+y0)-(x+x0, y+y0), c, bf
  21.                         line (x-x0, y-y0)-(x+x0, y-y0), c, bf
  22.                         e = e + 2*y0
  23.                 else
  24.                         line (x-y0, y-x0)-(x+y0, y-x0), c, bf
  25.                         line (x-y0, y+x0)-(x+y0, y+x0), c, bf
  26.                         x0 = x0 - 1
  27.                         e = e - 2*x0
  28.                 end if
  29.         loop
  30.         line (x-r,y)-(x+r,y),c,bf
  31.  
  32. 'Steve McNeil's  copied from his forum   note: Radius is too common a name ;-)
  33. SUB stevecf (CX AS LONG, CY AS LONG, R AS LONG)
  34.     DIM subRadius AS LONG, RadiusError AS LONG
  35.     DIM X AS LONG, Y AS LONG
  36.  
  37.     subRadius = ABS(R)
  38.     RadiusError = -subRadius
  39.     X = subRadius
  40.     Y = 0
  41.  
  42.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  43.  
  44.     ' Draw the middle span here so we don't draw it twice in the main loop,
  45.     ' which would be a problem with blending turned on. ;-)
  46.     LINE (CX - X, CY)-(CX + X, CY), , BF
  47.  
  48.     WHILE X > Y
  49.         RadiusError = RadiusError + Y * 2 + 1
  50.         IF RadiusError >= 0 THEN
  51.             IF X <> Y + 1 THEN
  52.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  53.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  54.             END IF
  55.             X = X - 1
  56.             RadiusError = RadiusError - X * 2
  57.         END IF
  58.         Y = Y + 1
  59.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  60.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  61.     WEND
  62.  

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Mars rotation only with using MEM
« Reply #13 on: June 23, 2018, 11:34:52 pm »
If anyone cares to do the math on it, here's a close up. Steve's on the left.

The circle is perhaps the simplest example of perfection.  Something being perfectly round does not exist in reality but it is, as an abstract concept, something we can easily conceive.  Steve introduces slight asymmetry in his own conception of the circle within the realm of QB64 to remind us of the nature of truth and reality.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mars rotation only with using MEM
« Reply #14 on: June 24, 2018, 09:42:07 am »
Wait... Vince, yours is faster and better than Steve's?

Wow I've got to check it out! Thanks