A Very Moving Experience|Sean McManus and Amstrad Computer User)Coding Listings

Basic Animation is the game; Sean McManus is the name.  Read on and pick up some important programming tips.

London by night - this is all you need to have seen to have the tools at your disposal for fast BASIC animation. But let's start with something simpler: junior school education.

Most of us have fond memories of making cartoons at school, by drawing two slightly different pictures, and then flicking rapidly between them. This is, in effect, two-frame animation - a cartoon made from two static pictures. To simulate this on the CPC we have to be able to 'flick' between two images on screen instantaneously. At this point, machine code programmers generally grin smugly, fold their arms and watch their BASIC counterparts wallow in failure.

The problem is that BASIC takes too long to draw a frame. Certainly any design worth animating would take at least several seconds to draw, shattering the illusion of motion. Perhaps we're approaching the problem the wrong way...

In mode 0 Oct's use this mode - the reason will become obvious later), you can have 16 different colours, including the 'background', from a possible 26, on screen at any given time. Pens are used to draw, and the pens are filled with INKS, using the INK command. If you're not familiar with these commands, now would be a very good time to reach for the manual. Pens can be made to flash by assigning two inks to them. The computer will automatically alternate the inks -changing all the occurances of the pen wherever it is on the screen. Instantaneously. Problem solved!

So, we can make the computer do our 'flicking' for us, by drawing our two images in different pens, and assigning the inks to flash. For example, if we have two frames, one drawn in pen one and the other drawn in pen two, we might assign the inks as follows:

INK 1,26,0:INK 2,0,26

This assumes that 0 is the background colour. Pen 1 will be 26 (bright white), while pen 2 is the background colour (hidden) .Then, pen 2 will become visible, as pen 1 is hidden. This 'flicking' between the images will continue until stopped, in the background of whatever else is happening.

Try DEMO I. It shows several animated jugglers. Upon running, you will be able to see the design as it appears in the default inks. Press any key to start. Parts of the design that are common to both frames are drawn in a pen which does not flash - it remains the same colour in both frames. As the scrolling message says, once the design is drawn, the computer can get on with other business, without interrupting the animation. The speed of the animation can be altered using the SPEED INK command. Can you imagine how painful it would have been to write this fairly simple demo without colour swapping?

10 ' Juggler - colour switching DEMO I
20 ' (C) 1991 Sean McManus
30 '
50 DATA EEEEFFFFEEEEFFFF0,00EEEEFFEEFFFF000,0000EE4444FF00000,00000044440000000,00000066660000000,0000AA88BB9900000,99AA00BB880099AA0,99AA0088660099AA0,00660066BB0066000,00006666666600001,00000077770000001,00000077770000001,00000077770000001
60 DATA 00003322222200001,00000033220000001,00000033330000000,0000000000000000E
70 CALL &BC02:x(0)=100:x(1)=500:y(1)=300:y(0)=100:MODE 0:RESTORE 50:FOR y=1 TO 16:READ a$:FOR x=1 TO 16:FOR a=0 TO 1:FOR b=0 TO 1:PLOT x*4+x(a),y*4+y(b),VAL("&"+MID$(a$,x,1)):PLOTR 0,2:NEXT b,a:TAG:MOVE 190+x*16,80+y*16:PRINT CHR$(143);:TAGOFF:NEXT x,y
80 SYMBOL 255,48,254,22,60,116,210,254,16:PEN 1:LOCATE 20,25:PAPER 0:PRINT CHR$(255);
90 PRINT CHR$(23)CHR$(1);:DEG:TAG:a$="Juggle":FOR g=1 TO LEN(a$):FOR i=12 TO 13:PLOT -10,-10,i:MOVE 310+200*SIN(g*15+315)+RND*20,160+200*COS(g*15+315)+RND*20:PRINT MID$(a$,g,1);:NEXT i,g:TAGOFF
100 CALL &BB06:INK 15,10,3:INK 14,3,10:INK 3,15:INK 2,6:INK 7,24:INK 8,26,2:INK 11,2,26:INK 9,2,3:INK 10,3,2:INK 0,3:INK 4,10:INK 13,24,3:INK 12,3,24:BORDER 3
110 a$="This Juggler is now animating himself in the background - the only processing is this scrolling message. ":WHILE 1:FOR g=1 TO LEN(a$):LOCATE 2,23:PRINT MID$(a$+a$,g,17);:NEXT:WEND

Whilst 'Roland on the Ropes' was deemed trendy in its day because the words flashed different colours between loading blocks, we now know how to do some very interesting interblock animations, without too much effort.

But all this only allows for two-frame animation. Let's return to London (yes, wondering about that, weren't you?): Piccadilly Circus by night and its towering facades of neon advertising. Very effective. Yet, each individual panel is quite simple. Shaped tubes are lit and unlit, in sequence. This does not sound dissimilar to an approach we can adopt for animation on the CPC. Our tubes become lines and shapes, and our lighting is achieved by colour swapping. In Mode 0 we have 15 different colours (potential frames) at our disposal.

