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

String Art

Craig Maiman
Spring Valley, NY

If you always wanted a program which generates beautiful mathematical patterns, now you have it. This program serves very well to impress friends (and yourself!) with the graphics capabilities of the Atari 400/800.

The program actually generates two lissajous figures that are TWISTed relative to each other, it then draws lines between them. The variables that determine the shape of the lissajous are FREQUENCY RATIO and PHASE. Since a lissajous pattern is generated by two signals perpendicular to each other, as on an oscilloscope, we can specify their frequency ratio to obtain many different figures. Changing the phase makes the pattern seem to rotate in 3-D space. An example would be a circle which has a frequency ratio of one-to-one and a phase of 0 degrees. If you now change the phase to 45 degrees it will look like a tilted ellipse. Another variable which can be controlled is DISPLACEMENT: this variable determines the vertical separation of the two lissajous patterns. It can be varied between 0 and 95.

Here are some numbers to generate nice patterns:

FREQUENCY RATIO: 1, 1
PHASE: 40
TWIST: 135
DISPLACEMENT: 0
FREQUENCY RATIO: 2, 1
PHASE: 0
TWIST: 60
DISPLACEMENT: 0
FREQUENCY RATIO: 1, 2
PHASE: 45
TWIST: 120
DISPLACEMENT: 70

Hints

  1. Good numbers for the FREQUENCY RATIO are various combinations of 1,2, and 3. Higher numbers tend to make messy pictures.
  2. For PHASE, 0 and 90 are good numbers, but try numbers in between also.
  3. The TWIST can be varied from—180 to 180. Try them all if you want.
  4. DISPLACEMENT can vary between 0 and 95. When you get near 90 all the pictures start looking the same. For starters, I would recommend using 0 then try 20, 30, etc.

Now to reveal the secrets of the program:

Lines   Description
20-40   Screen initialization (Put String… in inverse video)
50-80   Prompts for input (Put these in inverse video)
90      Tests for illegal displacement
130-140 Initializes screen for GRAPHICS 8
160-170 generates first lissajous
180-190 generates second lissajous
200     plots and connects the 2 lissajous
210-220 tests for key touch
10 REM STRING ART ! BY CRAIG MATMAN, JULY, 1981
20 GRAPHICS 0 = SETCOLOR 1,3,10: SETCOLOR 2,3,0
30 SETCOLOR 4,6,0 = H = 95 : POKE 752, 1
40 ?" | STRING ART PROGRAM  |"
50 ? :?  :? " | INPUT FREQUENCY RATIO |"
;: INPUT A, B
60 ?  :?  :? " | INPUT PHASE |" ; : INPUT PH
70 ?  :?  :?  "| INPUT TWIST I" ; : INPUT TW
80 ?  :?  :? " | INPUT DISPLACEMENT |" ; : | INPUT DI
90 IF DI> 95 THEN 80
100 ? :?  :? "| WHEN PICTURE IS DONE HIT |"
110 ? " | ANY KEY TO CONTINUE  |"
120 FOR D = 0 T0 TO 680 : NEXT D
130 DEG : GRAPHICS 24 : SETCOLOR 1,3,10
140 SETCOLOR 2, 3, 0 : SETCOLOR 4, 6, 0 : COLOR 1
150 FOR ANG = 0 TO 360 STEP 5
168 X1 =  H * SIN (A * ANG) + 159
170 Y1 = (H - DI) * COS (B * ANG + PH) + 96 - DI
180 X2 = H * SIN (A *(ANG + TW)) + 159
190 Y2 = (H -DI)* COS (B*(ANG + PH + TW)) + 96 + D1
200 PLOT X1, Y1 : DRAWTO X2, Y2 : NEXT ANG
210 IF PEEK (764) <> 255 THEN POKE 764, 255 : GOTO 20
220 GOTO 210