Halley’s Comet

Developer(s): Roald Schrack
Date: 1986
Type: Program
Platform(s): TS 2068
Tags: Astronomy

This program plots an interactive diagram of Halley’s Comet’s orbit through the inner solar system, drawing the orbits and labels of six planets (Earth, Jupiter, Saturn, Uranus, Neptune, and Pluto) before animating the comet’s elliptical path. The planet orbits are drawn using parametric polar equations with CIRCLE for the sun and incremental PLOT calls stepping by 3/r radians per iteration, where r is the orbital radius in screen units. Halley’s Comet trajectory uses Kepler’s equation — t = 12.12*(p – 0.9673*SIN p) — where p is the eccentric anomaly and 0.9673 is the orbital eccentricity, producing a physically accurate elliptical path. The comet’s distance from the sun is calculated each step and displayed in miles, with a year counter updating every simulated year as the comet progresses from perihelion through one full orbit (2π radians). The program was published in the CATS Newsletter in June 1986, timed to coincide with Halley’s Comet’s 1985–1986 apparition.


Program Analysis

Program Structure

The program divides into three logical phases:

  1. Solar system setup (lines 50–60): Clears the screen and draws a small circle representing the sun at screen coordinates (10, 85).
  2. Planet orbit drawing (lines 100–220): Loops through six planets read from a DATA statement, plotting each orbit as a series of incremental PLOT calls using parametric equations.
  3. Comet animation (lines 230–340): Iterates the eccentric anomaly p from 0 to 2π, computing the comet’s Cartesian screen position at each step, plotting it, displaying the distance from the sun in miles, and printing the current simulated year.

Planet Orbit Drawing

Each planet’s orbit data consists of a label string, a starting angle p, and an orbital radius r in screen units. The loop at lines 140–190 computes x = r*COS(p) + 10 and y = r*SIN(p) + 85, advancing the angle by 3/r radians each iteration. This variable step size means larger orbits get more plot points per radian — a pragmatic trade-off between accuracy and speed. The orbit is complete when p exceeds pz (the original positive value of the starting angle stored before negation at line 130).

Planet labels are printed at line 200 using PRINT AT 22-y/8, x/8, converting the high-resolution PLOT coordinate space (~176×256 or similar) back to the 22-row text grid.

Kepler’s Equation and Comet Orbit

The comet’s motion uses Kepler’s equation in the form t = 12.12*(p - 0.9673*SIN p), where p is the eccentric anomaly and 0.9673 is Halley’s Comet’s actual orbital eccentricity. The coefficient 12.12 scales the result so that t increments in years over one orbit (~75–76 years). The Cartesian screen position is computed as:

  • x = 107.4*(0.9673 - COS p) + 10
  • y = 27.2*SIN p + 85

The differing scale factors (107.4 vs 27.2) reflect the highly elliptical nature of the orbit when projected onto the screen’s non-square coordinate system. The orbit terminates at line 302 when p > 6.28318 (2π radians), completing one full revolution.

Distance Calculation

Line 304 computes the comet’s distance from the sun in miles:

d = 15.6E6 * SQR((x-10)^2 + (y-85)^2)

The offsets 10 and 85 are the sun’s screen coordinates, so the expression inside the square root is the squared screen-space distance. The scale factor 15.6×10⁶ miles per screen unit converts to real-world distance. This is displayed continuously at row 21.

Year Counter Logic

The variable tz tracks elapsed integer years. At line 270, if t > tz+1, execution jumps to line 290 (effectively a no-op skip — the condition is checked again at line 312 after the PLOT). When the year threshold is crossed, line 320 prints tz+1987 at row 20 column 7, and line 330 increments tz. The starting year 1986 is printed at line 245 as a literal, while subsequent years are computed as tz+1987, implying the simulation begins just before perihelion at year offset 0.

Bugs and Anomalies

  • Dead branch at line 270: The condition IF t>tz+1 THEN GO TO 290 jumps to line 290, which is the very next line — so this branch has no effect and the code always falls through to line 290 regardless. The meaningful conditional skip is at line 312, which branches to line 320 (the year-print block) only when the year threshold is crossed. The line 270 branch appears to be a remnant of an earlier structure or a typographical error.
  • Planet “p” vs “P”: Pluto is stored in DATA as lowercase "p", which will appear as a lowercase letter on screen — likely intentional to denote Pluto’s minor or uncertain planetary status, or simply a quirk of the original author.
  • Orbit start angle negation: Lines 120–130 save p into pz then negate p, so orbits are drawn from -p to +p, covering a symmetric arc. For values near π this produces nearly full circles, while smaller values produce partial arcs — intentional for inner vs. outer planets.

Key Variables

VariableRole
jPlanet loop index (1–6)
n$Planet label string
pAngle/eccentric anomaly (dual use)
pzOrbit end angle (planet phase) or unused
rOrbital radius in screen units
x, yScreen plot coordinates
tSimulated time in years (from Kepler’s equation)
tzInteger year counter
dDistance from sun in miles

Content

Appears On

Related Products

Related Articles

Short program that plots the orbit of Halley’s Comet, starting in 1986. Typed in by Tim Swenson.

Related Content

Image Gallery

Halley’s Comet

Source Code

    1 REM Halley's Comet Redux
    2 REM Roald Schrack
    3 REM CATS Newsletter v4 n3
    4 REM https://archive.org/details/cats-newsletter/CATS%20v4%20n3%20Jun%201986/page/7/mode/1up
    5 REM Typed by Tim Swenson
   10 REM ** Halley's Comet **
   50 CLS 
   60 CIRCLE 10,85,1
  100 FOR j=1 TO 6
  110 READ n$,p,r
  120 LET pz=p
  130 LET p=-p
  140 LET x=r*COS p+10
  150 LET y=r*SIN p+85
  160 PLOT x,y
  170 IF p>pz THEN GO TO 200
  180 LET p=p+3/r
  190 GO TO 140
  200 PRINT AT 22-y/8,x/8;n$
  210 NEXT j
  220 DATA "E",3.14,7,"J",1.73,31,"S",1.48,58,"U",.82,116,"N",.49,180,"p",.37,234
  230 LET tz=0
  240 LET p=0
  245 PRINT AT 20,1;"It is ";1986;". Halley's comet is"
  250 LET p=p+.008
  260 LET t=12.12*(p-.9673*SIN p)
  270 IF t>tz+1 THEN GO TO 290
  290 LET x=107.4*(.9673-COS p)+10
  300 LET y=27.2*SIN p+85
  302 IF p>6.28318 THEN STOP 
  304 LET d=15.6E6*SQR ((x-10)*(x-10)+(y-85)*(y-85))
  306 PRINT AT 21,1;d;" miles from the sun"
  310 PLOT x,y
  312 IF t>tz+1 THEN GO TO 320
  315 GO TO 250
  320 PRINT AT 20,7;tz+1987
  330 LET tz=tz+1
  340 GO TO 250

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top