I'm not finished yet, but I have a working demo and thought I'd post it now just in case I don't have time later tonight.
up/down arrow keys to zoom in/out
left/right arrow keys to speed up the years passed
mouse wheel zooms in/out but at smaller interval
hold right-mouse button to drag screen
// Project: solar system
// Created: 2016-11-03
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "solar system" )
SetWindowSize(1280, 720, 0 )
// set display properties
SetVirtualResolution(1920,1080)
#CONSTANT AU = 149597887
#CONSTANT SUN = 0
#CONSTANT MERCURY = 1
#CONSTANT VENUS = 2
#CONSTANT EARTH = 3
#CONSTANT MARS = 4
#CONSTANT JUPITER = 5
#CONSTANT SATURN = 6
#CONSTANT URANUS = 7
#CONSTANT NEPTUNE = 8
#CONSTANT PLUTO = 9
Type Star
x as integer
y as integer
EndType
Type Planet
name as string
diameter as float
perihelion as float : ` closest distance from sun in KM
aphelion as float : ` farthest distance from sun in KM
perAU as float : ` perihelion in AU
aphAU as float : ` aphelion in AU
diaAU as float : ` diameter in AU
x as float : ` x position of planet in simulation
y as float : ` y position of planet in simulation
ecc as float : ` orbital eccentricity (for calculating minor-axis)
color as integer
rev as float : ` earth years to make 1 revolution
rot as float : ` period of rotation in earth days
temp as integer : ` mean temperature
mass as string : ` mass in kg
EndType
Global planets as Planet[10]
planets[SUN].name = "Sun"
planets[SUN].diameter = 109
planets[SUN].diaAU = 0.009305
planets[SUN].rot = 24.47
planets[SUN].temp = 5777
planets[SUN].mass = "1.989 × 10^30"
planets[MERCURY].name = "Mercury"
planets[MERCURY].diameter = 0.38
planets[MERCURY].perihelion = 46001210
planets[MERCURY].aphelion = 69816927
planets[MERCURY].perAU = 0.307499062
planets[MERCURY].aphAU = 0.46669728
planets[MERCURY].diaAU = 0.000032
planets[MERCURY].ecc = 0.79469706
planets[MERCURY].rev = 0.24081476
planets[MERCURY].rot = 58.7
planets[MERCURY].temp = 452
planets[MERCURY].mass = "3.3 x 10^23"
planets[MERCURY].color = makeColor(216,204,102)
planets[VENUS].name = "Venus"
planets[VENUS].diameter = 0.95
planets[VENUS].perihelion = 107476259
planets[VENUS].aphelion = 108942109
planets[VENUS].perAU = 0.718434339
planets[VENUS].aphAU = 0.72823294
planets[VENUS].diaAU = 0.000081
planets[VENUS].ecc = 0.9932
planets[VENUS].rev = 0.61512347
planets[VENUS].rot = 243
planets[VENUS].temp = 726
planets[VENUS].mass = "4.87 x 10^24"
planets[VENUS].color = makeColor(219,221,169)
planets[EARTH].name = "Earth"
planets[EARTH].diameter = 1
planets[EARTH].perihelion = 147098074
planets[EARTH].aphelion = 152097701
planets[EARTH].perAU = 0.983289784
planets[EARTH].aphAU = 1.016710223
planets[EARTH].diaAU = 0.000085
planets[EARTH].ecc = 0.983289781
planets[EARTH].rev = 1
planets[EARTH].rot = 1
planets[EARTH].temp = 285
planets[EARTH].mass = "5.98 x 10^24"
planets[EARTH].color = makeColor(0,0,255)
planets[MARS].name = "Mars"
planets[MARS].diameter = 0.53
planets[MARS].perihelion = 206644545
planets[MARS].aphelion = 249228730
planets[MARS].perAU = 1.381333314
planets[MARS].aphAU = 1.665990978
planets[MARS].diaAU = 0.000045
planets[MARS].ecc = 0.90658767
planets[MARS].rev = 1.880797240321962
planets[MARS].rot = 1.026
planets[MARS].temp = 230
planets[MARS].mass = "6.42 x 10^23"
planets[MARS].color = makeColor(244,80,30)
planets[JUPITER].name = "Jupiter"
planets[JUPITER].diameter = 11
planets[JUPITER].perihelion = 777909012.4
planets[JUPITER].aphelion = 816259276.8
planets[JUPITER].perAU = 5.2
planets[JUPITER].aphAU = 5.456355656
planets[JUPITER].diaAU = 0.000954
planets[JUPITER].ecc = 0.952
planets[JUPITER].rev = 11.862
planets[JUPITER].rot = 0.41
planets[JUPITER].temp = 120
planets[JUPITER].mass = "1.90 x 10^27"
planets[JUPITER].color = makeColor(204,137,8)
planets[SATURN].name = "Saturn"
planets[SATURN].diameter = 9.4
planets[SATURN].perihelion = 1421179926.5
planets[SATURN].aphelion = 1506667852.8
planets[SATURN].perAU = 9.5
planets[SATURN].aphAU = 10.07145143
planets[SATURN].diaAU = 0.000806
planets[SATURN].ecc = 0.946
planets[SATURN].rev = 29.456
planets[SATURN].rot = 0.425
planets[SATURN].temp = 88
planets[SATURN].mass = "5.69 x 10^26"
planets[SATURN].color = makeColor(165,149,118)
planets[URANUS].name = "Uranus"
planets[URANUS].diameter = 4
planets[URANUS].perihelion = 2872279430.4
planets[URANUS].aphelion = 3006254592
planets[URANUS].perAU = 19.2
planets[URANUS].aphAU = 20.09556854
planets[URANUS].diaAU = 0.000346
planets[URANUS].ecc = 0.953
planets[URANUS].rev = 84.07
planets[URANUS].rot = 0.7458
planets[URANUS].temp = 59
planets[URANUS].mass = "8.68 x 10^25"
planets[URANUS].color = makeColor(0,245,231)
planets[NEPTUNE].name = "Neptune"
planets[NEPTUNE].diameter = 4
planets[NEPTUNE].perihelion = 4502896398.7
planets[NEPTUNE].aphelion = 4536740736
planets[NEPTUNE].perAU = 30.1
planets[NEPTUNE].aphAU = 30.3262354
planets[NEPTUNE].diaAU = 0.000331
planets[NEPTUNE].ecc = 0.991
planets[NEPTUNE].rev = 164.81
planets[NEPTUNE].rot = 0.7958
planets[NEPTUNE].temp = 48
planets[NEPTUNE].mass = "1.02 x 10^26"
planets[NEPTUNE].color = makeColor(87,56,242)
planets[PLUTO].name = "Pluto"
planets[PLUTO].diameter = 0.18
planets[PLUTO].perihelion = 5909116536.5
planets[PLUTO].aphelion = 7330561920
planets[PLUTO].perAU = 39.5
planets[PLUTO].aphAU = 49.00177447
planets[PLUTO].diaAU = 0.000022
planets[PLUTO].ecc = 0.75
planets[PLUTO].rev = 247.7
planets[PLUTO].rot = 6.39
planets[PLUTO].temp = 37
planets[PLUTO].mass = "1.29 x 10^22"
planets[PLUTO].color = makeColor(127,130,110)
// Make some happy little stars
Global stars as Star[100]
for i = 1 to stars.length
stars[i].x = random(0,1920)
stars[i].y = random(0,1200)
next i
planets[SUN].x = 300
planets[SUN].y = 360
scale# = 20
sx = 0
sy = 0
setPrintSize(24)
timestamp = getMilliseconds()
Ang# = 0
spr_info = createSprite(0)
setSpriteColor(spr_info, 14,67,240,191)
setSpriteSize(spr_info, 430,160)
Global t_title, t_ecc, t_dia, t_per, t_rot, t_tem, t_mas
t_title = createText("name") : setTextAlignment(t_title, 1) : setTextSize(t_title, 26)
t_ecc = createText("") : setTextSize(t_ecc, 20)
t_dia = createText("") : setTextSize(t_dia, 20)
t_per = createText("") : setTextSize(t_per, 20)
t_rot = createText("") : setTextSize(t_rot, 20)
t_tem = createText("") : setTextSize(t_tem, 20)
t_mas = createText("") : setTextSize(t_mas, 20)
do
// Show planet information
if hover_planet > -1
x = planets[hover_planet].x+200
y = planets[hover_planet].y-200
setSpritePosition(spr_info, x, y)
setInfoPosition(x, y)
c = makeColor(0,165,251)
drawBox(x, y, x+430, y+160, c,c,c,c, 0)
drawLine(x,y+160,planets[hover_planet].x,planets[hover_planet].y,c,c)
drawLine(x+10, y+26, x+420, y+26, c, c)
else
setSpriteVisible(spr_info, 0)
showText(0)
endif
// Only display info if mouse continually over celestial body
hover_planet = -1
// Draw some stars
for i = 1 to stars.length
k = 128+random(0,127)
c = makeColor(k,k,k)
drawBox(stars[i].x, stars[i].y, stars[i].x+1, stars[i].y+1, c, c, c, c, 1)
next i
// Draw the sun
r# = planets[SUN].diaAU/2 * scale#
if r# < 10 then r# = 10
DrawEllipse(planets[SUN].x, planets[SUN].y, r#, r#, makeColor(255,127,39),makeColor(255,127,39),1)
// If mouse is over planet
if (mx-planets[SUN].x)^2+(my-planets[SUN].y)^2 <= r1#^2
hover_planet = SUN
setInfo(hover_planet)
setSpriteVisible(spr_info, 1)
showText(1)
endif
// Update the simulation 3.65 Earth days every 100ms
ms = getMilliseconds()
if ms >= timestamp+100
years# = years# + 0.01
timestamp = getMilliseconds()
endif
mx = getRawMouseX()
my = getRawMouseY()
// Loop through planets
for i = 1 to 9
// radius of planet, keeping minimum displayed size at 10px radius
r1# = planets[i].diaAU/2.0 * scale#
if r1# < 10 then r1# = 10
// Find center between orbital foci
cX# = planets[SUN].x + (planets[i].aphAU - planets[i].perAU) * scale#
// orbit's semi-major axis
rx# = (planets[i].aphAU + planets[i].perAU) / 2.0 * scale#
// orbit's semi-minor axis
ry# = rx# * planets[i].ecc
// Draw orbit
drawEllipse(cX#, planets[SUN].y, rx#, ry#,planets[i].color,planets[i].color,0)
`ellipse(cx#, planets[SUN].y, 0,360, 9, rx#, ry#, planets[i].color )
// set orbital position of planet
ang# = (years# / planets[i].rev) * 360
planets[i].x = cx# + COS(Ang#) * rx#
planets[i].y = planets[SUN].y + SIN(Ang#) * ry#
// draw planet
drawEllipse(planets[i].x, planets[i].y, r1#, r1#, planets[i].color, planets[i].color,1)
// If mouse is over planet
if (mx-planets[i].x)^2+(my-planets[i].y)^2 <= r1#^2
hover_planet = i
setInfo(hover_planet)
setSpriteVisible(spr_info, 1)
showText(1)
endif
next i
// left
if getRawKeyState(37)
dec years#, 0.1
if years# < 0 then years# = 0
endif
// right
if getRawKeyState(39)
inc years#, 0.1
endif
// up
if getRawKeyState(38)
inc scale#, 200
endif
// down
if getRawKeyState(40)
dec scale#, 200
if scale# < 10 then scale# = 10
endif
wd = getRawMouseWheelDelta()
if wd < 0
inc scale#, 10
elseif wd > 0
dec scale#, 10
if scale# < 10 then scale# = 10
endif
rightDown = getRawMouseRightState()
if rightDown
if flag = 0
flag = 1
sx = getRawMouseX() - planets[SUN].x
sy = getRawMouseY() - planets[SUN].y
else
planets[SUN].x = getRawMouseX() - sx
planets[SUN].y = getRawMouseY() - sy
endif
endif
if getRawMouseRightReleased()
flag = 0
endif
print("Years: "+str(years#))
Sync()
loop
function setInfo(p)
setTextString(t_title, planets[p].name)
setTextString(t_ecc, "Eccentricity: " + trimString(str(planets[p].ecc),"0"))
setTextString(t_dia, "Diameter (KM): " + formatNumber(str(round(planets[p].diameter*AU))))
setTextString(t_per, "Dist. Sun (AU): " + trimString(str(planets[p].perAU),"0"))
if planets[p].rot < 1
r$ = trimString(str(planets[p].rot*24), "0") + " hours"
else
r$ = trimString(str(planets[p].rot),"0")+" days"
endif
setTextString(t_rot, "Rotation (Earth): " + r$)
setTextString(t_tem, "Temperature (K): " + formatNumber(str(planets[p].temp)))
setTextString(t_mas, "Mass (Kg): " + planets[p].mass)
endfunction
function setInfoPosition(x, y)
setTextPosition(t_title, x+215, y)
setTextPosition(t_ecc, x+10, y+35)
setTextPosition(t_dia, x+10, y+55)
setTextPosition(t_per, x+10, y+75)
setTextPosition(t_rot, x+10, y+95)
setTextPosition(t_tem, x+10, y+115)
setTextPosition(t_mas, x+10, y+135)
endfunction
function showText(n)
setTextVisible(t_title, n)
setTextVisible(t_ecc, n)
setTextVisible(t_dia, n)
setTextVisible(t_per, n)
setTextVisible(t_rot, n)
setTextVisible(t_tem, n)
setTextVisible(t_mas, n)
endfunction
FUNCTION ellipse( StartX AS INTEGER , StartY AS INTEGER , StartAng AS INTEGER , EndAng AS INTEGER , StepAmt AS FLOAT , SemiMajor AS FLOAT , SEMIMINOR AS FLOAT, color as integer )
FOR Ang# = StartAng TO EndAng STEP StepAmt
X = StartX + COS(Ang#) * SemiMajor
Y = StartY + SIN(Ang#) * SemiMinor
DrawBox(x,y,x+1,y+1, color, color, color, color, 1)
NEXT
ENDFUNCTION
// Add commas to string
function formatNumber(s$)
ts$ = ""
c = 0
for i = len(s$) to 1 step -1
inc c
ts$ = mid(s$, i, 1) + ts$
if c = 3 and i > 1
c = 0
ts$ = ","+ts$
endif
next i
endfunction ts$

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds