Biorhythms

This file is part of and Timex Sinclair Public Domain Library Tape 2004. Download the collection to get this file.
Date: 1983
Type: Program
Platform(s): TS 2068

This program calculates and plots biorhythm cycles for a given person based on their date of birth and the current date. It computes the elapsed days since birth and then graphs all three classical biorhythm cycles — physical (23 days), mental (28 days), and emotional (33 days) — as sine waves on the ZX Spectrum’s high-resolution graphics display. Each cycle is drawn in a different INK color (blue for physical, red for mental, green for emotional) using a bitwise color-selection trick inside the PLOT statement. The x-axis tick marks at multiples of a variable B (which appears uninitialized in the listing, likely intended to be set to approximately 8–9 pixels per day) indicate day boundaries across the current month.


Program Analysis

Program Structure

The program is organized into a small number of functional phases:

  1. Initialization (lines 5–8): Clears the screen, sets a random border color, and prints a title.
  2. Input (lines 10–20): Collects date of birth (day, month, year) and the current month and year.
  3. Age Calculation (line 30): Computes t, the total days elapsed since birth.
  4. Axis Drawing (lines 800–840): Draws a horizontal baseline and tick marks, then prints axis labels and a color-coded legend.
  5. Curve Plotting (lines 900–1040): Iterates over the three biorhythm periods from the DATA statement and plots each as a sine wave.
  6. Repeat Prompt (line 1050): Offers to restart; branches to line 1 (non-existent), which will trigger an error — this is a known technique effectively acting as a full restart via the error handler, but more likely a typo for GO TO 6 or GO TO 5.

Date and Phase Calculation

Line 30 computes the elapsed days as:

t = INT(((e-c)*365.25) + (d-b)*30.35) - a

where c/e are birth/current year, b/d are birth/current month, and a is the birth day. The constants 365.25 and 30.35 are reasonable approximations for average year and month lengths. Subtracting the birth day at the end correctly offsets the day-of-month component.

Line 910 computes the current phase angle for each cycle period u:

l = 2*PI*(t - INT(t/u)*u) / u

The expression t - INT(t/u)*u is a manual modulo operation (equivalent to t MOD u), giving the number of days into the current cycle, scaled to a radian angle.

Sine Wave Plotting

Line 1000–1020 plots each wave. The x-coordinate formula (a-l)*(35-28+u) maps the angular parameter to a screen x-position. Since u cycles through 23, 28, and 33, the factor (35-28+u) evaluates to 30, 35, and 40 respectively — this scales each cycle so it occupies a consistent horizontal span regardless of period length, essentially normalizing the display width per cycle. The y-coordinate is 90 + SIN(a)*60, centering the wave at pixel row 90 with an amplitude of 60 pixels.

Line 920 computes k = 2*PI*(33-u)*0.03, which produces a small angular offset used as the loop upper bound k+l+(2*PI) in line 1000. This extends the plot slightly beyond one full cycle for the shorter-period curves, though the practical effect is minor.

Color Selection Technique

The INK attribute in the PLOT statement on line 1010 uses a compact bitwise boolean expression:

INK ((1 AND u=23) + (2 AND u=28) + (4 AND u=33))

In Sinclair BASIC, AND with a boolean condition returns the left operand if true and 0 if false. Exactly one of the three terms is non-zero on each pass of the outer loop, selecting INK 1 (blue), INK 2 (red), or INK 4 (green) for the physical, mental, and emotional cycles respectively.

Bugs and Anomalies

  • Uninitialized variable B (line 815): The tick-mark condition IF r=INT(r/B)*B uses B, which is never assigned in the listing. If B is zero or unset (defaulting to 0 in Sinclair BASIC), this will cause a division-by-zero error. It was almost certainly intended to be a constant such as 8 or 9, representing pixels per day.
  • Input asks for current Day omitted: Line 20 only inputs current month (d) and year (e), not the current day. The calculation in line 30 therefore computes age only to the nearest month, which may introduce up to ~30 days of error in the phase angles.
  • GO TO 1 (line 1050): Line 1 does not exist in the listing. Branching there will cause an error rather than restarting cleanly. The intended target was likely line 6 or line 5.
  • Typo in SAVE name (line 9999): The program is saved as "Biorythm" (missing an ‘h’), while the REM at line 5 spells it correctly as “biorhythms”.
  • Variable reuse: a is used both as the birth day input (line 10) and as the loop variable in the sine-wave plotting loop (line 1000), overwriting the original value. This is harmless since a is no longer needed after line 30.

Data

CyclePeriod (days)INK color
Physical231 (Blue)
Mental282 (Red)
Emotional334 (Green)

Content

Appears On

One of a series of library tapes. Programs on these tapes were renamed to a number series. This tape contained

Related Products

Related Articles

Related Content

Image Gallery

Biorhythms

Source Code

    5 REM biorhythms by J. Clark    from SINCLAIR USER ANNUAL-83
    6 RESTORE : CLS 
    7 BORDER RND*8
    8 PRINT AT 0,0;"        BIORHYTHMS              "
   10 INPUT "Enter Date of Birth (numerical)","Day ";a;"  Month ";b;"   Year ";c
   20 INPUT "Enter Date Now (numerical)","Month ";d;"   Year ";e
   25 CLS 
   30 LET t=INT (((e-c)*365.25)+(d-b)*30.35)-a
  800 FOR r=0 TO 255
  810 PLOT r,10
  815 IF r=INT (r/B)*B THEN FOR u=10 TO 20: PLOT r,u: NEXT u
  820 NEXT r
  830 PRINT AT 21,0;"1st     10th      20th      30th"
  840 PRINT AT 0,0; INK 1;"physical  "; INK 2;"mental  "; INK 4;"emotional"
  900 FOR r=1 TO 3
  905 READ u
  910 LET l=2*PI*(t-(INT (t/u)*u))/u
  920 LET k=2*PI*(33-u)*.03
 1000 FOR a=l TO k+l+(2*PI) STEP .1
 1010 PLOT INK ((1 AND u=23)+(2 AND u=28)+(4 AND u=33));(a-l)*(35-28+u),90+SIN a*60
 1020 NEXT a
 1030 NEXT r
 1040 DATA 23,28,33
 1050 INPUT "Again (y/n)? ";a$: IF a$(1)="y" OR a$(1)="Y" THEN GO TO 1
 9998 STOP 
 9999 SAVE "Biorythm" LINE 1

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

People

No people associated with this content.

Scroll to Top