Author Topic: 3D Revolving Disks  (Read 8237 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
3D Revolving Disks
« on: August 17, 2019, 04:57:57 pm »
Something found at JB forum modified by yours truly:
Code: QB64: [Select]
  1. _TITLE "3D Revolving disks: any key toggles trails on/off " 'b+ trans start 2019-08-16
  2. ' mod from JB 2019-08-16 nice 3d effect by bluatigro fixed nice
  3. ' he called it "isometric 3d sprites" thread under games and graphics board
  4.  
  5. CONST xmax = 800, ymax = 600, pi = 3.141592654, nDisks = 300
  6. SCREEN _NEWIMAGE(xmax, ymax, 32)
  7. _SCREENMOVE 300, 20
  8. TYPE obj
  9.     x AS SINGLE
  10.     y AS SINGLE
  11.     z AS SINGLE
  12.     r AS SINGLE
  13.     c AS _UNSIGNED LONG
  14. DIM SHARED b(nDisks) AS obj
  15.  
  16. 'init
  17. FOR i = 0 TO nDisks
  18.     b(i).x = RND * xmax - xmax * .5
  19.     b(i).y = RND * ymax - ymax * .5
  20.     b(i).z = RND * xmax - xmax * .5
  21.     b(i).r = RND * 5
  22.     b(i).c = _RGB32(55 + RND * 200, 55 + RND * 200, 55 + RND * 200)
  23.  
  24. WHILE _KEYDOWN(27) = 0
  25.     IF LEN(INKEY$) THEN toggle = 1 - toggle
  26.     IF toggle THEN LINE (0, 0)-(xmax, ymax), _RGBA(0, 0, 0, 30), BF ELSE CLS
  27.     'update positions
  28.     FOR i = 0 TO nDisks
  29.         rotate b(i).x, b(i).z, pi / 360
  30.     NEXT i
  31.     'sort on z
  32.     QSort LBOUND(b), UBOUND(b)
  33.  
  34.     'draw b's
  35.     FOR i = nDisks TO 0 STEP -1
  36.         sx = xmax / 2 + b(i).x / (b(i).z + 1000) * 1000
  37.         sy = ymax / 2 - b(i).y / (b(i).z + 1000) * 1000
  38.         d = 100 / 2 / (b(i).z + 1000) * 1000
  39.         fcirc sx - d, sy - d, b(i).r * d / 100, b(i).c
  40.     NEXT i
  41.  
  42.     _DISPLAY
  43.     _LIMIT 60
  44.  
  45. SUB QSort (Start AS INTEGER, Finish AS INTEGER) 'sa$ needs to be shared array
  46.     DIM i AS INTEGER, j AS INTEGER, Zvalue
  47.     i = Start
  48.     j = Finish
  49.     Zvalue = b(INT((i + j) / 2)).z
  50.     WHILE i <= j
  51.         WHILE b(i).z < Zvalue
  52.             i = i + 1
  53.         WEND
  54.         WHILE b(j).z > Zvalue
  55.             j = j - 1
  56.         WEND
  57.         IF i <= j THEN
  58.             SWAP b(i), b(j)
  59.             i = i + 1
  60.             j = j - 1
  61.         END IF
  62.     WEND
  63.     IF j > Start THEN QSort Start, j
  64.     IF i < Finish THEN QSort i, Finish
  65.  
  66. SUB rotate (x, z, angle)
  67.     s = SIN(angle)
  68.     c = COS(angle)
  69.     newx = x * c - z * s
  70.     newz = x * s + z * c
  71.     x = newx
  72.     z = newz
  73.  
  74. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  75.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  76.     DIM X AS INTEGER, Y AS INTEGER
  77.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  78.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  79.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  80.     WHILE X > Y
  81.         RadiusError = RadiusError + Y * 2 + 1
  82.         IF RadiusError >= 0 THEN
  83.             IF X <> Y + 1 THEN
  84.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  85.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  86.             END IF
  87.             X = X - 1
  88.             RadiusError = RadiusError - X * 2
  89.         END IF
  90.         Y = Y + 1
  91.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  92.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  93.     WEND
  94.  
  95.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: 3D Revolving Disks
« Reply #1 on: August 17, 2019, 06:28:42 pm »
Bplus
What to say... Great, cool!

Thanks to share

Ps I must admit that this program has its neo.... it shows so many revolving balls :D
But if I think better in this program there is a great lesson that I try to learn.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D Revolving Disks
« Reply #2 on: August 17, 2019, 07:20:04 pm »
Bplus
What to say... Great, cool!

Thanks to share

Ps I must admit that this program has its neo.... it shows so many revolving balls :D
But if I think better in this program there is a great lesson that I try to learn.

shh... those aren't balls, those are disks :D

Thanks TempodiBasic, it may be a good entry level starter for 3D? I liked it, but now I am wondering if this is like Fellippe's flies thing from some time ago.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Revolving Disks
« Reply #3 on: August 17, 2019, 07:23:12 pm »
Pretty cool! I updated it to show big disco lights on your entire screen. I added a welcome page so people know to hit Esc to quit or any other key to change views. I'm just having fun with it, it won't be on my website.

Code: QB64: [Select]
  1. _TITLE "3D Revolving disks: any key toggles trails on/off " 'b+ trans start 2019-08-16
  2. ' mod from JB 2019-08-16 nice 3d effect by bluatigro fixed nice
  3. ' he called it "isometric 3d sprites" thread under games and graphics board
  4. ' Updated again by Ken G. to make disco lights.
  5.  
  6. PRINT "                   Disco Lights On Your Entire Screen"
  7. PRINT "     Press Esc to quit program or any other key to change the view."
  8. INPUT "                       Press Enter to start.", a$
  9.  
  10. CONST xmax = 800, ymax = 600, pi = 3.141592654, nDisks = 300
  11. SCREEN _NEWIMAGE(xmax, ymax, 32)
  12. '_SCREENMOVE 300, 20
  13. TYPE obj
  14.     x AS SINGLE
  15.     y AS SINGLE
  16.     z AS SINGLE
  17.     r AS SINGLE
  18.     c AS _UNSIGNED LONG
  19. DIM SHARED b(nDisks) AS obj
  20.  
  21. 'init
  22. FOR i = 0 TO nDisks
  23.     b(i).x = RND * xmax - xmax * .5
  24.     b(i).y = RND * ymax - ymax * .5
  25.     b(i).z = RND * xmax - xmax * .5
  26.     b(i).r = RND * 5
  27.     b(i).c = _RGB32(55 + RND * 200, 55 + RND * 200, 55 + RND * 200)
  28.  
  29. WHILE _KEYDOWN(27) = 0
  30.     IF LEN(INKEY$) THEN toggle = 1 - toggle
  31.     IF toggle THEN LINE (0, 0)-(xmax, ymax), _RGBA(0, 0, 0, 30), BF ELSE CLS
  32.     'update positions
  33.     FOR i = 0 TO nDisks
  34.         rotate b(i).x, b(i).z, pi / 360
  35.     NEXT i
  36.     'sort on z
  37.     QSort LBOUND(b), UBOUND(b)
  38.  
  39.     'draw b's
  40.     FOR i = nDisks TO 0 STEP -1
  41.         sx = xmax / 2 + b(i).x / (b(i).z + 1000) * 1000
  42.         sy = ymax / 2 - b(i).y / (b(i).z + 1000) * 1000
  43.         d = 100 / 2 / (b(i).z + 1000) * 1000
  44.         fcirc sx - d, sy - d, b(i).r * d / 100, b(i).c
  45.     NEXT i
  46.  
  47.     _DISPLAY
  48.     _LIMIT 60
  49.  
  50. SUB QSort (Start AS INTEGER, Finish AS INTEGER) 'sa$ needs to be shared array
  51.     DIM i AS INTEGER, j AS INTEGER, Zvalue
  52.     i = Start
  53.     j = Finish
  54.     Zvalue = b(INT((i + j) / 2)).z
  55.     WHILE i <= j
  56.         WHILE b(i).z < Zvalue
  57.             i = i + 1
  58.         WEND
  59.         WHILE b(j).z > Zvalue
  60.             j = j - 1
  61.         WEND
  62.         IF i <= j THEN
  63.             SWAP b(i), b(j)
  64.             i = i + 1
  65.             j = j - 1
  66.         END IF
  67.     WEND
  68.     IF j > Start THEN QSort Start, j
  69.     IF i < Finish THEN QSort i, Finish
  70.  
  71. SUB rotate (x, z, angle)
  72.     s = SIN(angle)
  73.     c = COS(angle)
  74.     newx = x * c - z * s
  75.     newz = x * s + z * c
  76.     x = newx
  77.     z = newz
  78.  
  79. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  80.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  81.     DIM X AS INTEGER, Y AS INTEGER
  82.     Radius = ABS(R): RadiusError = -Radius: X = Radius: Y = 0
  83.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  84.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  85.     WHILE X > Y
  86.         RadiusError = RadiusError + Y * 2 + 1
  87.         IF RadiusError >= 0 THEN
  88.             IF X <> Y + 1 THEN
  89.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  90.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  91.             END IF
  92.             X = X - 1
  93.             RadiusError = RadiusError - X * 2
  94.         END IF
  95.         Y = Y + 1
  96.         FOR cc = .25 TO X * 10 STEP .25
  97.             CIRCLE (CX - X, CY - Y), cc, C
  98.         NEXT cc
  99.  
  100.         'LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  101.         'LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  102.     WEND
  103.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D Revolving Disks
« Reply #4 on: August 17, 2019, 07:48:33 pm »
Yikes! what you did to the circle fill sub is like spray painting the Mona Lisa
Code: QB64: [Select]
  1.         FOR cc = .25 TO X * 10 STEP .25
  2.             CIRCLE (CX - X, CY - Y), cc, C
  3.         NEXT cc
  4.  
  5.         'LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  6.         'LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  7.  

Ken for you, here is your circle fill you might live with:
Code: QB64: [Select]
  1. 'Ken's circleFill sub demo / tester
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 60
  5.  
  6. PRINT "red circle fill at 100, 150 radius 30 and blue circle  fill at 300, 400 radius 100"
  7. CircleFill 100, 150, 30, _RGB32(255, 0, 0)
  8. CircleFill 300, 400, 100, _RGB32(0, 0, 255)
  9.  
  10. INPUT "press Enter for screen filled with circles... "; wait$
  11.  
  12. WHILE _KEYDOWN(27) = 0
  13.     CircleFill RND * xmax, RND * ymax, RND * 80, _RGB32(RND * 255, RND * 255, RND * 255)
  14.     lpCnt = lpCnt + 1
  15.     IF lpCnt MOD 50 = 49 THEN CLS
  16.     _DISPLAY
  17.     _LIMIT 60
  18.  
  19. SUB CircleFill (centerX, centerY, circleRadius, circleColor AS _UNSIGNED LONG)
  20.     FOR changeRadius = .25 TO circleRadius STEP .25
  21.         CIRCLE (centerX, centerY), changeRadius, circleColor
  22.     NEXT

I have to admit I never thought CIRCLE could fill a disk area solidly without holes until I saw your method Ken.

You can copy and paste the SUB into any program you need a CircleFill and just call it up with:
Code: QB64: [Select]
  1. CircleFill MyCenterX, MyCenterY, MyRadius, MyRGBColor


Here is your mod with YOUR CircleFill:
Code: QB64: [Select]
  1. _TITLE "3D Revolving disks: any key toggles trails on/off " 'b+ trans start 2019-08-16
  2. ' mod from JB 2019-08-16 nice 3d effect by bluatigro fixed nice
  3. ' he called it "isometric 3d sprites" thread under games and graphics board
  4. ' Updated again by Ken G. to make disco lights.
  5. ' MOD by B+ with Ken G style CircleFill  
  6.  
  7. PRINT "                   Disco Lights On Your Entire Screen"
  8. PRINT "     Press Esc to quit program or any other key to change the view."
  9. INPUT "                       Press Enter to start.", a$
  10.  
  11. CONST xmax = 800, ymax = 600, pi = 3.141592654, nDisks = 300
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. '_SCREENMOVE 300, 20
  14. TYPE obj
  15.     x AS SINGLE
  16.     y AS SINGLE
  17.     z AS SINGLE
  18.     r AS SINGLE
  19.     c AS _UNSIGNED LONG
  20. DIM SHARED b(nDisks) AS obj
  21.  
  22. 'init
  23. FOR i = 0 TO nDisks
  24.     b(i).x = RND * xmax - xmax * .5
  25.     b(i).y = RND * ymax - ymax * .5
  26.     b(i).z = RND * xmax - xmax * .5
  27.     b(i).r = RND * 5
  28.     b(i).c = _RGB32(55 + RND * 200, 55 + RND * 200, 55 + RND * 200)
  29.  
  30. WHILE _KEYDOWN(27) = 0
  31.     IF LEN(INKEY$) THEN toggle = 1 - toggle
  32.     IF toggle THEN LINE (0, 0)-(xmax, ymax), _RGBA(0, 0, 0, 30), BF ELSE CLS
  33.     'update positions
  34.     FOR i = 0 TO nDisks
  35.         rotate b(i).x, b(i).z, pi / 360
  36.     NEXT i
  37.     'sort on z
  38.     QSort LBOUND(b), UBOUND(b)
  39.  
  40.     'draw b's
  41.     FOR i = nDisks TO 0 STEP -1
  42.         sx = xmax / 2 + b(i).x / (b(i).z + 1000) * 1000
  43.         sy = ymax / 2 - b(i).y / (b(i).z + 1000) * 1000
  44.         d = 100 / 2 / (b(i).z + 1000) * 1000
  45.         CircleFill sx - d, sy - d, b(i).r * d / 100, b(i).c
  46.     NEXT i
  47.  
  48.     _DISPLAY
  49.     _LIMIT 60
  50.  
  51. SUB QSort (Start AS INTEGER, Finish AS INTEGER) 'sa$ needs to be shared array
  52.     DIM i AS INTEGER, j AS INTEGER, Zvalue
  53.     i = Start
  54.     j = Finish
  55.     Zvalue = b(INT((i + j) / 2)).z
  56.     WHILE i <= j
  57.         WHILE b(i).z < Zvalue
  58.             i = i + 1
  59.         WEND
  60.         WHILE b(j).z > Zvalue
  61.             j = j - 1
  62.         WEND
  63.         IF i <= j THEN
  64.             SWAP b(i), b(j)
  65.             i = i + 1
  66.             j = j - 1
  67.         END IF
  68.     WEND
  69.     IF j > Start THEN QSort Start, j
  70.     IF i < Finish THEN QSort i, Finish
  71.  
  72. SUB rotate (x, z, angle)
  73.     s = SIN(angle)
  74.     c = COS(angle)
  75.     newx = x * c - z * s
  76.     newz = x * s + z * c
  77.     x = newx
  78.     z = newz
  79.  
  80. SUB CircleFill (centerX, centerY, circleRadius, circleColor AS _UNSIGNED LONG)
  81.     FOR changeRadius = .25 TO circleRadius STEP .25
  82.         CIRCLE (centerX, centerY), changeRadius, circleColor
  83.     NEXT
  84.  
  85.  

You are now free to change Radii as you see fit, thanks for your consideration. :)
« Last Edit: August 17, 2019, 08:04:18 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D Revolving Disks
« Reply #5 on: August 17, 2019, 08:31:00 pm »
I found the code I was remembering Fellippe had posted, gave it a trails toggle like here. They are much alike!
Code: QB64: [Select]
  1. 'Fellippe had posted here:
  2. ' https://www.qb64.org/forum/index.php?topic=255.msg1387#msg1387
  3. ' 2019-08-17 B+ adds trails toggle, a trick he learned from this codes author
  4.  
  5. SCREEN _NEWIMAGE(600, 600, 32)
  6. _TITLE "Particles: any key toggles trails on and off"
  7.  
  8. TYPE PARTICLE
  9.     x AS SINGLE
  10.     xs AS SINGLE
  11.     y AS SINGLE
  12.     ys AS SINGLE
  13.     w AS SINGLE
  14.     h AS SINGLE
  15.     a AS SINGLE
  16.     r AS SINGLE
  17.     c AS _UNSIGNED LONG
  18.  
  19. DIM particle(100) AS PARTICLE
  20.  
  21. createParticles particle()
  22.  
  23.     IF LEN(INKEY$) THEN toggle = 1 - toggle
  24.     IF toggle THEN LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA32(0, 0, 0, 50), BF ELSE CLS
  25.     updateAndShowParticles particle()
  26.         IF r < 150 THEN r = r + 1 ELSE r = 0
  27.         CIRCLE (_MOUSEX, _MOUSEY), r, _RGBA32(255, 255, 0, 150 - r)
  28.     END IF
  29.     _DISPLAY
  30.     _LIMIT 30
  31.  
  32. SUB createParticles (this() AS PARTICLE)
  33.     FOR i = 0 TO UBOUND(this)
  34.         this(i).x = RND * _WIDTH
  35.         this(i).xs = 2 + RND * 3
  36.         this(i).y = RND * _HEIGHT
  37.         this(i).ys = 2 + RND * 3
  38.         this(i).w = RND * (_WIDTH / 4)
  39.         this(i).h = RND * (_WIDTH / 6)
  40.         this(i).a = RND * _PI(2)
  41.         this(i).r = RND * 3 + 1
  42.         this(i).c = _RGBA32(RND * 255, RND * 255, RND * 255, RND * 150 + 155)
  43.     NEXT
  44.  
  45. SUB updateAndShowParticles (this() AS PARTICLE)
  46.     FOR i = 0 TO UBOUND(this)
  47.         this(i).a = this(i).a + .1
  48.         IF this(i).a > _PI(2) THEN this(i).a = this(i).a - _PI(2)
  49.  
  50.         IF _MOUSEBUTTON(1) THEN
  51.             IF this(i).y > _MOUSEY THEN this(i).y = this(i).y + r / 15
  52.             IF this(i).y < _MOUSEY THEN this(i).y = this(i).y - r / 15
  53.             IF this(i).x > _MOUSEX THEN this(i).x = this(i).x + r / 15
  54.             IF this(i).x < _MOUSEX THEN this(i).x = this(i).x - r / 15
  55.         ELSE
  56.             r = 0
  57.             IF this(i).y > _MOUSEY THEN this(i).y = this(i).y - this(i).ys
  58.             IF this(i).y < _MOUSEY THEN this(i).y = this(i).y + this(i).ys
  59.             IF this(i).x > _MOUSEX THEN this(i).x = this(i).x - this(i).xs
  60.             IF this(i).x < _MOUSEX THEN this(i).x = this(i).x + this(i).xs
  61.         END IF
  62.  
  63.         CircleFill this(i).x + COS(this(i).a) * this(i).w, this(i).y + SIN(this(i).a) * this(i).h, this(i).r, this(i).c
  64.     NEXT
  65.  
  66. SUB CircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  67.     x0 = R
  68.     y0 = 0
  69.     e = 0
  70.     DO WHILE y0 < x0
  71.         IF e <= 0 THEN
  72.             y0 = y0 + 1
  73.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  74.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  75.             e = e + 2 * y0
  76.         ELSE
  77.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  78.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  79.             x0 = x0 - 1
  80.             e = e - 2 * x0
  81.         END IF
  82.     LOOP
  83.     LINE (x - R, y)-(x + R, y), C, BF
  84.  

