|★ APPLICATIONS ★ CREATION GRAPHIQUE ★ Speed your grand designs ★|
|Pattern Fill (Computing with the Amstrad)||Applications Creation Graphique|
IAN SHARPE's pattern fill packs power into your graphics
TO make up for the lack of a fill facility on the CPC464 several routines have appeared here
and elsewhere, but all have one drawback - they only fill an area with a single colour, which hardly exploits the Amstrad's potential.
Now you can put some life into the graphics of any model of CPC with this enhanced routine which fills an area with a pattern of your own design. You can get superb results with this utility and it will become an essential part of your graphics toolkit.
Type in, save and run Program I. Move the graphics cursor to a point within the shape to be filled (use the MOVE command) and to fill the area:
where pw is the width of the pattern in pixels, pd is its depth and pat$ contains the pattern as detailed further on. Note the @ before pat$ - it is essential on the CPC464 but on the CPC6128 you can omit it or even call the routine like this:
As mentioned earlier, filling starts at the current graphics cursor position. The first thing the routine does is to look at the colour of the screen at this point. It will then fill all points connected vertically and horizontally until it meets another colour.
The fill pattern is stored in pat$. Ideally it would be stored in a rectangular array, but I couldn't find a simple way of passing this to a machine code routine short of poking its contents into a known area of memory. This would be slow, and not particularly convenient.
Imagine a pattern in a rectangular block composed of individual dots (or pixels), each with an ink number. In Mode 0 the maximum ink value is 15, in Mode 1 it can range from 0 to 3 and in Mode 2 it can be either 0 or 1.
As an example, let's assume the pattern to be two dots wide by three high. To store the pattern in a form that can be passed to the machine code, we write down the ink values of the dots in the top row followed by the values for the second and third rows, giving a list of six numbers.
So using the default colours when you switch on, if the top row was coloured yellow, red, the second row red, blue and the third yellow, blue pat$ would be 133212.
Follow that through - pen 1 is yellow, pen 3 is red, pen 3 again, pen 2 is blue and so on. If you're working in Mode 0 and want the inks 10 to 15 you must use hexadecimal format. In other words 10 is A, 11 is B up to F which is 15. Now all you need to do is:
pat$="133212" :CALL &9000,2,3,@pat$
If that sounds a bit too much like hard work, never fear, Program II is a utility to let you plot your pattern on a grid and generate the string afterwards. It's the minimum required to get you going and isn't too difficult to develop and improve. A string can be up to 255 characters long, but to keep things simple this designer only caters for 15 x 15 dots.
The first thing it will do is prompt you for the screen mode - 0, 1 or 2. Then you'll be presented with a box containing a flashing cursor which can be moved about with the arrow keys. Press the spacebar to plot a point and use Shift plus the up and down cursor keys to change the plotting colour.
If the box is bigger than your pattern, make sure you plot from the top left hand corner working to the right and downwards.
When you've done that, press Tab again. Now you'll be asked what you want to call the string - remember to type in the $ symbol after the name -for example fred$. This is going to be written as a two or three line program to a file so you'll be prompted for the first line number and the filename.
A line can be a maximum of 255 characters, so if the string with its name and line number is too long it'll be split on to an extra line. Also, the width and depth of the pattern are written to a REM statement. These lines can then be added to your own program by loading it into memory and using MERGE"filename"
Writing a pattern fill presents more problems than for a single colour. This routine is quite fast because it bypasses the firmware and deals directly with the screen memory. The price for this and keeping the program a manageable size is that there are a few rules and restrictions on how it can be used:
To avoid this you must obey a simple rule: At no point in the pattern must the background colour appear in a column of two or more pixels -remember the top and bottom rows fall next to each other when the pattern is repeated.
Be warned, if you ignore this your micro will lock up when you attempt a fill and the Escape key is not checked
You may also encounter this if you define a pattern in say. Mode 0, using colours that aren't available in Mode 1 and then use the pattern in Mode 1. Some of the illegal colours may turn out as the background colour and cause problems.
Another point to bear in mind when the background colour appears in the pattern: If there are a lot of pixels set to the background colour, you may find the routine only fills simple shapes before aborting, and requires several attempts to complete the job. With normal patterns this shouldn't be a problem.
Here are a few possibilities to think about. Firstly, you can achieve a single colour fill by having a block of only one pixel, for instance:
a$="1":CALL &9000,1,1, @a$
This provides you with a way of changing the background colour should the existing one prove troublesome and avoids having to have two fill routines in memory.
Secondly, on Mode 1 and 2 screens you can get extra colours by alternating two inks such as 0,1 on the top row and 1,0 on the second. This is more successful with some combinations than others. Thirdly, when defining a pattern, if you're careful you can hide the fact that it's based on a rectangle by making one edge a continuation of what's happening on the opposite edge.