Enter Demo II. An animated Jack in the Box - a potential nightmare in BASIC - becomes quite simple by applying our'neon logic'. Upon running, inks (= frames) one to five are set to the background colours, to hide them while they are being drawn. Pen 8 is used to display a 'Please Wait' message, and our two-frame animation comes into its own with the little metronome that ticks away in front of us while the computer busies it self with the jack drawing. Each jack takes about 20 seconds to draw -well beyond the limit of normal animation. As it now stands, FOR-NEXT loops have been used to SLOW down its bounce! Note the technique of hiding a design in progress, to preserve its impact with spontaneity. Press any key to launch Jack, and another key to recall him. Repeat until bored, and then break. At the end, all the inks will be reset, revealing all frames.

10 ' Jack in the Box - DEMO II
20 ' (C) 1991 Sean McManus - 24th September
30 '
40 ON BREAK GOSUB 120:MODE 0:SYMBOL 255,48,254,22,60,116,210,254,16:PEN 13:LOCATE 20,25:PAPER 0:PRINT CHR$(255);:INK 13,23
50 x=320:y=300:BORDER 0:INK 0,0:INK 8,20:LOCATE 1,9:PEN 8:PAPER 0:PRINT"Please":PRINT" Wait":FOR g=1 TO 5:INK g,0:NEXT:PLOT 50,100,8:DRAWR 50,0:DRAWR 0,10:DRAWR -20,70:DRAWR -10,0:DRAWR -20,-70:DRAWR 0,-10:FOR g=1 TO 6:PLOT 74,130+g*6:DRAWR 4,0
60 NEXT:PLOT 105,162:DRAWR -30,-42,14:DRAWR -30,42,15:INK 15,20,0:INK 14,0,20:SPEED INK 15,15:FOR loop=5 TO 1 STEP -1:x=320:y=440-loop*50:a=loop*14:PLOT 270,100,loop:DRAW 270+50*SIN(280+a),100+50*COS(280+a):PLOT 380,100,loop
70 DRAW 380+50*SIN(90-a),100+50*COS(90-a):PLOT x,y:DRAWR -5,-5:DRAWR -20,-50:DRAWR 5,-5:DRAWR 51,0:DRAWR 5,5:DRAWR -20,50:DRAWR -5,5:DEG:FOR g=0 TO 2:FOR h=1 TO 360 STEP 40:PLOT x+5*SIN(h)+5,y+5*COS(h)-g*20:DRAW x+8*SIN(h)+5,y+8*COS(h)-g*20:NEXT h,g
80 PLOT x+30,y-60:FOR g=90 TO 270 STEP 5:DRAW x+35*SIN(g)+5,y+25*COS(g)-90:NEXT:DRAW x-22,y-60:PLOT x-15,y-120:DRAWR 40,0:FOR g=1 TO 2:PLOT x-45+g*20,y-140:DRAWR 10,20:DRAWR 10,-20:NEXT:DRAWR 10,20:DRAWR 10,-20:DRAWR -60,0
90 PLOT x-30,y-140:DRAWR -10,10:DRAWR -50,30:DRAWR -20,-15:DRAWR 70,-30:DRAWR 10,-10:DRAWR -10,-50:DRAWR 10,-10:DRAWR 70,0:DRAWR 10,10:DRAWR -10,50:DRAWR 10,10:DRAWR 70,30:DRAWR -20,15:DRAWR -70,-40
100 FOR g=1 TO 360 STEP 16:PLOT x+10*SIN(g)+120,y-100+10*COS(g):PLOT x+10*SIN(g)-110,y-100+10*COS(g):NEXT g,loop:FOR g=1 TO 100 STEP 2:PLOT 0,g:DRAW 270,g,0:DRAWR 110,0,7:DRAWR 150,0,0:NEXT:INK 7,24:WINDOW #1,1,6,1,25:PAPER 0:CLS #1:LOCATE 1,22:PEN 10
110 PRINT"Press":PRINT"Any Key":WHILE 1:INK 10,6:CALL &BB06:INK 10,0:FOR g=5 TO 1 STEP -1:INK g,26:FOR h=1 TO 120-g*15:NEXT h:INK g,0:NEXT:INK 1,26:CALL &BB06:FOR g=1 TO 5:INK g,26:FOR h=1 TO 80:NEXT h:INK g,0:NEXT:WEND

The Jacks are drawn from bottom to top, since they overlap and the top one must be the best. It is possible to plot the crossover points in a pen that is lit in both frames, and allow special programming for this. (See DEMO I's 'Juggle' text.) For an animation of this speed, it's hardly worth it.

These two programs demonstrate the power at the Basic programmer's fingers when he Thinks Neon' and uses colour swapping to bring screens alive.

Now, it's up to you. Work on your own designs, or pick and change on the two demos we've looked at here. If you're happy with the result, why not send it in to ACU for the crew to have a look at. The best piece of simple animation will be rewarded with a special ACU certificate, to boot.

So, get programming and let's see those demos soon.


★ PUBLISHER: Amstrad Computer User
★ ANNÉE: 1991
★ AUTHOR: Sean Mcmanus

CPCrulez[Content Management System] v8.7-desktop/cache
Page créée en 144 millisecondes et consultée 578 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.