OK so now I challenge!
Give the Mouse Particles / Flies code some 3D effect.
« Last Edit: August 17, 2019, 08:34:33 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: 3D Revolving Disks
« Reply #6 on: August 17, 2019, 08:44:24 pm »
Fun demo!

This reminds me of when I realized I needed real math to achieve the 3D look - because when I wrote similar things, something bugged me about where the actual "point of view" is located, and I come here to say this is not quite the idea to be studying if people want to really advance into the third dimension. Follow me.

This demo is showing a rotating mass of balls - here is the kicker - as viewed from "infinity". (By "infinity" I mean the user's eye is very very far away from the thing being looked at.) When you look at this scene, every single ball is in front of you - the only reason to not see any particular ball is when it goes off the side of the screen, right? But this is an incomplete implementation of 3D... In other words, why aren't any balls disappearing as they get too close to the user's eye and pass outside of our cone of vision? That is, why doesn't it feel like I can "fly through" this thing? I'm always watching it from far away. Feel me? In other words, if you were to try to make, whatever, a Wolfenstein engine with this as a starting point, you would see the entire level at all times. You could never get the walls behind you.

Honestly it took me a few years to go from what you've got here to what you see in Sanctum. It all changed when I wrote this note to myself:
main idea picture.jpg
* main idea picture.jpg (Filesize: 836.94 KB, Dimensions: 3507x2550, Views: 356)
You're not done when it works, you're done when it's right.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Revolving Disks
« Reply #7 on: August 17, 2019, 08:55:38 pm »
Wow thanks B+! I'm just starting to use _DISPLAY to stop the flickering, which is why I did the CIRCLE .25 loop still.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D Revolving Disks
« Reply #8 on: August 17, 2019, 09:00:22 pm »
Man! STxAxTIC, I just get use to doing perspective sizing and layering with a Z sort and now you want to fly through the thing!

Man! OK, you got me thinking... :)

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: 3D Revolving Disks
« Reply #9 on: August 17, 2019, 09:12:14 pm »
Phew! I thought you would take what I said as a dig - but along the lines of perspective sizing and z-sort...

