|★ CODING ★ LISTINGS ★ Colour swapping|Popular Computing Weekly) ★|
|Graphic - Colour Swapping|Popular Computing Weekly)||Coding Listings|
Colour swapping is a technique possible on machines such as the Amstrad and BBC that allows the colour of 'pens'that have been used to print or draw to be changed. On the Amstrad the technique works like this. Pens one to IS are used to draw - for instance - 15 adjacent, parallel lines. Then all Pens are filled with Ink the same colour as the Paper which in this case will be set to zero (let us say that this background is black). This means that all the coloured lines effectively disappear as far as the eye is concerned. However, they are actually still there but coloured black.
Now if the Ink in each Pen in turn is changed to, let us say, blue and then back to black again, a single line appears to move across the screen. If this process is now extended to pictures or various stages of a rotating shape then the result is very fast animation. The Lissajous Figures program is one which uses this colour swapping technique. The plotting can be speeded up by increasing the Step rate in Line 140, but the larger it gets the more the lines start to break up. The animation can be speeded up or slowed down by altering the 'wait' loops in Lines 230 and 270.
For this particular plot, as half of the pattern repeats itself going in the opposite direction it is possible to draw twice the amount of positions of the figure in half a cycle, and then step backwards through the colours in the animation section as well as forwards to complete the second half of the rotation. To see what I mean delete Lines 250 to 280 to see just half the cycle.
When using the technique two main things must be remembered. Firstly, whatever is plotted must only have 15 stages (although the Lissajous Figures program effectively has 30 because half of it is repeated). This is because 15 is the maximum number of Pens allowed in Mode 0 excluding one Pen for the Paper or background.
Secondly, if one part of a plotted shape is superimposed on another part of a previous shape in the previous Pen, then that part of the previous shape will be overwritten and lost, so try to avoid this. You can see what I mean from the early stages of the Figures program. The problem is more pronounced in Mode 0 where the pixels are bigger and more likely to overlap, so if the thing that you are animating can be done with a total of four Pens (including one background or Paper Pen) then use Mode 1.
The On Break Cosub statements in Line 60 and 300 are to prevent the program from being stopped and leaving the user with an unusable set of Inks -a common problem when breaking out of a program that uses colour swapping. The Call &BBFF resets the Pen Inks to default values. I found the Mode 1 command necessary because the machine code call appears to corrupt Mode 0 by mixing it with Mode 1. Delete the Mode 1 in Line 300 to see what I mean.
I leave you with the second program which I think is more impressive.