Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
collision detection where the<br />
place the pixels will occupy next<br />
is teasted to see if it is possible to<br />
move there. A realistic rebound<br />
is programmed in rather than a<br />
straight reversal of course if a<br />
collision is detected.<br />
Lines<br />
Line <strong>graphics</strong> can be the most<br />
satisfying because they can be<br />
used to make up wire images of<br />
objects, giving a three dimen<br />
sional effect. That object can be<br />
moved realistically around the<br />
screen and even rotated around<br />
variour points. Wire images<br />
have been used in some com<br />
puter games but are probably<br />
best known in such applications<br />
as building and car design. The<br />
program in figure 3 is an example.<br />
These are the three main<br />
ways of producing <strong>graphics</strong> on<br />
most home computers and for<br />
tunately we have access to all<br />
three on the Sinclair Spectrum.<br />
It has to be said that the best<br />
animation on the Spectrum will<br />
be written using machine code<br />
rather than BASIC because<br />
machine code is a good deal<br />
faster. BASIC is easy to unders<br />
tand, and has b^en used in the<br />
examples here for clarity,<br />
though it can cause flickering<br />
and other odd eff3Cts and<br />
detra. t from the effect that you<br />
ire trying to achieve<br />
The actual process of anima<br />
non on computers is a good deal<br />
different from that using hand<br />
drawn images and film. A com<br />
puter really only undertands<br />
numbers, so that images shown<br />
have to be digitised to coordinates<br />
and these coordinates<br />
manipulated to produce new images<br />
in dillerent positions. Do<br />
that quickly enough and you<br />
have animation. In extreme<br />
cases a single drawing may be<br />
made and many different images<br />
made by mathematical<br />
manipulation. For example, an<br />
image may be made wider or<br />
taller by altering values along<br />
one axis, give a computer two<br />
images, one bigger than the<br />
other and the computer can be<br />
programmed to produce a new<br />
image between the two sizes —<br />
this is known as an in<br />
betweening. Animation implies<br />
change, so that images<br />
presented sequentially appear<br />
to move. The basis of animation<br />
involves a number of key<br />
elements that help produce the<br />
desired effect. The obvious is<br />
change in size or shape, others<br />
include change in speed, angle,<br />
colour, position and perspective<br />
- remember these are animation<br />
techniques and not computer<br />
techniques. We have all<br />
seen some really funny cartoons<br />
where some of the humour has<br />
been about the ability of a<br />
character or object to survive<br />
impossibly destructive situations<br />
for example holding a<br />
bomb when it goes off, being<br />
squashed flat or streched.<br />
Twist, skew, shear, bend and<br />
explode can all be used to great<br />
effect. Explosions seem to<br />
characterise the even popular<br />
arcade game and it is worth<br />
knowing how to do this.<br />
Bang!<br />
ZX COMPUTING DECEMBER/JANUARY 1985<br />
The basis of an explosion effect<br />
is that the image breaks up and<br />
moves apart from a central<br />
point. The image is initially chopped<br />
or minced into short lines or<br />
pieces and these move radially<br />
ZX CRAPHICS<br />
out from a central point. Most<br />
explosions are a variation of this,<br />
for example the bus of the exploded<br />
image can be made to<br />
tumble, flicker or leave trailing<br />
images as it moves apart. The<br />
image may be exploded into<br />
single pixels that change colour<br />
rapidly as they move outwards.<br />
A computer can generate useful<br />
sound effects to accompany<br />
this visual extravaganza which<br />
makes the whole process more<br />
effective.<br />
Manipulation in size is one<br />
technique that a computer can<br />
do quickly without the need for<br />
new images to be drawn, digitis<br />
ed and stored. It is simply a mat<br />
ter of arithmetic to alter the size<br />
of an object. For example<br />
characters can be made larger<br />
by scanning the character<br />
10 REM PIXEL GRAPHIC ANIMATION<br />
20 REM AND COLLISION DETECTION<br />
30 CLS<br />
40 REM DRAW BORDER<br />
50 FOR 1=1 TO 20: PRINT AT 1,1<br />
I"B": PRINT AT I,301<br />
60 NEXT I<br />
70 FOR 1=1 TO 30: PRINT AT 1,1<br />
PRINT AT 20,IJ B FL*<br />
80 NEXT I<br />
90 GO TO 220: REM MAIN PART<br />
100 REM PLOT SUBROUTINE<br />
110 PLOT X,Y<br />
120 PAUSE 4<br />
130 RETURN<br />
140 REM UNPLOT SUBROUTINE<br />
150 PLOT OVER 1;X,Y<br />
160 RETURN<br />
170 REM COLLISION DETECTION<br />
180 REM SUBROUTINE<br />
190 IF POINT (X+XDIR,Y+YDIR)=1<br />
AND POINT (X+XDIR,Y+YDIR+1>-1 AN<br />
D POINT (X+XDIR,Y+YDIR-1)-1 THEN<br />
LET XDIR-XDIR*-1<br />
200 IF POINT (X+XDIR,Y+YDIR)-1<br />
AND POINT (X+XDIR+1,Y+YDIR>=1 AN<br />
D POINT (X+XDIR-1,Y+YDIR)-1 THEN<br />
LET YDIR"YDIR*-1<br />
210 RETURN<br />
220 REM MAIN LOOP<br />
230 LET X-70: LET Y-100: LET XD<br />
IR=--3. 1 : LET YDIR-1<br />
240 GO SUB 170: REM COLLIDED?<br />
250 GO SUB 110: REM PLOT<br />
260 GO SUB 140: REM UNPLOT<br />
270 LET X=X+XDIR<br />
280 LET Y=Y+YDIR<br />
290 GO TO 240 Figure 2<br />
square and reproducing the image<br />
larger or smaller. The pro<br />
grarne is figured four does this<br />
four one character and displays<br />
an image twice the size at a different<br />
place on the screen. It<br />
achieves this by scanning all the<br />
sixty four pixels in the character<br />
square and displaying them<br />
doubled up on both axis. It is a<br />
simple matter to adapt this program<br />
to reproduce a character<br />
that is stretched taller or wider<br />
by only adjusting the values on<br />
one or the other axis. This<br />
technique, because it works at<br />
the pixel level will also expand<br />
any shape. In BASIC it is rather<br />
slow, in machine code it is much<br />
faster and can be used to great<br />
effect.<br />
Perhaps the most exciting<br />
possibility for a home computer<br />
user is to make use of line<br />
<strong>graphics</strong> and produce a three<br />
dimensional representation of<br />
an object that can be rotated in<br />
any given direction and create<br />
some illusion of movement. The<br />
wire frame image depends on<br />
coordinate geometry to<br />
manipulate it, it is a matter of<br />
numbers and few rules. The big<br />
gest problem is that the television<br />
or other computer screen is<br />
only two-dimensional. Perhaps<br />
one day hologram technology<br />
will have advanced enough so<br />
that three-dimensional images<br />
can be projected into a living<br />
room like a super television, but<br />
until then we must rely on the<br />
eye being fooled by twodimensional<br />
trickery. Perspective<br />
drawings do this and the<br />
Renaissance artists were<br />
masters of the art and produced<br />
some remarkable paintings and<br />
drawings. The keys to such<br />
works of art is the 'vanishing<br />
point". Looking along railway<br />
lines, the tracks appear to converge<br />
at a point — this is a<br />
vanishing point. These drawings<br />
are made with reference to such<br />
a point which is often off the<br />
paper.<br />
3D<br />
In three-dimensional reality we<br />
can describe an object by<br />
reference to three axis- x,y andz<br />
as they are conventionally<br />
known. When measuring an object<br />
we normally described the<br />
dimensions in terms of length,<br />
width and height, but in order to<br />
describe an object in terms<br />
suitable for computer <strong>graphics</strong><br />
we must describe the object in<br />
distances from an origin point.<br />
The origin can be a corner of the<br />
object itself or further away, the<br />
object may be viewed from the<br />
origin or another point. This introduces<br />
the idea of how we can •<br />
I L