If you pursue a more general approach, perspective sizing goes out the window and is handled automatically by field of view distance. In my old prototypes, the fudge factor variable I used was called "falsedepth", and was SO happy to erase it when I cracked the problem. (You are walking a 100% analogous path to the one I took...)

And if you go with my notation, Z sort is correctly replaced by N-sort, where N is the vector perpendicular to the screen.

Okay, shutting up now.
You're not done when it works, you're done when it's right.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Revolving Disks
« Reply #10 on: August 18, 2019, 04:42:38 am »
It's getting going. :-) I solved the limitation of the size of the displayed field by means of the circular collision detection adjusted to the semicircle (for X / Z) and the circle for (X / Y). Just what is in front of the monitor or outside the set radius from the camera does not count at all.  (the beginning of the vector is a spatial 3D point where the camera is standing, and the ending 3D point is the vertex in the field (further in my program it is already a point in the body or outside the body around which the body can rotate))
I calculate the size of the vector by the Pythagorean theorem and the angle of the vector in radians using the JK! Functions I wrote. This is available in the MAPTRIANGLE 3D thread. It is definitely very interesting to see the conversion of X and Y to Z using 2D commands.




Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Revolving Disks
« Reply #11 on: August 18, 2019, 08:54:46 pm »
I took this idea and added it to my new Solar System Simulator. I'll post it also in the old Solar System thread. :) I didn't use the same code though, just trial and error figured it out.  Use Mouse over the planets to I.D. them. Use Mouse Wheel to zoom in and out to all of the planets, and use Up and Down Arrow Keys to tilt the view.

