Ball (GTIA Demo)

Type
Graphics
Category
GTIA colour-cycling demo
Author
Unknown (early GTIA demonstration program, author not identified in the book)
Published in
The Creative Atari (Creative Computing Press, 1983), "Design Philosophy and GTIA Demos"
Year
1983
Language
Atari BASIC
Requirements
GTIA chip (any XL/XE or later 400/800); 16K RAM; Atari BASIC
A sphere made of vertical colour stripes in GRAPHICS 10

About the program

The demos come from the "Design Philosophy and GTIA Demos" chapter of The Creative Atari. The column's writer explained that Atari had started fitting the new GTIA chip to all Atari 800s in January 1982, and that the chip added three graphics modes. He didn't know who had written these little demonstration programs. He guessed they came from somebody at Atari with an early sample of the chip, and he asked the author to get in touch so that he could give credit.

Ball draws a sphere made of vertical "meridian" stripes, like a beach ball seen side-on. Each ring is two-tone, with one colour on one side and the next colour on the other. When it is drawn, the program shuffles which colour sits in which register, so the stripes march across the ball and it seems to spin on its axis. Unlike several of the other demos in the chapter, it needs no machine code. The colour cycling is done in BASIC.

What you need

  • A GTIA machine: any XL/XE, a 400/800 built from 1982 on, or an emulator such as Altirra. CTIA machines run the program but show the wrong colours.
  • 16K RAM, Atari BASIC.

Typing it in

The listing is plain ASCII. The seventh value in line 116 is 3 in this listing, but 9 on the original printed page. The values are hue numbers, so either one runs. With 9 you get eight different hues instead of a repeat. DIM D(LIM,2) sits in the middle of line 118. That is legal, because Atari BASIC allows DIM anywhere as long as it runs before the array is used.

How to use it

RUN it. Drawing takes a little time. Then the ball spins until you press BREAK.

How it works

  • Line 115 turns each DATA value into value*16+8 (hue × 16, luminance 8) and stores it both in the registers and in the array C(). The first value, −.5, works out as 0, so the background is black.
  • Lines 118–120 build a 22-step sine/cosine table in D().
  • Subroutine 2000 draws ellipses that all have the same height (60) but get narrower as R grows ((30-R)*0.6). Nested ellipses like that look like the lines of longitude on a globe.
  • Lines 1005–1030 group the rings into bands of increasing width. Line 1020 changes colour halfway round each ellipse (IF V>=LIM/2), so the front and back halves of a band differ.
  • Lines 490–520 copy the eight stored colours into registers 705–712, each time starting one register further along. The pattern rotates one step per pass, and the eye sees it as rotation of the ball. POKE 77,0 stops the attract mode.

Variations to try

  • Change the luminance (+8) in line 115 for a darker or brighter ball.
  • Put a short delay loop into line 520 to slow the spin.

Listing

100 REM GTIA TEST
115 DIM C(8):GRAPHICS 10:FOR Z=704 TO 712:READ R:R=R*16+8:C(Z-704)=R:POKE Z,R:NEXT Z
116 DATA -.5,1,3,4,5,7,3,12,13
118 LIM=22:T2=3.14159*2/LIM:COL=3:E1=1:DIM D(LIM,2)
120 GOSUB 1500:FOR V=1 TO LIM:T=T+T2:GOSUB 1500:NEXT V
400 GOTO 1000
490 REG=705
500 FOR X=1 TO 8:POKE REG,C(X):REG=REG+1:IF REG>712 THEN REG=705
510 NEXT X:REG=REG+1:IF REG>712 THEN REG=705
520 POKE 77,0:GOTO 500
1000 REM
1005 FOR E=1 TO 10:E2=INT(E/2-0.5)
1010 FOR R=E1 TO E1+E2:CR=8-COL:IF CR=0 THEN CR=8
1015 V=0:COLOR CR:GOSUB 2000:PLOT X,Y
1020 FOR V=1 TO LIM:T=T+T2:GOSUB 2000:DRAWTO X,Y:IF V>=LIM/2 THEN COLOR COL
1025 NEXT V:NEXT R:COL=COL+1:IF COL=9 THEN COL=1
1030 E1=E1+INT(E/2+0.5):NEXT E
1200 GOTO 490
1500 D(V,1)=SIN(T):D(V,2)=COS(T):RETURN
2000 X=(30-R)*0.6*D(V,1)+40:Y=60*D(V,2)+80:RETURN

Credits