6

Bicycle wheel


One of the most useful facilities on the BBC Micro is the ability to change any logical colour at will, with the VDU19 command. By switching chosen colours from black to, say, yellow and black again, we can give the illusion of rapid motion, which is precisely what this program does.
   We chose Mode 1 for the higher definition that it gives us. This mode allows four colours on the screen at once, but we will be using only two while the bicycle wheel is spinning; these will be black and yellow. Remember, however, that although only four are allowed, we still have a genuine eight to play with.
   The *FX9,0 command has the same effect as *FX10 mentioned previously; that of making the flashing colours steady. Line 40 places the origin of the graphics in the centre of the screen and then we call PROCPOLY 15 times. PROCPOLY draws a large central hexagon and is well worth saving for other purposes. The hexagon is outlined and then each point is connected to every other point. Each hexagon is drawn a different colour, although (again) it is worth noticing that because Mode 1 allows only four, the appearance at this stage is of overlapping hexagons in red, yellow and white. Internally, however, BBC BASIC considers them as all different.
   When the hexagons are drawn, the REPEAT-UNTIL loop of lines 80-140 is entered, with UNTIL 0 signifying 'for ever'. At each pass through the loop we have another FOR-NEXT loop inside it, which switches the sequence colour on at line 100 and off at line 120. Line 110 provides a tiny delay of three one-hundredths of a second. The effect of all this is a most convincing impression of a bicycle wheel revolving rather smartly. Try altering the bracketed value of line 110 for a faster or slower effect, but if you speed it up too much, the image does not have time to form completely before it is wiped out, and so becomes less satisfactory and may even disappear altogether.

Variables

X(0) to X(5)X,Y co-ordinates of each of the 6 points
Y(0) to Y(5)of the hexagon currently being drawn
XGeneral counter
KA dummy
RThe radius of the polygon
CColour of polygon
BIASAngle of twist (in radians)
AAngle in radians
PIBASIC standard variable for pi (surprise!)
LCounter for the chords connecting points

   10 REM Bicycle wheel
   20 DIM X(5),Y(5)
   30 MODE1:*FX9,0
   40 VDU29,600;500;
   50 FOR X=1 TO 15
   60 PROCPOLY(500,X,X*15)
   70 NEXT
   80 REPEAT
   90 FOR X=1 TO 3
  100 VDU19,X,3,0,0,0
  110 K=INKEY(3)
  120 VDU19,X,0,0,0,0
  130 NEXT
  140 UNTIL 0
  150  
  160 DEFPROCPOLY(R,C,BIAS)
  170 GCOL0,C
  180 FOR SIDE=0 TO 5
  190 A=SIDE*2*PI/5+BIAS
  195 X(SIDE)=R*COSA:Y(SIDE)=R*SINA
  200 NEXT SIDE
  210 FOR SIDE=1 TO 5
  220 FOR L=SIDE TO 5
  222 MOVE X(SIDE),Y(SIDE):DRAW X(L),Y(L)
  224 NEXT L
  230 NEXT SIDE
  240 ENDPROC