Code: QB64: [Select]
  1. 'Ken G. made thie program on August 18, 2019,
  2. 'Thank you to STxAxTIC on the QB64.org forum for a little bit of help with The Moon orbit!
  3.  
  4. _TITLE "Solar System Simulator by Ken G. Use Mouse Over Planets, Mouse Wheel to Zoom, and Up and Down Arrow Keys To Tilt."
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. mercury = 0.241
  7. venus = 0.6152
  8. mars = 1.8809
  9. jupiter = 11.8618
  10. saturn = 29.457
  11. uranus = 84.0205
  12. neptune = 164.8
  13. angle = 180
  14. tilt = 1
  15. one:
  16. _LIMIT 500
  17. mouseWheel = 0
  18.     mouseX = _MOUSEX
  19.     mouseY = _MOUSEY
  20.     mouseLeftButton = _MOUSEBUTTON(1)
  21.     mouseRightButton = _MOUSEBUTTON(2)
  22.     mouseMiddleButton = _MOUSEBUTTON(3)
  23.     mouseWheel = mouseWheel + _MOUSEWHEEL
  24. IF mouseWheel < 0 THEN angle = angle - 10
  25. IF mouseWheel > 0 THEN angle = angle + 10
  26.  
  27. IF mouseX > 385 AND mouseX < 415 AND mouseY > 285 AND mouseY < 315 THEN LOCATE 2, 49: PRINT "Sun    "
  28. IF mouseX > x1 - 15 AND mouseX < x1 + 15 AND mouseY > y1 - 15 AND mouseY < y1 + 15 THEN LOCATE 2, 49: PRINT "Mercury"
  29. IF mouseX > x2 - 15 AND mouseX < x2 + 15 AND mouseY > y2 - 15 AND mouseY < y2 + 15 THEN LOCATE 2, 49: PRINT "Venus  "
  30. IF mouseX > x - 15 AND mouseX < x + 15 AND mouseY > y - 15 AND mouseY < y + 15 THEN LOCATE 2, 49: PRINT "Earth  "
  31. IF mouseX > x3 - 15 AND mouseX < x3 + 15 AND mouseY > y3 - 15 AND mouseY < y3 + 15 THEN LOCATE 2, 49: PRINT "Mars   "
  32. IF mouseX > x5 - 15 AND mouseX < x5 + 15 AND mouseY > y5 - 15 AND mouseY < y5 + 15 THEN LOCATE 2, 49: PRINT "Jupiter"
  33. IF mouseX > x6 - 15 AND mouseX < x6 + 15 AND mouseY > y6 - 15 AND mouseY < y6 + 15 THEN LOCATE 2, 49: PRINT "Saturn "
  34. IF mouseX > x7 - 15 AND mouseX < x7 + 15 AND mouseY > y7 - 15 AND mouseY < y7 + 15 THEN LOCATE 2, 49: PRINT "Uranus "
  35. IF mouseX > x8 - 15 AND mouseX < x8 + 15 AND mouseY > y8 - 15 AND mouseY < y8 + 15 THEN LOCATE 2, 49: PRINT "Neptune"
  36.  
  37. a$ = INKEY$
  38. IF a$ = CHR$(27) THEN END
  39. IF a$ = CHR$(0) + CHR$(72) THEN tilt = tilt + 1
  40. IF a$ = CHR$(0) + CHR$(80) THEN tilt = tilt - 1
  41. IF angle > 360 THEN angle = 360
  42. IF angle < 10 THEN angle = 10
  43. IF tilt > 90 THEN tilt = 90
  44. IF tilt < 1 THEN tilt = 1
  45. seconds = seconds + .01
  46. s1 = (60 - seconds) * 6 + 180 / mercury
  47. s2 = (60 - seconds) * 6 + 180 / venus
  48. s3 = (60 - seconds) * 6 + 180 'Earth and Moon
  49. s4 = (60 - seconds) * 6 + 180 / mars
  50. s5 = (60 - seconds) * 6 + 180 / jupiter
  51. s6 = (60 - seconds) * 6 + 180 / saturn
  52. s7 = (60 - seconds) * 6 + 180 / uranus
  53. s8 = (60 - seconds) * 6 + 180 / neptune
  54.  
  55. 'Mercury
  56. x1 = INT(SIN(s1 / 45 * 3.141592) * angle / 4) + 400
  57. y1 = INT(COS(s1 / 45 * 3.141592) * (angle / 4) / tilt) + 300
  58.  
  59. 'Venus
  60. x2 = INT(SIN(s2 / 90 * 3.141592) * angle / 2) + 400
  61. y2 = INT(COS(s2 / 90 * 3.141592) * (angle / 2) / tilt) + 300
  62.  
  63. 'Earth
  64. x = INT(SIN(s3 / 180 * 3.141592) * angle) + 400
  65. y = INT(COS(s3 / 180 * 3.141592) * angle / tilt) + 300
  66.  
  67. 'Mars
  68. x3 = INT(SIN(s4 / 270 * 3.141592) * angle * 1.5) + 400
  69. y3 = INT(COS(s4 / 270 * 3.141592) * (angle * 1.5) / tilt) + 300
  70.  
  71. 'Moon
  72. x4 = INT(SIN(19 * s3 / 270 * 3.141592) * angle / 10) + x
  73. y4 = INT(COS(19 * s3 / 270 * 3.141592) * (angle / 10) / tilt) + y
  74.  
  75. 'Outer Planets
  76. 'Jupiter
  77. x5 = INT(SIN(s5 / 450 * 3.141592) * angle * 3) + 400
  78. y5 = INT(COS(s5 / 450 * 3.141592) * (angle * 3) / tilt) + 300
  79.  
  80. 'Saturn
  81. x6 = INT(SIN(s6 / 630 * 3.141592) * angle * 4.5) + 400
  82. y6 = INT(COS(s6 / 630 * 3.141592) * (angle * 4.5) / tilt) + 300
  83.  
  84. 'Uranus
  85. x7 = INT(SIN(s7 / 810 * 3.141592) * angle * 6) + 400
  86. y7 = INT(COS(s7 / 810 * 3.141592) * (angle * 6) / tilt) + 300
  87.  
  88. 'Neptune
  89. x8 = INT(SIN(s8 / 990 * 3.141592) * angle * 7.5) + 400
  90. y8 = INT(COS(s8 / 990 * 3.141592) * (angle * 7.5) / tilt) + 300
  91.  
  92. 'Mercury
  93. CIRCLE (x1, y1), 5, _RGB32(120, 98, 102)
  94. PAINT (x1, y1), _RGB32(120, 98, 102)
  95.  
  96. 'Venus
  97. CIRCLE (x2, y2), 5, _RGB32(161, 67, 39)
  98. PAINT (x2, y2), _RGB32(161, 67, 39)
  99.  
  100. 'Earth
  101. CIRCLE (x, y), 5, _RGB32(0, 0, 255)
  102. PAINT (x, y), _RGB32(0, 0, 255)
  103.  
  104. 'Mars
  105. CIRCLE (x3, y3), 5, _RGB32(240, 72, 22)
  106. PAINT (x3, y3), _RGB32(240, 72, 22)
  107.  
  108. 'Moon
  109. CIRCLE (x4, y4), 2.5, _RGB32(179, 179, 181)
  110. PAINT (x4, y4), _RGB32(179, 179, 181)
  111.  
  112. 'Outer Planets
  113. 'Jupiter
  114. CIRCLE (x5, y5), 5, _RGB32(255, 166, 127)
  115. PAINT (x5, y5), _RGB32(255, 166, 127)
  116.  
  117. 'Saturn
  118. CIRCLE (x6, y6), 5, _RGB32(255, 127, 127)
  119. PAINT (x6, y6), _RGB32(255, 127, 127)
  120. FOR rings = 1 TO 2
  121.     CIRCLE (x6, y6), 7 + rings, _RGB32(255, 127, 127), , , .65
  122. NEXT rings
  123.  
  124. 'Uranus
  125. CIRCLE (x7, y7), 5, _RGB32(127, 166, 255)
  126. PAINT (x7, y7), _RGB32(127, 166, 255)
  127.  
  128. 'Neptune
  129. CIRCLE (x8, y8), 5, _RGB32(0, 78, 255)
  130. PAINT (x8, y8), _RGB32(0, 78, 255)
  131.  
  132. 'Sun
  133. CIRCLE (400, 300), 5, _RGB32(249, 240, 22)
  134. PAINT (400, 300), _RGB32(249, 240, 22)
  135. IF seconds > 99999 THEN
  136.     CLS
  137.     seconds = 0
  138.     GOTO one:
  139. GOTO one:
  140.  

« Last Edit: August 18, 2019, 08:57:23 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D Revolving Disks
« Reply #12 on: August 18, 2019, 09:30:41 pm »
Hi Ken,

I like the tilt but not quite there with Zorder, what is drawn in front of what, ie the sun is always in front.

Nor quite there with near and far sizing for perspective.

Still, you worked out the tilt! :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Revolving Disks
« Reply #13 on: August 19, 2019, 01:22:33 am »
Yeah I wasn't even thinking of these things earlier, but thanks for telling me. I tried all kinds of ways tonight to make the Sun disappear and reappear, etc. etc. etc. I finally did it the only way I know how, to make the planets disappear if X increases and starts going behind the Sun, then reappears when they come back around. This only happens when you tilt the planets to a certain degree. I also made the Sun smaller so you could see more of the planets. Making them disappear and reappear also makes the illusion of them leaving and come back, which is your other thing you mentioned. Just know that I've never worked that much with the Z axis except in CAD type drawings. I use DIM z(10) so the planets would stay the way they were until they were needed to change. Tonight and 1 or 2 other times I've noticed a difference in QB64 and QBasic (I think) in that when you are using a main loop and you just want to skip over some code to not do it in that certain loop, the graphics you want to not-make, still happens. I think because the loop goes so fast that it doesn't give the user time to see it disappear. So, I use an array instead sometimes to deal with certain times when things need to be off or on. In this program z(1) = 1 means that Mercury is going to hide until it comes back around. :)

Note: I was about to head to bed and I immediately figured out how to make this better, please go to my next post, thank you.

