Sunday, April 30, 2006

Animating with vectrex logo: first steps

This morning I have started to learn how to make animations using the vectrex logo program. It has been addictive- I didn't even notice I had spent as much time as I did on it (a sure sign of a good product).

One of the programs / patches / whatever I worked on is shown below. My aim was to draw a shape with 'tentacles' that expand or contract by rolling up or straightening.

I have coloured different areas of the structure to help with an explanation.

1. RED AREA: Initialising variables
line 1 glyphs: SET VAR (var 1 = 10)
Variable 1 is used for the angle of rotation on each element that makes up each tentacle in the animation.

2. BLUE AREA: Main program
line 2 glyphs: CLEAR SCREEN (lightspeed = on)
This is so that when the main program is looped, the drawing of each individual vector of each frame is not seen. Rather, each loop is seen as a completed frame.

line 3 glyphs: CALL PROC, CALC (var 1 = var 1 + 2)
Here, the green area is called. this is responsible for the actual drawing of the tentacles, an action that is repeated for each frame of animation. After calling the tentacle procedure, a new value for the angle of each element of the tentacle is calculated (and is two higher than in the previous iteration). The value for angle wraps around at 127.

line 4 glyphs: CALL PROC, REPEAT (27), RETURN
This final line of the main program pretty much just ties things up. First, a procedure is called (shown in yellow at the bottom of the diagram). This procedure sets the amount of pause seen in each frame, amounting to the speed of the animation. The whole process from line 2 (the first CLEAR SCREEN glyph) to line 4 is then repeated 27 times. The RETURN glyph signals the end of the main program.

3. GREEN AREA: First proc
line 5 glyphs: FORWARD (13), LEFT (var 1), REPEAT (5)
Contains the instructions for drawing a single tentacle. The turtle moves forward for 13 units, and turns left by the number of vegrees set by variable 1. By the way, 32 vegrees is equal to 45 degrees. The maximum rotation of one LEFT or RIGHT glyph is about 179 degrees (127 vegrees). These motions are then repeated 5 times, indicating the number of elements in each tentacle.

line 6 glyphs: HOME (rotation = on, turtle = invisible), RIGHT (32), REPEAT (8), RETURN
Here, the whole collection of tentacles comes together. First, the turtle travels home, so that the next tentacle will be drawn from the same origin as the previous one. Memory of rotation is kept, so that each tentacle will be drawn 1/8th of a full rotation from the previous one. Next, a 1/8th rotation (32 vegrees or 45 degrees) is performed, so that the next tentacle can be drawn. The process from lines 5 and 6 is then repeated 8 times. The RETURN glyph signals the end of this procedure.

4. YELLOW AREA: Second proc
line 7 glyphs: CLEAR SCREEN (lightspeed = off, don't clear screen = on), REPEAT(6), RETURN
The aim of this procedure is to slow down the speed of animation if it is too quick. First, the speed is slowed down from lightspeed (without the screen being cleared). This is required, since without this, the individual frames would not be seen (only the net result of loops and calculation). This step is then repeated a number of times, in effect pausing the frame. The RETURN glyph signals the end of this procedure also (suprise, suprise).

I know this is quite a simple logo patch. I have decided to write all this down, because it helps to clarify things in my mind. Next time I may take a little video of a vectrex animation...