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

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D Revolving Disks
« Reply #15 on: August 19, 2019, 10:27:00 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.  

Hi Ken,

Not hijacking if working towards goal of presenting Solar System in 3D, I had same thought!

Nope, what I am deeply, deeply saddened by is that you aren't using the handy dandy FillCircle routine I worked up for you, you could cut your program lines in half (almost):
Code: QB64: [Select]
  1. SUB CircleFill (centerX, centerY, circleRadius, circleColor AS _UNSIGNED LONG)
  2.     FOR changeRadius = .25 TO circleRadius STEP .25
  3.         CIRCLE (centerX, centerY), changeRadius, circleColor
  4.     NEXT
Maybe I should have named it SUB KensCircleFill(x, y, r, Kolor as _unsigned long)

...wait is that the problem? Kolor as _UNSIGNED LONG ?

That's THE TYPE to use for Color variables in a graphics screen, it allows _RGB32() colors and &HAARRGGBB (< fix thanks Steve) colors and once you get to using alpha = transparencies you will never look back! :))

You use the SUB just like you use CIRCLE, only you don't put x, y in (),
KensFillCircle x, y, r, _RGB32(255, 0, 0)

BTW, never change anything inside the SUB, change the variables used in the call to the SUB
KensFillCircle x, y, r, Colr    '<  change any variable or number here in main code.

another example of a "call" to use the sub
'drawMars
KensFillCircle marsX, marsY, marsRadius, _RGB32(255, 0, 0) ' < Mars color

and you could really, really cut your program lines down by using a planetary array or arrays, so I don't have to read mindless repetition of code, but we can only change things one step at a time... :)

« Last Edit: August 19, 2019, 11:18:58 am by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 3D Revolving Disks
« Reply #16 on: August 19, 2019, 10:41:42 am »
Quick typo fix for Bplus: &HAARRGGBB colors.  Alpha, Red, Green, Blue.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D Revolving Disks
« Reply #17 on: August 19, 2019, 10:55:04 am »
Oops! Thanks Steve, I will fix.

Yeah remember what the pirates say! "AARRGGBB matey, use that dang CircleFill!" ;-))
« Last Edit: August 19, 2019, 10:58:10 am by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 3D Revolving Disks
« Reply #18 on: August 19, 2019, 11:01:12 am »
Oops! Thanks Steve, I will fix.

No worries.  32-bit colors are tricky beasts.  Their values are &HAARRGGBB, we use the _RGBA command to set them usually, and they’re actually stored in memory as BBGGRRAA... 

And folks say programmers are supposed to be very logical... 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Revolving Disks
« Reply #19 on: August 19, 2019, 01:04:09 pm »
Wow... well thanks B+, but there's a couple things you should know. First, I'm sure you guys have heard on here from people saying "It's hard to teach old dogs new tricks." Second, that tied together with my head injury problems, like very bad memory, often times I just forget things to use with programming. I know all of this can be fixed by lots of practice. SUB's are still a tiny bit in the gray area to me. I know what they are, like little programs within programs, etc. But I think one big reason I didn't even use GOSUBs in any of the code on this program is because each and every variable is different. Every planet is using different numbers at different locations with different colors. I'm not sure how I could make an array when everything is using different numbers at one time. And really, I think 2 different variables use the same memory has 1 array of 2 different numbers. Of course, you know tons more about it than I do so the way you program would have been much shorter I'm sure. But I'm still proud that this program only goes to line 237 with a lot of empty lines. :)

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: 3D Revolving Disks
« Reply #20 on: August 19, 2019, 01:34:45 pm »
Every planet is using different numbers at different locations with different colors. I'm not sure how I could make an array when everything is using different numbers at one time. And really, I think 2 different variables use the same memory has 1 array of 2 different numbers.

This is where learning the use of TYPE declarations shows its stuff.

Code: QB64: [Select]
  1. TYPE planet
  2.     n AS STRING * 10 '    planets name
  3.     x AS INTEGER '          cartesian positions x, y & z
  4.     y AS INTEGER
  5.     z AS INTEGER
  6.     rad AS INTEGER '     planets radius
  7.     oprd AS INTEGER '       planets orbital period
  8.     orad AS INTEGER '       planets orbital radius
  9.     r AS INTEGER '             red component of planet color
  10.     g AS INTEGER '            green   "      "     "      "     "
  11.     b AS INTEGER '            blue     "     "      "      "      "
  12.     ' and anything else you need or want to add, calling it whatever
  13.     ' you want so long as it doesn't conflict with reserved words.
  14.  
  15. DIM P(10) AS planet '       dimension planet type as a 10 element array
  16.  

Then all you have to do to reference any variable for a particular planet is to call on the particular element in the user type array.

e.g. planet 5's orbital period would be P(5).oprd, it's position in X would be P(5).x, etc.

call the planets color by _RGB32(P(5).r, P(5).g, P(5).b)

Iterations of multiple planets becomes compact and simple.
« Last Edit: August 19, 2019, 01:55:13 pm by OldMoses »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 3D Revolving Disks
« Reply #21 on: August 19, 2019, 01:52:58 pm »
Wow... well thanks B+, but there's a couple things you should know. First, I'm sure you guys have heard on here from people saying "It's hard to teach old dogs new tricks." Second, that tied together with my head injury problems, like very bad memory, often times I just forget things to use with programming. I know all of this can be fixed by lots of practice. SUB's are still a tiny bit in the gray area to me. I know what they are, like little programs within programs, etc. But I think one big reason I didn't even use GOSUBs in any of the code on this program is because each and every variable is different. Every planet is using different numbers at different locations with different colors. I'm not sure how I could make an array when everything is using different numbers at one time. And really, I think 2 different variables use the same memory has 1 array of 2 different numbers. Of course, you know tons more about it than I do so the way you program would have been much shorter I'm sure. But I'm still proud that this program only goes to line 237 with a lot of empty lines. :)

Hi Ken,

Oh wow, you didn't use any GOSUB (not that that is so bad). Sorry if I keep pressing you to try a SUB, you show so much enthusiasm and ingenuity, I am hoping to get you to power it up. Look how you worked in tilt!!!

Using your own CircleFill Sub is as easy as using CIRCLE built in, except for the () around X, Y it is the same way to use and you have to Copy / Paste the subroutine to the bottom of your code (keeping it outside you main code program). Oh, color is not optional, you have to say a color, you have to say all 4 things x, y, radius, color


OK I will cease and desist now. ;-)) Thanks for your patience.
« Last Edit: August 19, 2019, 02:01:48 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: 3D Revolving Disks
« Reply #22 on: August 20, 2019, 12:13:40 am »
LOL Thanks B+! QB64 turned my life around a LOT a couple months ago and still does. I've been a BASIC programmer off and on all my life. Even started to program in the 7th grade around 1985 or so on Apple 2c computers in the school lab with something called LOGO. You told the computer where to move the "Turtle" and he drew lines for what numbers you gave him. lol But as for nowadays, I've had too much time on my hands (I'm disabled and don't work) and I've wanted something like this to come back again. I would have used QB64 many years ago if I knew it existed LOL. But I guess it was for a reason :). That's one thing about life, never completely give up because someday something like this can come along. And I thank all of you guys for helping me fulfill this dream I've had since the 90's.