Solar System
Posted: Sat Mar 15, 2025 8:52 pm
This is my latest version with several improvements:
Option to go directly to Today’s Date
Approximate Daytime region of sky is shown
Improvements and corrections to Leap Year calculations
Improvements in going to specific starting date
Sliders now work while Paused
-Leap Year calculations have several exceptions in other Centuries. They can be added if you want. They make a very long IF-THEN statement.
-Daytime sky is an estimate based on Mercury not being visible after sunrise.
-Startup Date (Day# 0) can be changed. The required data can be obtained at the web site given in the REM statements.
Option to go directly to Today’s Date
Approximate Daytime region of sky is shown
Improvements and corrections to Leap Year calculations
Improvements in going to specific starting date
Sliders now work while Paused
-Leap Year calculations have several exceptions in other Centuries. They can be added if you want. They make a very long IF-THEN statement.
-Daytime sky is an estimate based on Mercury not being visible after sunrise.
-Startup Date (Day# 0) can be changed. The required data can be obtained at the web site given in the REM statements.
Code: Select all
'g'.
' ==== NEW FEATURES: Jan 1 (2925) Start date ======
/* Goes to specific Start Date instantly ======= Nov 19/2026
Gpttion to go directly to Today's date
Version 2: Misc improvements: Pause, improved scaling, 2-digit year input
Version 3: Added (simulated) elliptical orbit for Mercury
Version 4: Goes directly to a future date w/o drawing the intermediate dates, ie only
updates the dates, but runs faster by not drawing them all. The STEP is
never >1, so drawing is always accurate while in this mode.
Version 4.1 Fixed problem of on-screen keyboard entry not displaying properly.
Not posted to Forum. Replaced by Ver5.
Version 5. Changed Specific Date section to all GRAPHICS. Replaces Ver4.1
Version 6: Changed Startup date to Jan 1, 2025
Version 7: Goes to calculated specific start date instantly.
7.1: Added day/night skies, and Goto Today's date
-----------------------------------------------
Although this program shows the planets positions reasonably accurately on any particular date, it is not designed to be precise; the orbit diameters are to scale, but are circular, not elliptical, so the orbital speeds are constant, not varying at perihelion & aphelion. This will give a slight inaccuracy in their positions, which, at the scale drawn, will probably not be noticable to the naked eye. In particular, Pluto's orbit is represented by a circle with its centre offset from the Sun so that it crosses Neptunes orbit in a realistic looking manner, though not perfectly accurate.
The Moons distance from earth is greatly exaggerated to make it distinguishable from Earth. Although I suppose zoom could be increased.
The planets sizes are not to scale, other than the inner planets being smaller than the outer ones. The sizes do not change with the zoom.
Day#1 is Jan 1/2025, because that was the best date I could find data at the time.
Note: Celestial Longitude is measured CCW; Smart BASIC measures angles CW. This can be confusing.
DRAW etc co-ordinates are for iPad mini: screen size sw=1024 sh=724
hh===========================================================
RAW DATA from an astronomy handbook; only used for ref when writing program:
Dist(millions-km) Revolution(days)
Mercury 57.9 87.969
Venus 108.1 224.7
Earth 149.5 365.258 BUT PROG USES 365.0 SEE LEAP YEAR NOTE BELOW.
Mars 227.8 687.0
Jupiter 778 4332 days = 11.86 years (program works in days)
Saturn 1427 10760 = 29.46
Uranus 2869 30685 = 84.01
Neptune 4497 60195 = 164.8j
Pluto 5900 90475 = 247.7
Moon 0.3 27.321661
Moon's distance is greatly exaggerated in the diplay, to distinguish it from Earth.
Pluto Eccentricity = 0.25 Longitude of Perihelion = +224º
Mercury Eccentricity=0.2 " " " = +77.5º
(NOTE: + angles are CCW on real sky, but draw CW in BASIC. This can be confusing.)
Pluto's & Mercury;s eccentricities are simulated by an offset circle.
NOTE re LEAP YEARS: Planet orbital periods are Earth days based on 365.0 days per year, i.e Calendar days. Therefore Earth period and position is calculated with 365.0 days, with the extra day added every leap year. This also adds the 1 day to the planets' periods. This is very confusing to work out, but it seems to be correct. Also, the Leap Year calculation (in the Date Calculation section) should contain exceptions to the exceptions, but those shown will not show any visible error for several hundred years. Enough is enough!
*/ '=============== PROGRAM BEGINS HERE =============================
'b'
OPTION BASE 1
OPTION ANGLE DEGREES
OPTION SPRITE POS CENTRAL
SET BUTTONS CUSTOM
SET BUTTONS FONT SIZE 35
DIM pname$(10), dist(10), pper(10), mon$(13), days(13) 'dacc(13)
' pperiod (days), dist (mill km) init pos of planets is 1 Jan 2025 = Day# 1.
' dacc() is day# of year on last day of each momth
' days() is num of days in each month
'r'
'Calendar for dates:
DATA "Jan",31,"Feb",28,"Mar",31,"Apr",30,"May",31,"Jun",30,"Jul",31,"Aug",31
DATA "Sep",30, "Oct",31,"Nov",30, "Dec",31
FOR i=1 TO 12
READ mon$(i), days(i)
NEXT i
'------------------------------------
'Table of planet data: From https://eco.mtk.nao.ac.jp/cgi-bin/koyomi/cande/planet_ecliptic_en.cgi
' Dist(mill km) RevPer (d) Start date is initial pang() of Dec 31.2024 = Day# 0
DATA "Mercury", 57.9, 87.969, -199.4088, "Venus", 108.1, 224.7, -49.81, "Earth", 149.5, 365, -99.47
DATA "Mars", 227.8, 687.0, -108.77879, "Jupiter", 778, 4331.98, -78.26455, "Saturn", 1427, 10760, -349.77655 ' 1 Earth day is defined as 365.0 per year
DATA "Uranus", 2869, 30685, -55.73444, "Neptune", 4497, 60194, -359.14093, "Pluto",5900,90475, 60.1233, "Moon", 7, 27.321661, 73.467 'moon dist is exaggerated to display outside earth.
' Note: Plutos orbit is centred at OFFSET of 56, -73 to simulate ellipse.
FOR i=1 TO 10 'incl moon when i=10.
READ pname$(i), dist(i), pper(i), pang(i)
'1st pang(i) (starting date) is init pos of planets on JAN 1/25.
' Note: initial pang() (planet angle) is starting angle ====
ovel(i)= -360/pper(i) 'orbital vel.(degrees/day) (**is ccw) ==============
NEXT i
'g'
GRAPHICS
GRAPHICS CLEAR 0, .8, 1
DRAW COLOR 1, 1, 1
sw=SCREEN_WIDTH() ! sh=SCREEN_HEIGHT() ' 1024 x 724; iPhone: auto
sw2=sw/2-50 ! sh2=sh/2 ' 50 pix left of centre screen, to allow Plutos orbit
dscale= .8 ' scale for drawing circles (orbits)
''
spw=1000 ! sph=1000 'sprite width, height
SPRITE "bg" BEGIN spw, sph 'daytime sky background
FILL COLOR 0, .8 , 1
FILL TRI 500, 500, 0, 280, 0, 720
SPRITE END
SPRITE "bg" RESIZE 8000, 8000 'resize even larger will "fuzz" the edges for more realistic
SPRITE "bg" ALPHA 0.3 ' Text is behind the sprite
'------------- 'ALPHA is really Opacity, not transparency
'r' STARTUP DATE & some SETTINGS =================================================
yr=2024 'starting date (day #0)
m=12 ' Start date (Day# 0) is Dec 31/2024 ***** (Day#1 is Jan 1/2025)*****
d=31
daynum=0 ' 1 is added to date & day# on 1st iteration of "main:" loop.aAa
STEP=1 'default
pse=1 '1=start up with PAUSE on. 0=start up running
'c'
50
'GRAPHICS !' GRAPHICS CLEAR 0,0,.7
'FIELD "ask" TEXT "Go directly to specific date? y/n" AT 100,100 SIZE 500,50 'create
FIELD "ask" TEXT "Go to Today? (t) Other date? (y/n)" AT 100,100 SIZE 500,50 'create
FIELD "ask" FONT SIZE 25
FIELD "ask" SELECT
DO
UNTIL FIELD_CHANGED("ask")=1
y$=LOWSTR$(FIELD_TEXT$("ask"))
IF y$<>"y" AND y$<>"n" AND y$<>"t" THEN 50 '- invalid entry
IF y$="n" THEN GOTO 60 ' date search not req;d
IF y$="t" THEN ' todays date
dsp=CURRENT_DATE()
msp=CURRENT_MONTH()
ysp=CURRENT_YEAR()
ch$="t"
'GOTO 60
ENDIF
sd=1 ' activate specific start date routine
FOR i=1 TO 10
pang(i)+=ovel(i) 'inc 1 day to set pang() to day#1 if y$"y" or "t"
NEXT i
FIELD "ask" DELETE
IF y$="t" THEN GOTO 60 ' skip date input
GRAPHICS CLEAR 0, 0, .7
FIELD "d" TEXT "Date" AT 100,50 SIZE 100,50 'create
FIELD "d" FONT SIZE 25
FIELD "m" TEXT "Month#" AT 100,100 SIZE 120,50 'create
FIELD "m" FONT SIZE 25
FIELD "y" TEXT "Year (yy or yyyy)" AT 100,150 SIZE 230,50 'create
FIELD "y" FONT SIZE 25
'r'
55 ' ======= Specific "Go-To" date Entry ================
FIELD "d" SELECT
FIELD "d" TEXT "Date"
DO
UNTIL FIELD_CHANGED("d")=1
dsp=FIELD_TEXT$("d")
'----------------------
FIELD "m" TEXT "Month#"
FIELD "m" SELECT
DO
UNTIL FIELD_CHANGED("m")=1
msp=FIELD_TEXT$("m")
FIELD "m" TEXT mon$(msp)
'--------------------
57
FIELD "y" SELECT
DO
UNTIL FIELD_CHANGED("y")=1
ysp=FIELD_TEXT$("y")
IF ysp<100 THEN ysp=ysp+2000 ' "yy" format only in this century!!
IF ysp<2025 THEN
FIELD "y" TEXT "Yr must be >2024"
GOTO 57
ENDIF
FIELD "y" TEXT ysp
'-------------------
FIELD "ok" TEXT "Confirm? y/n" AT 100,250 SIZE 250,50
FIELD "ok" FONT SIZE 25
FIELD "ok" SELECT
DO
UNTIL FIELD_CHANGED("ok")=1
y$=LOWSTR$(FIELD_TEXT$("ok"))
IF y$<>"y" THEN GO TO 55
59
FIELD "d" DELETE ! FIELD "m" DELETE ! FIELD "y" DELETE ! FIELD "ok" DELETE
''
60 linum=60
FIELD "ask" DELETE ' when no specific date entered
FILL COLOR 1,0,0 ' for button colour.
DRAW FONT SIZE 22
BUTTON "toggle" TEXT "PAUSE" AT sw-200, sh-80 SIZE 130,70
DRAW FONT SIZE 20
SLIDER "scale" VALUE 0.9 AT 1000, 600 SIZE 400 ANGLE -90 ' zoom, & initial value
SLIDER "speed" VALUE 0.3 AT 20, 600 SIZE 400 ANGLE -90 'speed
dsc=0 'initial scale
found=0
SPRITE "bg" SHOW
62 linum=62
'g'================= MAIN LOOP ============================
main:
GRAPHICS CLEAR 0, 0, .3 'very dark blue sky
REFRESH OFF ' stops flicker - don't update screen during calculations,
DRAW FONT SIZE 20
SPRITE "bg" SHOW 'Show daylight sky background; REM out if not wanted
'Heliocentric Longitude etc markers ---------------------
DRAW LINE sw2+250,sh2 TO sw2+330, sh2 ! DRAW TEXT "0º" AT sw2+335,sh2-10
DRAW LINE sw2-250,sh2 TO sw2-330, sh2 ! DRAW TEXT "180º" AT sw2-380,sh2-10
DRAW LINE sw2,sh2-250 TO sw2, sh2-300 ! DRAW TEXT "90º" AT sw2-13,sh2-320
DRAW LINE sw2,sh2+250 TO sw2, sh2+315 ! DRAW TEXT "270º" AT sw2-18,sh2+320
DRAW TEXT "Spring Equinox" AT sw2-400, sh2+10
DRAW TEXT "Summer Solstice" AT sw2+10, sh2+300
DRAW TEXT "Fall Equinox" AT sw2+300, sh2+10
DRAW TEXT "Winter Solstice" AT sw2+10, sh2-300
' ----- Jan 1 mark for Earth: ================
DRAW LINE sw2-dist(3)+100,sh2-dist(3)-110 TO sw2-dist(3)+140, sh2-dist(3)+100
DRAW TEXT "Jan 1" AT sw2-dist(3)+65, sh2-dist(3)-130
DRAW LINE 1, 510 TO 50,510 'just a marker for change of STEP
65 linum=65
'========== READ SLIDERS ===========
sv2=SLIDER_VALUE("speed") 'orbital speed
IF sv2<=0.3 THEN ' The lower part controls the PAUSE duration (at the
STEP=1 ' end of the loop), allowing a slower
pdelay=24*(sv2-.3)^2 ' display speed for the inner planets.
ENDIF
IF STEP>25 THEN STEP=25 'STEP>28 could skip a whole month, throwing off the date display
IF sv2>.3 THEN 'The upper part of the slider range varies the STEP, ie
'how many days pass for each iteration of the loop,
'allowing a higher display speed for the outer planets.
' **NOTE: if STEP > ~15 or 20 the accuracy will be reduced.**
DRAW COLOR 1, .5, .5
DRAW TEXT "*STEP IS " & INT(STEP) & " DAYS" AT 40,450 'WARNING msg:
' if STEP >than ~20 days, accuracy may be reduced.
DRAW COLOR 1,1,1
pdelay=0 ' pause at end of main: loop
STEP=INT(MAX(1,200*(sv2-.3)^2))
ENDIF
'found=0
skip=1
'dbp
'r'
1000 linum=1000 '========= DATE CALCULATION: =========--=-=-=-=-=-=-=-=-=-=
IF daynum=0 THEN days(2)=28 ' * Because Start Date (Day#0) is last day of 2024
1010 linum=1010
FOR stp=1 TO STEP ' check through STEP ates. sd=0
1400 linum=1400
d=d+1 ' next day (date) of month------
linum=1410
daynum=daynum+1
linum=1420
IF d>days(m) THEN ' next month ----------------
m=m+1
linum=1430
IF m>12 THEN ' next year
m=1 ' reset month to Jan.
yr=yr+1 ' next year ------------
1450
linum=1450
IF yr/4=INTEG(yr/4) AND yr/100<>INTEG(yr/100) THEN 'SEE LEAP YEAR NOTE ABOVE
days(2)=29 ' is leap year!
ELSE
days(2)=28 ' reset to default after leap year
ENDIF
ENDIF
d=1 'reset date
ENDIF
linum=1480
IF sd=0 AND ch$<>"t" THEN GOTO 1800 ' CONTINUE stp ' skip date search ===========
1500 linum=1500
'------------ look for stop (start) date -----------------
IF d=dsp AND m=msp AND yr=ysp THEN 'found date. d, m, yr
skip=daynum-1 'for planet ang pang()
found=1 'found stop date
ENDIF 'keep looking
linum=1600
IF found=0 THEN GOTO 1400
BREAK stp 'date found=1 so jump out
1800 linum=1800
NEXT stp 'next step
'---------------------------------------------
1900 linum=1900 ' ***** Now daynum is where to skip to *****
'g'
DRAW TEXT INT(d) & " " & mon$(m) & " " & yr AT sw-160, 60
DRAW TEXT "Day# " & INT(daynum) AT sw-160, 30
DRAW TEXT "ZOOM" AT sw-60, 200
DRAW TEXT "SPEED" AT 5, 200
'-------------------- SCALE ------------
'dsc=dscale*.3*(SLIDER_VALUE("scale"))+.024 ' set values
dsc=dscale*.95*(SLIDER_VALUE("scale"))^2 +.03 ' better display scale factor; use this one
'Pluto and Mercury's orbits are elliptical; simulate as off-centre circle:
' The following prevents the offsets from apparing to vary with Zoom value).
poffx=dsc*3100*COS(224-180) '2000 'Pluto Perihelion = +224º (-224 in BASIC)
poffy=dsc* -3100*SIN(224-180) 'Vary Pluto offset according to dsc (zoom/drawing scale).
moffx=dsc* -25*COS(77.5) ' Mercury Perihelion = +77.45º (-77.45º in S-BASIC)
moffy=dsc*25*SIN(77.5) ' Vary mercury offset according to dsc (scale)
FILL COLOR 1,1, 0 ' yellow, for sun
FILL CIRCLE sw2, sh2 SIZE 25*dsc 'Sun, variable size, according to zoom scale
DRAW COLOR 1, 1, 1 ' white, for planets & orbits
' ============== ORBITS ----- depend on scale -------------------
FOR i=1 TO 9
IF i>1 AND i<9 THEN DRAW CIRCLE sw2,sh2 SIZE dist(i)*2*dsc 'draw orbits of 8 planets
GOSUB offsets ' 1 is Mercury, 9 is Pluto:
IF i=1 OR i=9 THEN DRAW CIRCLE sw2+pxoff, sh2+pyoff SIZE dist(i)*2*dsc
NEXT i
'dbp
'b' ============= PLANETS ======= depend on scale & step =========
2000 linum=2000
FOR i=1 TO 10
FILL COLOR 1,1,1 'white, for planets
IF i=3 THEN FILL COLOR .2, .2, 1 'blue, for Earth only
IF i=4 THEN FILL COLOR 1, .5, .5 'reddish, for Mars only
IF i=7 THEN FILL COLOR .4, 1, .4 'greenish, for Uranus only
2100 linum=2100
pang(i)=pang(i)+ovel(i)*skip*STEP 'new angular pos each day (or each STEP in ' FOR loop) but NOT when PAUSED.
2110 linum=2110
pang(i)=pang(i)%360 ' a%b is (a MOD b) or MOD(a,360)
sz=8 'planet size
IF i<=4 OR i=9 THEN sz=4 ' inner planets & Pluto are smaller
GOSUB offsets
' planets only: dsc is the drawing scale.
IF i<10 THEN
x(i)=dist(i)*2*COS(pang(i))*dsc + pxoff ' dist to planet from sun; x position
y(i)=dist(i)*2*SIN(pang(i))*dsc + pyoff ' ditto, y position
FILL CIRCLE sw2+x(i), sh2+y(i) SIZE sz 'draw planets
DRAW TEXT LEFT$(pname$(i),2) AT sw2+x(i), sh2+y(i)+8 'place below planet
ELSE 'i=10 is the moon
DRAW CIRCLE sw2+x(3), sh2+y(3) SIZE dist(10)*2*dsc 'MOON ORBIT, ctr on Earth
' MOON POS'N: ----------
x(10)=sw2+x(3)+dist(10)*2*COS(pang(10))*dsc 'posn in orbit
y(10)=sh2+y(3)+dist(10)*2*SIN(pang(10))*dsc
FILL CIRCLE x(10),y(10) SIZE 5*dsc 'centred at current posn of Earth+dist from Earth
ENDIF
SPRITE "bg" AT sw2+x(3), sh2+y(3) ANGLE (pang(3)) ' daylight sky region
2200 linum=2200
NEXT i
'=====================================================
skip=1
sd=0
REFRESH ON 'now update the screen
PAUSE pdelay 'to set speed - pdelay is set by Slider "speed"
5000 linum=5000
'g' ========== PAUSE BUTTON ROUTINE =========
IF found=1 THEN pse=1
IF BUTTON_PRESSED("toggle")=1 THEN pse=1-pse
5010 linum=5010
IF pse=1 THEN
BUTTON "toggle" SET TEXT "RUN" 'paused
DO 'do nothing until button pressed again
IF SLIDER_CHANGED ("speed") THEN GOTO main
IF SLIDER_CHANGED ("scale") THEN GOTO main
IF BUTTON_PRESSED("toggle")=1 THEN pse=0
UNTIL pse=0
ENDIF
'c'
5020 linum=5020
BUTTON "toggle" SET TEXT "PAUSE" 'running
found=0 ' } Done searching for date;
ch$="" ' } now is regular running.
GOTO main
END ' Just for protection ===============
'======================================================
'r'===================== SUBROUTINES & DEFs ======================
offsets: ' set offsets for Mercury & Pluto orbits, to simulate ellipses
pxoff=0 ! pyoff=0 ' zero offset for most planets & moon
IF i=1 THEN 'Mercury
pxoff=moffx ! pyoff=moffy 'Mercury offset
ENDIF
IF i=9 THEN 'Pluto
pxoff=poffx ! pyoff=poffy 'Pluto offset, to simulate ellipse
ENDIF
' other planets & moon- no offset
RETURN
END
''=========================================
DEF dbp ! DEBUG PAUSE ! END DEF 'this is very helpful for debugging (refer to lnum)
'r'
''