al0_1.py

Created by steveg1cmz

Created on August 09, 2023

3.65 KB

Astronomy: Lunar (AL) v 0.1 Version 0.1 is a simple astronomy program showing orbital characteristics (circular simplified) using Turtle. It includes an animation of the light Comms delay to commemorate the anniversary of Apollo 11 in July. I am experienced, but this is my first Numworks script. There is a similar program by me on HP Prime. If your platform supports keyboard, change waittime to 0. (Numworks app has EXE key) https://www.hpmuseum.org/forum/thread-13311.html Tested on Numworks 19.4.0 Tested on Numworks 20 3.2


"""Astronomy: Lunar (AL).
This version shows orbital data (simplified to be circular).
It animates light transfer time, to commemorate Apollo 11.
"""

__version__ = '0.1'

from turtle import *
from time import * #sleep
try: 
  from ion import *   #keydown
except:
  pass #use waittime instead
waittime = 2 #seconds, or 0=keydown

crid="""Astronomy: Lunar (AL) V""" +__version__ +"""
© 2023 SteveG1CMZ"""

#customise
linesz=18
pixels=70 #radius of filled circle
showme=True
speedt=0 #0 ..10 or string unused
pensz = 1 #normal pensize
xscreen=int(318/2)
yscreen=int(186/2)
pbd='blue' #pale blue dot 
y=[254,234,0] #yellow

#end custom

stlunar = "Lunar Distance:"

#physical data
#relative values (circular simplified)
earthrr=1
moonrr=0.2727 #0.2724 #0.2727

earthkm = 6371.0 #radius
moonkm = 1737.4 #radius
orbitalradiuskm=384400
orbitalradiust=1.27 #s
stationarykm = 35876
earthdens = 5514 # kg/M3
moondens = 3344

#general functions
def aboutme():
  print( """Programmer seeks work.
Email: at gmail.com""")

def  fillcircle(N):
  """Fill a circle.
  Tech: uses pensize
  #N>140 memory fails (Numworks)
  """
  pensize(round(N))
  forward(1) #draw something
  pensize(pensz)

def getkey():
  while not( keydown(KEY_EXE)): pass

def waiting():
  if waittime:
    sleep(waittime)
  else:
    getkey()

def more():
  penup(); hideturtle()
  goto(-xscreen,-yscreen)
  if not(waittime):
    write("[press EXE to continue]")
#end general functions

def earth():
  penup();hideturtle()
  st="Earth Radius: (1)\t{} km".format( round(earthkm))
  goto(-xscreen,yscreen-2*linesz)
  write(st)

  goto(0,0)  
  pendown()
  color(pbd)
  fillcircle(pixels)
  penup(); hideturtle()

def moon():
  penup();hideturtle()
  
  st="Moon Radius:({})\t{} km ".format( round(moonrr,3), round(moonkm))
  goto(-xscreen,yscreen-3*linesz)
  write(st)
  goto(0,0)
  pendown()
  color(y)
  fillcircle(pixels*moonrr)

def em(): #earth-moon
  penup(); hideturtle()
  goto(-xscreen,yscreen-0*linesz)
  st="Lunar Distance:  {} km".format( round(orbitalradiuskm))
  write(st)
  st="Lunar Distance: {} s".format( orbitalradiust)
  goto(-xscreen,yscreen-1*linesz)
  write(st)
  goto(0,0)
  color(pbd)
  pendown()
  circle(1)
  penup()

  goto(0,-pixels)
  color(y) 
  pendown()
  circle(pixels)
  more()
  waiting()
  penup()
  goto(pixels,0)
  color('black')
  setheading(180)
  pendown()
  for X in range (pixels):
    forward(1) #this time is not counted yet
    sleep(orbitalradiust/pixels)
  penup()
  goto(-xscreen,-5*linesz)
  write(" That's one small step for a man")
  sleep(orbitalradiust)
  goto(-xscreen,-6*linesz)
  write(" one giant leap for mankind")
  sleep(orbitalradiust)

  

def legend():
  rrkm = getroche( earthkm,earthdens,moondens)
  if True: aboutme()
  print("Earth radius: km:",round(earthkm))
  print("Moon radius:  km:",moonkm)
  if True:
    print("Roche limit: km:",round(rrkm))
  print("Geotationary orbit: km",stationarykm)
  print(stlunar,"km:",orbitalradiuskm)
  print(stlunar,"s:",orbitalradiust)

def getroche(radius1,dens1,dens2):
  """Get (rigid) Roche limit in units of R1.
  Roche limit depends on:
  Radius of primary
  Relative density
  Expected: 9492
  (A fluid moon would double that).
 """
  rr= radius1 * (2*dens1/dens2)**(1 / 3.)
  return rr

def main():
  penup();hideturtle()
  goto(-xscreen,yscreen)
  write(crid)
  sleep(1)

  earth()
  goto(-xscreen,-yscreen)
  more()
  waiting()
  moon()
  penup(); hideturtle()
  goto(-xscreen,yscreen)
  waiting()
  reset() #clearscreen
  em()
  legend()


if showme or __name__ == "__main__":
  print(crid)
  if not(waittime): 
    try:
      inp=input("Wait time (s) or 0 (EXE)?")
    except: #not effective in Numworks
      inp="0"
    waittime=float(inp)
  main()