Program: Solar System Screensaver
Creator: Cloud Zimmermann
Date: 1/13/2018
'Program: Solar System Screensaver
'Creator: Cloud Zimmermann
'Date: 1/13/2018
RANDOMIZE TIMER 'set the seed of the randomizer to the current number of seconds since midnight 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
CONST SCREEN_HEIGHT
= 200
' data type for all spheres (suns, planets, gas giants, moons, satellites, ect)
rotation_offset
AS SINGLE 'saved as degrees direction
AS INTEGER ' clockwise or counter-clockwise angular_velocity
AS SINGLE ' allow for different rotation speedsDIM spheres
(sphere_count
) AS sphere
'sample data
spheres(0).radius = 5
spheres(0).parent = -1
spheres(0).direction = 1
spheres(0).angular_velocity = .25
spheres(1).radius = 2
spheres(1).parent = 0
spheres(1).direction = 1
spheres(1).angular_velocity = 4
spheres(2).radius = 3.3
spheres(2).parent = -1
spheres(2).rotation_offset = 60
spheres(2).direction = 1
spheres(2).angular_velocity = 1
spheres(3).radius = 4
spheres(3).parent = -1
spheres(3).rotation_offset = 180
spheres(3).direction = -1
spheres(3).angular_velocity = 2
spheres(4).radius = 6
spheres(4).parent = -1
spheres(4).rotation_offset = -300
spheres(4).direction = 1
spheres(4).angular_velocity = 1.3
DIM stars
(star_count
) AS star
stars
(i%
).x
= (RND * 320) + 1 stars
(i%
).y
= (RND * 200) + 1 stars
(i%
).c
= (RND * 1) + 7
' main loop
' draw background
PSET (stars
(i%
).x
, stars
(i%
).y
), stars
(i%
).c
COLOR 15 'set color as WHITE for text/graphics LOCATE 3, 17 'set text cursor to x,y
'LOCATE 5, 17
'PRINT angle
' draw the sun
CIRCLE (SCREEN_WIDTH
/ 2, SCREEN_HEIGHT
/ 2), 10, , , , 1
' update the global rotation angle
angle = angle + 0.01
FOR i%
= 0 TO sphere_count
' does this sphere have a parent?
IF spheres
(i%
).parent
<> -1 THEN
' draw path of the orbit near the parent
COLOR 2 '0 is black, 2 is green, 7 is light gray, 8 is dark gray, 15 is white CIRCLE (spheres
(spheres
(i%
).parent
).cordinateX
, spheres
(spheres
(i%
).parent
).cordinateY
), 8 * spheres
(i%
).radius
, , , , 1 ' draw circle(x,y),radius,,,,aspect ratio
' calculate the position of the sphere near the parent
x
= (spheres
(spheres
(i%
).parent
).cordinateX
) + (COS(angle
* spheres
(i%
).angular_velocity
+ spheres
(i%
).rotation_offset
) * (8 * spheres
(i%
).radius
)) y
= (spheres
(spheres
(i%
).parent
).cordinateY
) + (SIN(angle
* spheres
(i%
).angular_velocity
+ spheres
(i%
).rotation_offset
) * (8 * spheres
(i%
).radius
)) r = spheres(i%).radius
' draw path of orbit
'COLOR INT(RND * 6) + 1 ' change the color from 1 to 6 (out of 16 possible)
CIRCLE (SCREEN_WIDTH
/ 2, SCREEN_HEIGHT
/ 2), SCREEN_HEIGHT
/ spheres
(i%
).radius
, , , , 1 ' draw circle(x,y),radius,,,,aspect ratio
' calculate the position of the sphere
x
= (SCREEN_WIDTH
/ 2) + (COS(spheres
(i%
).direction
* angle
* spheres
(i%
).angular_velocity
+ spheres
(i%
).rotation_offset
) * (SCREEN_HEIGHT
/ spheres
(i%
).radius
)) y
= (SCREEN_HEIGHT
/ 2) + (SIN(spheres
(i%
).direction
* angle
* spheres
(i%
).angular_velocity
+ spheres
(i%
).rotation_offset
) * (SCREEN_HEIGHT
/ spheres
(i%
).radius
)) r = spheres(i%).radius
' save the position of the sphere (for the children)
spheres(i%).cordinateX = x
spheres(i%).cordinateY = y
' draw sphere
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) _LIMIT (60) 'qb64: limit to 60 loops per second