Author Topic: Solar System Screensaver  (Read 1132 times)

0 Members and 1 Guest are viewing this topic.

Offline CloudZimmermann

  • Newbie
  • Posts: 4
    • View Profile
Solar System Screensaver
« on: May 13, 2020, 10:56:54 am »
Program: Solar System Screensaver
Creator:  Cloud Zimmermann
Date:      1/13/2018

Code: QB64: [Select]
  1. 'Program: Solar System Screensaver
  2. 'Creator:  Cloud Zimmermann
  3. 'Date:      1/13/2018
  4.  
  5. RANDOMIZE TIMER 'set the seed of the randomizer to the current number of seconds since midnight
  6. SCREEN 7, 1, 0, 1 'use screen 7 mode (320x200 @256 colors with 7 pages of memory), use color mode, set memory page as 0 for drawing, and set memory page 1 as the selected
  7.  
  8. CONST SCREEN_WIDTH = 320
  9. CONST SCREEN_HEIGHT = 200
  10.  
  11. CONST sphere_count = 4
  12. CONST star_count = 100
  13.  
  14. DIM angle AS SINGLE
  15.  
  16. ' data type for all spheres (suns, planets, gas giants, moons, satellites, ect)
  17. TYPE sphere
  18.     cordinateX AS SINGLE 'x
  19.     cordinateY AS SINGLE 'y
  20.     cordinateZ AS SINGLE 'z
  21.     radius AS INTEGER 'radius of circle
  22.     color AS INTEGER '0 to 16
  23.     rotation_offset AS SINGLE 'saved as degrees
  24.     parent AS INTEGER ' relationship
  25.     direction AS INTEGER ' clockwise or counter-clockwise
  26.     angular_velocity AS SINGLE ' allow for different rotation speeds
  27. DIM spheres(sphere_count) AS sphere
  28.  
  29. 'sample data
  30. spheres(0).radius = 5
  31. spheres(0).parent = -1
  32. spheres(0).direction = 1
  33. spheres(0).color = 11
  34. spheres(0).angular_velocity = .25
  35.  
  36. spheres(1).radius = 2
  37. spheres(1).parent = 0
  38. spheres(1).direction = 1
  39. spheres(1).color = 12
  40. spheres(1).angular_velocity = 4
  41.  
  42. spheres(2).radius = 3.3
  43. spheres(2).parent = -1
  44. spheres(2).rotation_offset = 60
  45. spheres(2).direction = 1
  46. spheres(2).color = 13
  47. spheres(2).angular_velocity = 1
  48.  
  49.  
  50. spheres(3).radius = 4
  51. spheres(3).parent = -1
  52. spheres(3).rotation_offset = 180
  53. spheres(3).direction = -1
  54. spheres(3).color = 14
  55. spheres(3).angular_velocity = 2
  56.  
  57.  
  58. spheres(4).radius = 6
  59. spheres(4).parent = -1
  60. spheres(4).rotation_offset = -300
  61. spheres(4).direction = 1
  62. spheres(4).color = 6
  63. spheres(4).angular_velocity = 1.3
  64.  
  65. TYPE star
  66.     x AS INTEGER
  67.     y AS INTEGER
  68.     c AS INTEGER
  69. DIM stars(star_count) AS star
  70.  
  71. FOR i% = 0 TO star_count
  72.     stars(i%).x = (RND * 320) + 1
  73.     stars(i%).y = (RND * 200) + 1
  74.     stars(i%).c = (RND * 1) + 7
  75. NEXT i%
  76.  
  77.  
  78. ' main loop
  79.     ' draw background
  80.     FOR i% = 0 TO star_count
  81.         PSET (stars(i%).x, stars(i%).y), stars(i%).c
  82.     NEXT i%
  83.  
  84.     COLOR 15 'set color as WHITE for text/graphics
  85.     LOCATE 3, 17 'set text cursor to x,y
  86.     PRINT TIME$ ' print the current time
  87.  
  88.     'LOCATE 5, 17
  89.     'PRINT angle
  90.  
  91.     ' draw the sun
  92.     COLOR 14
  93.     CIRCLE (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2), 10, , , , 1
  94.     PAINT STEP(0, 0), 14, 14
  95.  
  96.     ' update the global rotation angle
  97.     angle = angle + 0.01
  98.     IF angle > 360 THEN angle = 0
  99.  
  100.     FOR i% = 0 TO sphere_count
  101.  
  102.         ' does this sphere have a parent?
  103.         IF spheres(i%).parent <> -1 THEN
  104.  
  105.             ' draw path of the orbit near the parent
  106.             COLOR 2 '0 is black, 2 is green, 7 is light gray, 8 is dark gray, 15 is white
  107.             CIRCLE (spheres(spheres(i%).parent).cordinateX, spheres(spheres(i%).parent).cordinateY), 8 * spheres(i%).radius, , , , 1 ' draw circle(x,y),radius,,,,aspect ratio
  108.  
  109.             ' calculate the position of the sphere near the parent
  110.             x = (spheres(spheres(i%).parent).cordinateX) + (COS(angle * spheres(i%).angular_velocity + spheres(i%).rotation_offset) * (8 * spheres(i%).radius))
  111.             y = (spheres(spheres(i%).parent).cordinateY) + (SIN(angle * spheres(i%).angular_velocity + spheres(i%).rotation_offset) * (8 * spheres(i%).radius))
  112.             r = spheres(i%).radius
  113.  
  114.         ELSE
  115.  
  116.             ' draw path of orbit
  117.             'COLOR INT(RND * 6) + 1 ' change the color from 1 to 6 (out of 16 possible)
  118.             COLOR 2
  119.             CIRCLE (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2), SCREEN_HEIGHT / spheres(i%).radius, , , , 1 ' draw circle(x,y),radius,,,,aspect ratio
  120.  
  121.             ' calculate the position of the sphere
  122.             x = (SCREEN_WIDTH / 2) + (COS(spheres(i%).direction * angle * spheres(i%).angular_velocity + spheres(i%).rotation_offset) * (SCREEN_HEIGHT / spheres(i%).radius))
  123.             y = (SCREEN_HEIGHT / 2) + (SIN(spheres(i%).direction * angle * spheres(i%).angular_velocity + spheres(i%).rotation_offset) * (SCREEN_HEIGHT / spheres(i%).radius))
  124.             r = spheres(i%).radius
  125.         END IF
  126.  
  127.         ' save the position of the sphere (for the children)
  128.         spheres(i%).cordinateX = x
  129.         spheres(i%).cordinateY = y
  130.  
  131.         ' draw sphere
  132.         COLOR spheres(i%).color '11 '10
  133.         CIRCLE (x, y), r, , , , 1
  134.         PAINT STEP(0, 0), spheres(i%).color, spheres(i%).color
  135.  
  136.     NEXT i%
  137.  
  138.  
  139.     PCOPY 0, 1 'copy/flip the video memory page from 0 to 1 (so we can see what we have drawn without watching the drawing itself)
  140.     CLS
  141.     _LIMIT (60) 'qb64: limit to 60 loops per second
  142.  
  143.  