Code: QB64: [Select]
  1. 'Ken G. made thie program on August 18, 2019,
  2. 'Thank you to STxAxTIC on the QB64.org forum for a little bit of help with The Moon orbit!
  3.  
  4. _TITLE "Solar System Simulator by Ken G. Use Mouse Over Planets, Mouse Wheel to Zoom, and Up and Down Arrow Keys To Tilt."
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. DIM z(10)
  7. mercury = 0.241
  8. venus = 0.6152
  9. mars = 1.8809
  10. jupiter = 11.8618
  11. saturn = 29.457
  12. uranus = 84.0205
  13. neptune = 164.8
  14. angle = 180
  15. tilt = 1
  16. one:
  17. _LIMIT 500
  18. mouseWheel = 0
  19.     mouseX = _MOUSEX
  20.     mouseY = _MOUSEY
  21.     mouseLeftButton = _MOUSEBUTTON(1)
  22.     mouseRightButton = _MOUSEBUTTON(2)
  23.     mouseMiddleButton = _MOUSEBUTTON(3)
  24.     mouseWheel = mouseWheel + _MOUSEWHEEL
  25. IF mouseWheel < 0 THEN angle = angle - 10
  26. IF mouseWheel > 0 THEN angle = angle + 10
  27.  
  28. IF mouseX > 385 AND mouseX < 415 AND mouseY > 285 AND mouseY < 315 THEN LOCATE 2, 49: PRINT "Sun    "
  29. IF mouseX > x1 - 15 AND mouseX < x1 + 15 AND mouseY > y1 - 15 AND mouseY < y1 + 15 THEN LOCATE 2, 49: PRINT "Mercury"
  30. IF mouseX > x2 - 15 AND mouseX < x2 + 15 AND mouseY > y2 - 15 AND mouseY < y2 + 15 THEN LOCATE 2, 49: PRINT "Venus  "
  31. IF mouseX > x - 15 AND mouseX < x + 15 AND mouseY > y - 15 AND mouseY < y + 15 THEN LOCATE 2, 49: PRINT "Earth  "
  32. IF mouseX > x3 - 15 AND mouseX < x3 + 15 AND mouseY > y3 - 15 AND mouseY < y3 + 15 THEN LOCATE 2, 49: PRINT "Mars   "
  33. IF mouseX > x5 - 15 AND mouseX < x5 + 15 AND mouseY > y5 - 15 AND mouseY < y5 + 15 THEN LOCATE 2, 49: PRINT "Jupiter"
  34. IF mouseX > x6 - 15 AND mouseX < x6 + 15 AND mouseY > y6 - 15 AND mouseY < y6 + 15 THEN LOCATE 2, 49: PRINT "Saturn "
  35. IF mouseX > x7 - 15 AND mouseX < x7 + 15 AND mouseY > y7 - 15 AND mouseY < y7 + 15 THEN LOCATE 2, 49: PRINT "Uranus "
  36. IF mouseX > x8 - 15 AND mouseX < x8 + 15 AND mouseY > y8 - 15 AND mouseY < y8 + 15 THEN LOCATE 2, 49: PRINT "Neptune"
  37.  
  38. a$ = INKEY$
  39. IF a$ = CHR$(27) THEN END
  40. IF a$ = CHR$(0) + CHR$(72) THEN tilt = tilt + 1
  41. IF a$ = CHR$(0) + CHR$(80) THEN tilt = tilt - 1
  42. IF angle > 360 THEN angle = 360
  43. IF angle < 10 THEN angle = 10
  44. IF tilt > 30 THEN tilt = 30
  45. IF tilt < 1 THEN tilt = 1
  46. seconds = seconds + .01
  47. s1 = (60 - seconds) * 6 + 180 / mercury
  48. s2 = (60 - seconds) * 6 + 180 / venus
  49. s3 = (60 - seconds) * 6 + 180 'Earth and Moon
  50. s4 = (60 - seconds) * 6 + 180 / mars
  51. s5 = (60 - seconds) * 6 + 180 / jupiter
  52. s6 = (60 - seconds) * 6 + 180 / saturn
  53. s7 = (60 - seconds) * 6 + 180 / uranus
  54. s8 = (60 - seconds) * 6 + 180 / neptune
  55.  
  56.  
  57. 'Mercury
  58. oldx1 = x1
  59. x1 = INT(SIN(s1 / 45 * 3.141592) * angle / 4) + 400
  60. y1 = INT(COS(s1 / 45 * 3.141592) * (angle / 4) / tilt) + 300
  61.  
  62. 'Venus
  63. oldx2 = x2
  64. x2 = INT(SIN(s2 / 90 * 3.141592) * angle / 2) + 400
  65. y2 = INT(COS(s2 / 90 * 3.141592) * (angle / 2) / tilt) + 300
  66.  
  67. 'Earth
  68. oldx = x
  69. x = INT(SIN(s3 / 180 * 3.141592) * angle) + 400
  70. y = INT(COS(s3 / 180 * 3.141592) * angle / tilt) + 300
  71.  
  72. 'Mars
  73. oldx3 = x3
  74. x3 = INT(SIN(s4 / 270 * 3.141592) * angle * 1.5) + 400
  75. y3 = INT(COS(s4 / 270 * 3.141592) * (angle * 1.5) / tilt) + 300
  76.  
  77. 'Moon
  78. x4 = INT(SIN(19 * s3 / 270 * 3.141592) * angle / 10) + x
  79. y4 = INT(COS(19 * s3 / 270 * 3.141592) * (angle / 10) / tilt) + y
  80.  
  81. 'Outer Planets
  82. 'Jupiter
  83. oldx5 = x5
  84. x5 = INT(SIN(s5 / 450 * 3.141592) * angle * 3) + 400
  85. y5 = INT(COS(s5 / 450 * 3.141592) * (angle * 3) / tilt) + 300
  86.  
  87. 'Saturn
  88. oldx6 = x6
  89. x6 = INT(SIN(s6 / 630 * 3.141592) * angle * 4.5) + 400
  90. y6 = INT(COS(s6 / 630 * 3.141592) * (angle * 4.5) / tilt) + 300
  91.  
  92. 'Uranus
  93. oldx7 = x7
  94. x7 = INT(SIN(s7 / 810 * 3.141592) * angle * 6) + 400
  95. y7 = INT(COS(s7 / 810 * 3.141592) * (angle * 6) / tilt) + 300
  96.  
  97. 'Neptune
  98. oldx8 = x8
  99. x8 = INT(SIN(s8 / 990 * 3.141592) * angle * 7.5) + 400
  100. y8 = INT(COS(s8 / 990 * 3.141592) * (angle * 7.5) / tilt) + 300
  101.  
  102.  
  103. 'Sun
  104. CIRCLE (400, 300), 2, _RGB32(249, 240, 22)
  105. PAINT (400, 300), _RGB32(249, 240, 22)
  106.  
  107. IF tilt > 6 THEN
  108.     IF x1 > oldx1 THEN z(1) = 1
  109.     IF x2 > oldx2 THEN z(2) = 1
  110.     IF x3 > oldx3 THEN z(3) = 1
  111.     IF x5 > oldx5 THEN z(4) = 1
  112.     IF x6 > oldx6 THEN z(5) = 1
  113.     IF x7 > oldx7 THEN z(6) = 1
  114.     IF x8 > oldx8 THEN z(7) = 1
  115.     IF x > oldx THEN z(8) = 1
  116.     IF x1 < oldx1 THEN z(1) = 0
  117.     IF x2 < oldx2 THEN z(2) = 0
  118.     IF x3 < oldx3 THEN z(3) = 0
  119.     IF x5 < oldx5 THEN z(4) = 0
  120.     IF x6 < oldx6 THEN z(5) = 0
  121.     IF x7 < oldx7 THEN z(6) = 0
  122.     IF x8 < oldx8 THEN z(7) = 0
  123.     IF x < oldx THEN z(8) = 0
  124.  
  125.     IF z(1) = 0 THEN
  126.         'Mercury
  127.         CIRCLE (x1, y1), 5, _RGB32(120, 98, 102)
  128.         PAINT (x1, y1), _RGB32(120, 98, 102)
  129.     END IF
  130.  
  131.     IF z(2) = 0 THEN
  132.         'Venus
  133.         CIRCLE (x2, y2), 5, _RGB32(161, 67, 39)
  134.         PAINT (x2, y2), _RGB32(161, 67, 39)
  135.     END IF
  136.  
  137.     IF z(8) = 0 THEN
  138.         'Earth
  139.         CIRCLE (x, y), 5, _RGB32(0, 0, 255)
  140.         PAINT (x, y), _RGB32(0, 0, 255)
  141.         'Moon
  142.         CIRCLE (x4, y4), 2.5, _RGB32(179, 179, 181)
  143.         PAINT (x4, y4), _RGB32(179, 179, 181)
  144.     END IF
  145.     IF z(3) = 0 THEN
  146.         'Mars
  147.         CIRCLE (x3, y3), 5, _RGB32(240, 72, 22)
  148.         PAINT (x3, y3), _RGB32(240, 72, 22)
  149.     END IF
  150.     IF z(4) = 0 THEN
  151.         'Outer Planets
  152.         'Jupiter
  153.         CIRCLE (x5, y5), 5, _RGB32(255, 166, 127)
  154.         PAINT (x5, y5), _RGB32(255, 166, 127)
  155.     END IF
  156.     IF z(5) = 0 THEN
  157.         'Saturn
  158.         CIRCLE (x6, y6), 5, _RGB32(255, 127, 127)
  159.         PAINT (x6, y6), _RGB32(255, 127, 127)
  160.         FOR rings = 1 TO 2
  161.             CIRCLE (x6, y6), 7 + rings, _RGB32(255, 127, 127), , , .65
  162.         NEXT rings
  163.     END IF
  164.     IF z(6) = 0 THEN
  165.         'Uranus
  166.         CIRCLE (x7, y7), 5, _RGB32(127, 166, 255)
  167.         PAINT (x7, y7), _RGB32(127, 166, 255)
  168.     END IF
  169.     IF z(7) = 0 THEN
  170.         'Neptune
  171.         CIRCLE (x8, y8), 5, _RGB32(0, 78, 255)
  172.         PAINT (x8, y8), _RGB32(0, 78, 255)
  173.     END IF
  174.  
  175.  
  176.     'Mercury
  177.     CIRCLE (x1, y1), 5, _RGB32(120, 98, 102)
  178.     PAINT (x1, y1), _RGB32(120, 98, 102)
  179.  
  180.     'Venus
  181.     CIRCLE (x2, y2), 5, _RGB32(161, 67, 39)
  182.     PAINT (x2, y2), _RGB32(161, 67, 39)
  183.  
  184.     'Earth
  185.     CIRCLE (x, y), 5, _RGB32(0, 0, 255)
  186.     PAINT (x, y), _RGB32(0, 0, 255)
  187.     'Moon
  188.     CIRCLE (x4, y4), 2.5, _RGB32(179, 179, 181)
  189.     PAINT (x4, y4), _RGB32(179, 179, 181)
  190.  
  191.     'Mars
  192.     CIRCLE (x3, y3), 5, _RGB32(240, 72, 22)
  193.     PAINT (x3, y3), _RGB32(240, 72, 22)
  194.  
  195.     'Outer Planets
  196.     'Jupiter
  197.     CIRCLE (x5, y5), 5, _RGB32(255, 166, 127)
  198.     PAINT (x5, y5), _RGB32(255, 166, 127)
  199.  
  200.     'Saturn
  201.     CIRCLE (x6, y6), 5, _RGB32(255, 127, 127)
  202.     PAINT (x6, y6), _RGB32(255, 127, 127)
  203.     FOR rings = 1 TO 2
  204.         CIRCLE (x6, y6), 7 + rings, _RGB32(255, 127, 127), , , .65
  205.     NEXT rings
  206.  
  207.     'Uranus
  208.     CIRCLE (x7, y7), 5, _RGB32(127, 166, 255)
  209.     PAINT (x7, y7), _RGB32(127, 166, 255)
  210.  
  211.     'Neptune
  212.     CIRCLE (x8, y8), 5, _RGB32(0, 78, 255)
  213.     PAINT (x8, y8), _RGB32(0, 78, 255)
  214.  
  215. IF seconds > 99999 THEN
  216.     CLS
  217.     seconds = 0
  218.     GOTO one:
  219. GOTO one:
  220.  
