Sharp logo

MZ-800 course Chapter 7 
7. Graphical applications


7.5 Animations

What is an animation exactly?
An animation is a representation of reality on the computer, and this reality moves too, otherwise it would be a model.
To make a good animation, you need machine language for sure, you also need more memory than the SHARP has. The simplest animations can be done on the SHARP, like a rotating globe. This goes as follows:
First, the initial projection of the globe is drawn and stored in the memory. In this way, we can for example store five angles in the memory, but this of course depends on the size of the memory. When you think the rotations is smoothly enough, you write a machine language program that is fast enough to show the different angles of the globe in such a way that the globe appears to be rotating. If you have partitioned the angles well, the globe will be in its initial position after the sixth rotation and the cycle can be repeated until you are fed up with it.
Unfortunately, we can not show you this type of animation, because it requires a lot of work. In this chapter, we shall restrict ourselves to even more simple animations that can be made with the graphical instructions of the SHARP. With these programs, we try to illustrate what can be done in BASIC regarding animations.

Program 1: Train

An animation of a ’driving’ train. By doing something with the colours, it looks like the rails underneath the train are moving and it appears that the train itself is moving.

10 INIT "CRT:M1":PAL 2,7:PAL 3,7:PAL 1,0
20 FOR C=1 TO 39:READ A,B,A1,B1:LINE A,B,A1,B1:NEXT C
30 FOR C=1 TO 14:READ A,B,A1,B1:BOX A,B,A1,B1:NEXT C
40 FOR T=8 TO 296 STEP 32:BOX [2]T,161,T+12,165:BOX [1]T+16,161,T+28,165:NEXT
50 CIRCLE 115,147,9:CIRCLE 150,147,9
60 BOX [2]104,144,160,152:PAINT [0]105,145,2:BOX 104,144,160,152
70 OUT @$F2,$F5:OUT @$F2,$D9:T=10:LINE T,158,T,159:S=-150
80 WAIT 50:PAL 2,0:PAL 1,7:GOSUB 190
90 WAIT 50:PAL 2,7:PAL 1,0:GOSUB 190
100 GOTO 80
110 DATA 73,32,319,32,64,36,80,32,40,80,64,
36,40,80,40,122,64,152,40,122,64,152,96,152,
96,152,102,136,102,136,319,136
120 DATA 168,136,182,152,182,152,319,152,0,
157,319,157,0,160,319,160,314,64,319,64,314,
88,319,88,314,64,314,88,314,72,319,72
130 DATA 71,96,71,136,96,96,96,136,53,56,70,
60,70,60,64,86,64,86,40,80,59,48,319,48,199,
48,211,64
140 DATA 230,88,264,136,238,48,256,72,268,88,
304,136,255,48,266,64,285,88,320,136,295,48,
313,72
150 DATA 152,104,160,104,160,104,165,107,165,
107,171,107,171,107,167,111,171,107,168,104,
167,111,160,111,160,111,157,108,157,108,149,
108,149,108,152,104,149,108,152,111
160 DATA 144,64,184,88,200,64,240,88,256,64,
296,88,144,64,164,72,164,64,184,72,200,64,
220,72,220,64,240,72
170 DATA 256,64,276,72,276,64,296,72,104,64,
136,136,107,68,118,96,123,68,134,96
180 DATA 80,72,88,96,48,102,53,112
190 LINE [0]T,158,T,159:LINE [0]T+1,158,T+1,159:T=T+16:IF T>319 THEN T=0
200 LINE T,158,T,159:LINE T+1,158,T+1,159
210 LINE [0]S,158,S,159:LINE [0]S+1,158,S+1,159:S=S+16:IF S>319 THEN S=10
220 LINE S,158,S,159:LINE S+1,158,S+1,159
230 RETURN

Program 2: Rolling wheel

