Classic Computer Magazine Archive COMPUTE! ISSUE 19 / DECEMBER 1981 / PAGE 108

Billiard Bounce

Kevin and Priscilla Laws
Carlisle, PA

This program was written initially to provide a graphic demonstration of two lessons on Billiard Ball Mathematics presented by Harold Jacobs in his delightful book entitled Mathematics: A Human Endeavor (Freeman, San Francisco, 1970). Once the program was entered, we discovered that we could spend hours watching wonderful patterns unfold before us. Floor designs, Navajo rugs, smooth and nubby fabrics can all be designed with a simple change of two inputs.

In the program, the path of a "billiard ball" is traced on a "table" with a horizontal length of 160 pixels and a vertical width of 96 pixels. The user inputs the horizontal and vertical distance the ball moves during each program step. (These inputs determine the angle at which the ball moves.) A background color and trace color are chosen at random during each run to prevent viewers from becoming tired of the color scheme.

When the program is run the Atari prints:

Angle Horizontal, Vertical?

The user then enters two numbers separated by a comma, such as 1,2 and presses the return key. Users will quickly discover that integers lead to fairly smooth patterns, large numbers to rapidly unfolding patterns, and decimal fractions to jagged lines. Some entries a novice user might like to try:

3.14159, 3.14159 (leads eventually to a waffle iron)
3.3, 7.7 (looks like a woven curtain
6.2, 6.3 a folksy looking fabric)
4.5, 6.3 (an indian rug)
3.4, 5.5 (a greek design)
2,9 (bedsprings!)

If a particularly interesting pattern appears before the design is complete it can be studied by pressing the "CNTRL" key and the "1" key simultaneously. Hitting these two keys again will allow the design process to continue.

The use of the GRAPHICS 7 + 16 mode allows the program to fit easily in an 8K Atari.

10 PRINT "Angle Horizontal, Vertical" : INPUT X1, Y1
20 GRAPHICS 7 + 16
30 COLR1 = INT(RND(0)*15) + 1 : SETCOLOR 4, COL R1, 10
40 COLR2 = INT(RND(0)*15) + 1 : SETCOLOR 0, COL R2, 5
60 X = X - X1 : Y = Y - Y1
70 IF ABS(Y)>95 THEN Y = 95
80 IF ABS(X)>159 THEN X = 159 : GOTO 100
90 GOTO 60
120 X = X - X1 : Y = Y - Y1
130 IF ABS(X)>159 THEN X = 159
140 IF ABS(Y)>95 THEN Y = 95
150 GOTO 110