* solar-system.exe (Filesize: 1.4 MB, Downloads: 167)
* solar-system.bas (Filesize: 4.65 KB, Downloads: 118)
« Last Edit: May 16, 2020, 04:35:17 pm by CloudZimmermann »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Solar System Screensaver
« Reply #1 on: May 13, 2020, 02:08:27 pm »
Welcome to the forum CloudZimmermann,

Nice work!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Solar System Screensaver
« Reply #2 on: May 13, 2020, 04:31:40 pm »
Pretty cool CloudZimmerman! Welcome to the forum!

If you don't know already, QB64 lets you make a graphics window as large as you want. I usually use 800 x 600. To use it, use this command:
SCREEN _NEWIMAGE(800,600,32)

That makes a 32 bit screen on 800 x 600 pixels. The colors for 32 bit are enormous. For example you can do this for the LINE command:
LINE (50,50)-(200,200),_RGB32(255,0,0),BF
255 is the maximum amount of red you can use, it's RED, GREEN, BLUE. For complete white it's 255,255,255 and for complete black it's 0,0,0.
Anyway, you might know all this already so I'll end there. Happy programming!

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Solar System Screensaver
« Reply #3 on: May 14, 2020, 01:11:48 am »
Good Job @CloudZimmermann . Welcome to the forum! :D
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 johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Solar System Screensaver
« Reply #4 on: May 14, 2020, 04:38:53 am »
What? No aliens!! Nah. Kidding. Good job! ... and Welcome!
Logic is the beginning of wisdom.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Solar System Screensaver
« Reply #5 on: May 16, 2020, 02:13:53 am »
Pretty, but scary.  May cause independent eye motion.

Why is one "planet" retrograde?  Is that a really big spaceship?
It works better if you plug it in.

Offline 40wattstudio

  • Newbie
  • Posts: 82
    • View Profile
    • 40wattstudio
Re: Solar System Screensaver
« Reply #6 on: May 16, 2020, 09:12:48 am »
Good job CloudZimmermann! Thanks especially for making this available in .exe, I think it's much more convenient that way.
If you want to make this with better graphics maybe give the NASA textures a try and use some _PUTIMAGE statements. https://nasa3d.arc.nasa.gov/images