This program uses a piece of machine code to make the wheel roll. This could have been used in the previous program, but a train moves a bit faster than a normal wheel. Even with machine code, the train does not move very fast, but the rolling wheel is only just doable.

10 INIT "CRT:M1":PAL 0,7:PAL 3,0:PAL 2,0:XV=1
20 POKE $FD00,$DB,$E0,$3E,$83,$D3,$CC,$D3,
$CD,$21,$20,$9C,$E,$14,$37,$3F,$6,$4,$CB,
$16,$23,$10,$FB,$11,$24,$0,$19,$D,$20,$F0,
$DB,$E1,$C9
30 CIRCLE 10,190,9
40 FOR S=1 TO 14
50 FOR T=0 TO p STEP p/20
60 X=COS(T)*9:Y=SIN(T)*9
70 X1=COS(T+.5*p)*9:Y1=SIN(T+.5*p)*9
80 USR($FD00)
90 LINE [2,1]10-X+XV,190-Y,10+X+XV,190+Y
100 LINE [2,1]10-X1+XV,190-Y1,10+X1+XV,190+Y1
110 IF XV>0 AND XV/8=INT(XV/8) THEN POKE $FD09,PEEK($FD09)+1
120 XV=XV+1
130 NEXT T,S

Program 3: Walking men

By placing different motions of a puppet next to each other in different colours and by making a different colour visible each time, we can simulate a number of men walking behind each other.
This program does not require the extra ICs.

1 INIT "CRT:M1"
2 C=1:FOR A=1 TO 24:CIRCLE [C]A*12,160,5:C=C+1 :IF C=4 THEN C=1
3 NEXT A
4 C=1:FOR B=1 TO 23 STEP 2:LINE [C]B*12,165,B*12-3,180,B*12+3,190,B*12-6,197
:LINE [C]B*12-3,180,B*12,190,B*12-2,199
5 LINE [C]B*12+1,178,B*12-4,175,B*12,165,
B*12+1,174,B*12+5,177 :C=C+2 :IF C>3 THEN C=C-3
6 NEXT B
7 C=2:FOR B=2 TO 24 STEP 2:LINE [C]B*12,
165,B*12-5,192,B*12-15,189 :LINE [C]B*123,180,B*12+10,186,B*12+7,199
8 LINE [C]B*12-5,176,B*12-9,172,B*12-1,
167,B*12+4,175,B*12+11,172 :C=C+2 :IF C>3 THEN C=C-3
9 NEXT B
10 WAIT 1000
11 PAL 1,0:PAL 2,0:PAL 3,0
12 PAL 1,0:PAL 2,0:PAL 3,15:WAIT 100
13 PAL 1,15:PAL 2,0:PAL 3,0:WAIT 100
14 PAL 1,0:PAL 2,15:PAL 3,0:WAIT 100
15 GET A$:IF A$="" THEN 12
16 PAL 1,1:PAL 2,2:PAL 3,15:END

Program 4: Bouncing ball

By using a sinusoidal up and down movement with a decreasing amplitude and by using a normal sideways movement, we can simulate the movement of a bouncing ball.

1 INIT "CRT:M1":M=319:N=199:H=200:W=p/40
:D=90*p/180 K=.01:LINE 0,N,M,N
2 FOR O=0 TO M-10 STEP T:P=H*SIN(W*O+D)*EXP(-K*O) :P=N-ABS(P)-3
3 CIRCLE [0]X,Y-1,2 :CIRCLE O+10,P-1,2
:X=O+10:Y=P:IF Y>195 THEN NOISE "O1T7A1"
4 NEXT O

In this way lots of other movements can be simulated, like a driving car, the movement of an aeroplane and so on. The problem is, the movements do not resemble reality very well. The only solution is a program that is written entirely in machine code and uses all memory.

Previous page
Next page
Contents


Go to the top of this page Home

last updated February 4, 2008
Arjan Habing, Mark de Rover, Jeroen F. J. Laros, sharpmz@sharpmz.org