The last lesson drew ten bars once. This program keeps drawing: a counted loop places eighty circles, and an outer loop repeats that work with changing positions. You’ll separate the work that draws a picture from the change that makes it move.
What you’ll see by the end
The circles overlap, so you won’t necessarily be able to count eighty distinct outlines in a still image. The loop bounds tell you how many Circle calls each update makes. Left-click to stop in the mouse-port setup used here.
The whole program
; Redraw eighty circles using two alternating bitmaps.
VWait 100
BLITZ
BitMap 0,320,256,3
BitMap 1,320,256,3
Slice 0,44,3
t.f = 0
db = 0
While Joyb(0) = 0
VWait
Show db
db = 1-db
Use BitMap db
Cls 0
For i = 0 To 79
x.w = 160 + Sin(t + i*0.4)*140
y.w = 128 + Cos(t*0.8 + i*0.27)*110
Circle x, y, 7, 2+i/20
Next
t = t + 0.04
WendThe opening VWait 100 gives Workbench time before entering BLITZ mode, as in the earlier lessons. The two BitMap lines create separate 320×256 drawing areas. A depth of 3 gives eight colour slots, numbered 0–7. Slice sets up the display through which a bitmap is shown.
Load and compile it
Use the first lesson’s plain-text import procedure with a new file called many.ab3. Keep its three-line RuntimeDebug = 0 settings header and put this listing below it. In PED, choose Compiler → Compile & Run, or press right-Amiga+#. Right-Amiga+X cuts text in PED.
Check that the circle pattern changes position over time. Press and hold the left mouse button until it finishes; press Return if AmiBlitz shows its termination prompt. Joyb(0) reads buttons on port 0, the mouse port in this setup. While no button is pressed it returns zero, so While Joyb(0) = 0 keeps repeating. You do not need to reset the Amiga to stop this program.
The Blitz BASIC 2.1 manual, “Joyb”, printed p. 108, describes those button values.
One loop draws; another repeats the update
The inner loop runs from i=0 through i=79, including both ends: 80 passes. Each pass calculates a position and draws one circle of radius 7. The final argument chooses its colour.
The button is checked between updates, so a brief click can be missed while the program is drawing.
The outer While … Wend loop checks the button, shows a bitmap, chooses the other one for drawing, clears it, draws the eighty circles, and advances t. Then it checks the button again.
These are calculated positions, not eighty stored records. Each pass works out a circle afresh from i and t.
Where the positions come from
x.w = 160 + Sin(t + i*0.4)*140
y.w = 128 + Cos(t*0.8 + i*0.27)*110Sin and Cos turn an angle into a value between −1 and 1. Blitz uses radians, another way of measuring angles. You can use these expressions now without learning trigonometry first.
160and128put the movement around the middle of the bitmap.- Multiplying by
140and110sets how far positions vary horizontally and vertically. - The terms using
igive each circle a different place in the pattern. t.fholds a fractional value. Adding0.04after each drawing pass advances the pattern for the next update. The.wvariables hold whole-number coordinates for drawing.
The manual’s “Sin” and “Cos” entries, printed p. 113, specify radians. The motion comes from changing t; the circle loop alone would draw the same picture repeatedly.
Two bitmaps, two jobs
Double buffering means showing one bitmap while drawing into the other. Trace the four lines in their actual order:
Show db
db = 1-db
Use BitMap db
Cls 0db starts at 0. Show uses its current value; the assignment then switches 0 to 1, or 1 to 0. Use BitMap selects that other bitmap for drawing, and Cls 0 clears only the selected drawing bitmap.
| Update | db before Show |
Bitmap shown | Bitmap cleared and drawn |
|---|---|---|---|
| First | 0 | 0 | 1 |
| Second | 1 | 1 | 0 |
| Third | 0 | 0 | 1 |
The first update draws the first circle picture into bitmap 1. The second shows that picture while drawing the next into bitmap 0. Later updates keep exchanging the jobs. Clearing before drawing removes the old circle positions from the bitmap being reused.
If you delete db = 1-db, which bitmap does the first update show and draw into?
Show the explanation
Both jobs use bitmap 0. The program would clear and draw the bitmap it is showing, losing the separation. Restore the assignment before compiling: the useful rule is that the shown bitmap and drawing bitmap must differ on every update.
This sequence follows the manual’s double-buffer example, printed pp. 85–87. It avoids displaying the intermediate drawing work; it does not guarantee a particular update rate on every machine.
Try this: freeze the pattern
Change only t = t + 0.04 to t = t + 0. Predict what happens, then compile and run.
Why does the picture stop moving even though you can still left-click to finish?
Show the explanation
t stays unchanged, so each pass calculates the same positions. The outer loop still shows, clears and redraws bitmaps, and still checks Joyb(0). A still picture does not mean execution has stopped.
Now use t = t + 0.01. Each update advances the angle by one quarter of the original amount. Run and observe the smaller changes, then restore 0.04. This changes the movement per update; the time between updates also depends on how long drawing takes.
Try this: more drawing work
First change Circle x, y, 7, 2+i/20 to Circle x, y, 7, 2 and run the original eighty-circle loop. All circles now use colour 2. Keep that fixed colour for the comparison: extending the original colour expression to larger i values would take it beyond this bitmap’s eight colour slots.
Then change only For i = 0 To 79 to For i = 0 To 199. Predict the number of drawing calls, compile, observe the pattern, and left-click to stop.
How much more circle-drawing work does each update request? Does that prove an update rate?
Show the explanation
There are 200 calls instead of 80: two and a half times as many. That count does not measure how many updates finish per second. Observe what your setup does; don’t assume it will keep the same timing. Restore To 79 and the original colour expression to return to the starting program.
VWait waits for a vertical blank between display refreshes. It cannot make the drawing finish within one refresh interval. Neither this recording nor a visual impression establishes a measured frame rate, or a speed comparison with AMOS. See the previous lesson’s timing explanation.
If it doesn’t work
- It stays still. Check the final assignment to
t. Use0.04for the original animation;0deliberately freezes the positions. - The bigger crowd has unexpected colours. Use the fixed colour
2before extending the loop. Keep the colour expression and the loop limit as separate experiments. - Left-click does not finish. Keep the button down until the next input check. Check that port 0 is configured as the mouse and that the emulator has received the input. Keep the
Joyb(0)condition intact. - Compilation fails around BLITZ or a graphics command. Check the imported file’s settings header and keep
VWait 100beforeBLITZ. Use the reported line to compare against the listing.
What you’ve learnt
The inner loop draws one picture; the outer loop repeats the update and checks input. Changing t changes the next picture. Two bitmaps separate display from drawing. More circles mean more work, while an update rate needs measurement on a named setup.
What’s next
Next — Slices and the Display — look more closely at how a bitmap reaches the screen.