« Last Edit: August 19, 2019, 03:00:10 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Revolving Disks
« Reply #14 on: August 19, 2019, 02:59:36 am »
Here is a much nicer version. The planets stay appeared until right before they go behind the Sun. I also made Saturn look better. I was able to do this by adding some more info on the IF/THEN statements to see where the coordinates are exactly. I added this to the ones that see if the planets are going right or left so I know where they are headed. Check this one out. :)  Also, I didn't mean to hijack your thread here. I would make  my own thread but I already have this in 1 other thread as well lol.
Oh, and don't ask about the Moon orbit. I tried hiding that behind the Earth and couldn't do it. It's just barely noticeable anyway. :)

Code: QB64: [Select]
  1. 'Ken G. made thie program on August 18, 2019,
  2. 'Thank you to STxAxTIC on the QB64.org forum for a little bit of help with The Moon orbit!
  3.  
  4. _TITLE "Solar System Simulator by Ken G. Use Mouse Over Planets, Mouse Wheel to Zoom, and Up and Down Arrow Keys To Tilt."
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. DIM z(10)
  7. mercury = 0.241
  8. venus = 0.6152
  9. mars = 1.8809
  10. jupiter = 11.8618
  11. saturn = 29.457
  12. uranus = 84.0205
  13. neptune = 164.8
  14. angle = 180
  15. tilt = 1
  16. one:
  17. _LIMIT 500
  18. mouseWheel = 0
  19.     mouseX = _MOUSEX
  20.     mouseY = _MOUSEY
  21.     mouseLeftButton = _MOUSEBUTTON(1)
  22.     mouseRightButton = _MOUSEBUTTON(2)
  23.     mouseMiddleButton = _MOUSEBUTTON(3)
  24.     mouseWheel = mouseWheel + _MOUSEWHEEL
  25. IF mouseWheel < 0 THEN angle = angle - 10
  26. IF mouseWheel > 0 THEN angle = angle + 10
  27.  
  28. IF mouseX > 385 AND mouseX < 415 AND mouseY > 285 AND mouseY < 315 THEN LOCATE 2, 49: PRINT "Sun    "
  29. IF mouseX > x1 - 15 AND mouseX < x1 + 15 AND mouseY > y1 - 15 AND mouseY < y1 + 15 THEN LOCATE 2, 49: PRINT "Mercury"
  30. IF mouseX > x2 - 15 AND mouseX < x2 + 15 AND mouseY > y2 - 15 AND mouseY < y2 + 15 THEN LOCATE 2, 49: PRINT "Venus  "
  31. IF mouseX > x - 15 AND mouseX < x + 15 AND mouseY > y - 15 AND mouseY < y + 15 THEN LOCATE 2, 49: PRINT "Earth  "
  32. IF mouseX > x3 - 15 AND mouseX < x3 + 15 AND mouseY > y3 - 15 AND mouseY < y3 + 15 THEN LOCATE 2, 49: PRINT "Mars   "
  33. IF mouseX > x5 - 15 AND mouseX < x5 + 15 AND mouseY > y5 - 15 AND mouseY < y5 + 15 THEN LOCATE 2, 49: PRINT "Jupiter"
  34. IF mouseX > x6 - 15 AND mouseX < x6 + 15 AND mouseY > y6 - 15 AND mouseY < y6 + 15 THEN LOCATE 2, 49: PRINT "Saturn "
  35. IF mouseX > x7 - 15 AND mouseX < x7 + 15 AND mouseY > y7 - 15 AND mouseY < y7 + 15 THEN LOCATE 2, 49: PRINT "Uranus "
  36. IF mouseX > x8 - 15 AND mouseX < x8 + 15 AND mouseY > y8 - 15 AND mouseY < y8 + 15 THEN LOCATE 2, 49: PRINT "Neptune"
  37.  
  38. a$ = INKEY$
  39. IF a$ = CHR$(27) THEN END
  40. IF a$ = CHR$(0) + CHR$(72) THEN tilt = tilt + 1
  41. IF a$ = CHR$(0) + CHR$(80) THEN tilt = tilt - 1
  42. IF angle > 360 THEN angle = 360
  43. IF angle < 10 THEN angle = 10
  44. IF tilt > 50 THEN tilt = 50
  45. IF tilt < 1 THEN tilt = 1
  46. seconds = seconds + .01
  47. s1 = (60 - seconds) * 6 + 180 / mercury
  48. s2 = (60 - seconds) * 6 + 180 / venus
  49. s3 = (60 - seconds) * 6 + 180 'Earth and Moon
  50. s4 = (60 - seconds) * 6 + 180 / mars
  51. s5 = (60 - seconds) * 6 + 180 / jupiter
  52. s6 = (60 - seconds) * 6 + 180 / saturn
  53. s7 = (60 - seconds) * 6 + 180 / uranus
  54. s8 = (60 - seconds) * 6 + 180 / neptune
  55.  
  56.  
  57. 'Mercury
  58. oldx1 = x1
  59. x1 = INT(SIN(s1 / 45 * 3.141592) * angle / 4) + 400
  60. y1 = INT(COS(s1 / 45 * 3.141592) * (angle / 4) / tilt) + 300
  61.  
  62. 'Venus
  63. oldx2 = x2
  64. x2 = INT(SIN(s2 / 90 * 3.141592) * angle / 2) + 400
  65. y2 = INT(COS(s2 / 90 * 3.141592) * (angle / 2) / tilt) + 300
  66.  
  67. 'Earth
  68. oldx = x
  69. x = INT(SIN(s3 / 180 * 3.141592) * angle) + 400
  70. y = INT(COS(s3 / 180 * 3.141592) * angle / tilt) + 300
  71.  
  72. 'Mars
  73. oldx3 = x3
  74. x3 = INT(SIN(s4 / 270 * 3.141592) * angle * 1.5) + 400
  75. y3 = INT(COS(s4 / 270 * 3.141592) * (angle * 1.5) / tilt) + 300
  76.  
  77. 'Moon
  78. x4 = INT(SIN(19 * s3 / 270 * 3.141592) * angle / 10) + x
  79. y4 = INT(COS(19 * s3 / 270 * 3.141592) * (angle / 10) / tilt) + y
  80.  
  81. 'Outer Planets
  82. 'Jupiter
  83. oldx5 = x5
  84. x5 = INT(SIN(s5 / 450 * 3.141592) * angle * 3) + 400
  85. y5 = INT(COS(s5 / 450 * 3.141592) * (angle * 3) / tilt) + 300
  86.  
  87. 'Saturn
  88. oldx6 = x6
  89. x6 = INT(SIN(s6 / 630 * 3.141592) * angle * 4.5) + 400
  90. y6 = INT(COS(s6 / 630 * 3.141592) * (angle * 4.5) / tilt) + 300
  91.  
  92. 'Uranus
  93. oldx7 = x7
  94. x7 = INT(SIN(s7 / 810 * 3.141592) * angle * 6) + 400
  95. y7 = INT(COS(s7 / 810 * 3.141592) * (angle * 6) / tilt) + 300
  96.  
  97. 'Neptune
  98. oldx8 = x8
  99. x8 = INT(SIN(s8 / 990 * 3.141592) * angle * 7.5) + 400
  100. y8 = INT(COS(s8 / 990 * 3.141592) * (angle * 7.5) / tilt) + 300
  101.  
  102.  
  103. 'Sun
  104. CIRCLE (400, 300), 5, _RGB32(249, 240, 22)
  105. PAINT (400, 300), _RGB32(249, 240, 22)
  106.  
  107. IF tilt > 6 THEN
  108.     IF x1 > oldx1 AND x1 > 375 AND x1 < 425 THEN z(1) = 1
  109.     IF x2 > oldx2 AND x2 > 375 AND x2 < 425 THEN z(2) = 1
  110.     IF x3 > oldx3 AND x3 > 375 AND x3 < 425 THEN z(3) = 1
  111.     IF x5 > oldx5 AND x5 > 375 AND x5 < 425 THEN z(4) = 1
  112.     IF x6 > oldx6 AND x6 > 375 AND x6 < 425 THEN z(5) = 1
  113.     IF x7 > oldx7 AND x7 > 375 AND x7 < 425 THEN z(6) = 1
  114.     IF x8 > oldx8 AND x8 > 375 AND x8 < 425 THEN z(7) = 1
  115.     IF x > oldx AND x > 375 AND x < 425 THEN z(8) = 1
  116.  
  117.     IF x1 > oldx1 AND x1 > 424 THEN z(1) = 0
  118.     IF x2 > oldx2 AND x2 > 424 THEN z(2) = 0
  119.     IF x3 > oldx3 AND x3 > 424 THEN z(3) = 0
  120.     IF x5 > oldx5 AND x5 > 424 THEN z(4) = 0
  121.     IF x6 > oldx6 AND x6 > 424 THEN z(5) = 0
  122.     IF x7 > oldx7 AND x7 > 424 THEN z(6) = 0
  123.     IF x8 > oldx8 AND x8 > 424 THEN z(7) = 0
  124.     IF x > oldx AND x > 424 THEN z(8) = 0
  125.  
  126.  
  127.     IF x1 < oldx1 THEN z(1) = 0
  128.     IF x2 < oldx2 THEN z(2) = 0
  129.     IF x3 < oldx3 THEN z(3) = 0
  130.     IF x5 < oldx5 THEN z(4) = 0
  131.     IF x6 < oldx6 THEN z(5) = 0
  132.     IF x7 < oldx7 THEN z(6) = 0
  133.     IF x8 < oldx8 THEN z(7) = 0
  134.     IF x < oldx THEN z(8) = 0
  135.  
  136.     IF z(1) = 0 THEN
  137.         'Mercury
  138.         CIRCLE (x1, y1), 5, _RGB32(120, 98, 102)
  139.         PAINT (x1, y1), _RGB32(120, 98, 102)
  140.     END IF
  141.  
  142.     IF z(2) = 0 THEN
  143.         'Venus
  144.         CIRCLE (x2, y2), 5, _RGB32(161, 67, 39)
  145.         PAINT (x2, y2), _RGB32(161, 67, 39)
  146.     END IF
  147.  
  148.     IF z(8) = 0 THEN
  149.         'Earth
  150.         CIRCLE (x, y), 5, _RGB32(0, 0, 255)
  151.         PAINT (x, y), _RGB32(0, 0, 255)
  152.         'Moon
  153.         CIRCLE (x4, y4), 2.5, _RGB32(179, 179, 181)
  154.         PAINT (x4, y4), _RGB32(179, 179, 181)
  155.     END IF
  156.     IF z(3) = 0 THEN
  157.         'Mars
  158.         CIRCLE (x3, y3), 5, _RGB32(240, 72, 22)
  159.         PAINT (x3, y3), _RGB32(240, 72, 22)
  160.     END IF
  161.     IF z(4) = 0 THEN
  162.         'Outer Planets
  163.         'Jupiter
  164.         CIRCLE (x5, y5), 5, _RGB32(255, 166, 127)
  165.         PAINT (x5, y5), _RGB32(255, 166, 127)
  166.     END IF
  167.     IF z(5) = 0 THEN
  168.         'Saturn
  169.         CIRCLE (x6, y6), 5, _RGB32(255, 127, 127)
  170.         PAINT (x6, y6), _RGB32(255, 127, 127)
  171.         FOR rings = 4 TO 5
  172.             CIRCLE (x6, y6), 7 + rings, _RGB32(255, 127, 127), , , .2
  173.         NEXT rings
  174.     END IF
  175.     IF z(6) = 0 THEN
  176.         'Uranus
  177.         CIRCLE (x7, y7), 5, _RGB32(127, 166, 255)
  178.         PAINT (x7, y7), _RGB32(127, 166, 255)
  179.     END IF
  180.     IF z(7) = 0 THEN
  181.         'Neptune
  182.         CIRCLE (x8, y8), 5, _RGB32(0, 78, 255)
  183.         PAINT (x8, y8), _RGB32(0, 78, 255)
  184.     END IF
  185.  
  186.  
  187.     'Mercury
  188.     CIRCLE (x1, y1), 5, _RGB32(120, 98, 102)
  189.     PAINT (x1, y1), _RGB32(120, 98, 102)
  190.  
  191.     'Venus
  192.     CIRCLE (x2, y2), 5, _RGB32(161, 67, 39)
  193.     PAINT (x2, y2), _RGB32(161, 67, 39)
  194.  
  195.     'Earth
  196.     CIRCLE (x, y), 5, _RGB32(0, 0, 255)
  197.     PAINT (x, y), _RGB32(0, 0, 255)
  198.     'Moon
  199.     CIRCLE (x4, y4), 2.5, _RGB32(179, 179, 181)
  200.     PAINT (x4, y4), _RGB32(179, 179, 181)
  201.  
  202.     'Mars
  203.     CIRCLE (x3, y3), 5, _RGB32(240, 72, 22)
  204.     PAINT (x3, y3), _RGB32(240, 72, 22)
  205.  
  206.     'Outer Planets
  207.     'Jupiter
  208.     CIRCLE (x5, y5), 5, _RGB32(255, 166, 127)
  209.     PAINT (x5, y5), _RGB32(255, 166, 127)
  210.  
  211.     'Saturn
  212.     CIRCLE (x6, y6), 5, _RGB32(255, 127, 127)
  213.     PAINT (x6, y6), _RGB32(255, 127, 127)
  214.     FOR rings = 1 TO 2
  215.         CIRCLE (x6, y6), 7 + rings, _RGB32(255, 127, 127), , , .65
  216.     NEXT rings
  217.  
  218.     'Uranus
  219.     CIRCLE (x7, y7), 5, _RGB32(127, 166, 255)
  220.     PAINT (x7, y7), _RGB32(127, 166, 255)
  221.  
  222.     'Neptune
  223.     CIRCLE (x8, y8), 5, _RGB32(0, 78, 255)
  224.     PAINT (x8, y8), _RGB32(0, 78, 255)
  225.  
  226. IF seconds > 99999 THEN
  227.     CLS
  228.     seconds = 0
  229.     GOTO one:
  230. GOTO one:
  231.  
  232.  
« Last Edit: August 19, 2019, 03:17:17 am by SierraKen »