News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_AMSDOS

Multicoloured Graphics in BASIC discuss.

Started by AMSDOS, 06:29, 26 May 19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AMSDOS

This follows on from numerous examples I've had from the "Silly Programming Ideas - Turning Text into Graphics" thread, however, I've decided to start a new thread if members wish to discuss further the process of Building a Multicoloured Graphic in BASIC.


My latest example returns to that old Bouncing Ball routine, this time I've added a second Ball and to keep the Balls within the area a Multicoloured Wall is drawn in around the perimeter and a smaller inner wall for the Balls to Bounce off has also been added.


I've made the Demo interactive to demonstrate what kinds of problems may occur when tackling Multicoloured graphics, both examples here use the Text Coordinated Transparent Mode to produce a 3 Coloured Block:


* Example 1 Draws the Block over the existing Window in Sky Blue, to produce a White/Sky Blue/Light Blue Graphic.


* Example 2 asks for a 3rd Colour between 4 & 13, after specifying a colour, the centre of the block will use that instead of the existing Sky Blue.


When it came to Example 2, I had to write it another way from Example 1 because in order to get the centre colour, I needed to have Transparent Mode switched off. This is so I could use PAPER for the Background and print the other colour in it's specified PEN, in this case White, which is the top half of the Block, but to get the last Character in place, Transparent Mode needs to be on to Avoid deleting the Top Corner of the Block. A good test to see how the Blocks are drawn up is to Select Example 2 and Specify 13 for the 3rd Colour, it's quite noticeable the Light Green colour can be seen before the 2nd Character is Drawn in due to the Number of Blocks that require drawing in.


10 MODE 2:DEFINT a-z:CALL &BC02:PAPER 0:PEN 1
20 LOCATE 1,1:INPUT"(1) Select 2 Colour Graphic or (2) 3 Colour Graphic";s
30 IF s<1 OR s>2 THEN GOTO 20
40 IF s=2 THEN LOCATE 1,3:INPUT"Select 3rd Colour (4-13)";p:IF p<4 OR p>13 THEN GOTO 40
100 MODE 0:DIM b$(10,25)
110 INK 0,1:INK 1,26:INK 2,2:INK 3,11:INK 4,25
120 WINDOW 5,14,1,25:PAPER 3:CLS:GOSUB 1000:PAPER 3:PEN 4
130 x1=5:x2=5:y1=15:y2=5:xd1=1:yd1=1:xd2=-1:yd2=-1
140 WHILE 1
150   b$(x1,y1)=" ":LOCATE x1,y1:PRINT b$(x1,y1);
160   x1=x1+xd1:y1=y1+yd1:b$(x1,y1)="O"
170   LOCATE x1,y1:PRINT b$(x1,y1);
180   b$(x2,y2)=" ":LOCATE x2,y2:PRINT b$(x2,y2);
190   x2=x2+xd2:y2=y2+yd2:b$(x2,y2)="O"
200   LOCATE x2,y2:PRINT b$(x2,y2);
210   IF b$(x1+1,y1)=CHR$(1) THEN xd1=-1
220   IF b$(x1-1,y1)=CHR$(1) THEN xd1=1
230   IF b$(x1,y1+1)=CHR$(1) THEN yd1=-1
240   IF b$(x1,y1-1)=CHR$(1) THEN yd1=1
250   IF b$(x2+1,y2)=CHR$(1) THEN xd2=-1
260   IF b$(x2-1,y2)=CHR$(1) THEN xd2=1
270   IF b$(x2,y2+1)=CHR$(1) THEN yd2=-1
280   IF b$(x2,y2-1)=CHR$(1) THEN yd2=1
290 WEND
1000 SYMBOL 240,255,127,63,7,7,7,3,0
1010 SYMBOL 241,0,128,192,192,192,192,252,255
1020 PAPER p:xon$=CHR$(22)+CHR$(1):xof$=CHR$(22)+CHR$(0)
1030 LOCATE 1,1:PRINT xon$;
1040 FOR x=6 TO 9
1050   y=13:ON s GOSUB 1210,1310:b$(x,y)=CHR$(1)
1060 NEXT x
1070 FOR y=1 TO 25
1080   x=1:ON s GOSUB 1210,1310:b$(x,y)=CHR$(1):x=10:ON s GOSUB 1210,1310:b$(x,y)=CHR$(1)
1090 NEXT y
1100 FOR x=2 TO 9
1110   y=1:ON s GOSUB 1210,1310:b$(x,y)=CHR$(1):y=25:ON s GOSUB 1210,1310:b$(x,y)=CHR$(1)
1120 NEXT x
1130 LOCATE 1,1:PRINT xof$;
1140 RETURN
1200 ' Setup 2 Colour Wall
1210 FOR c=1 TO 2
1220   PEN c
1230   LOCATE x,y
1240   PRINT CHR$(239+c);
1250 NEXT c
1260 RETURN
1300 ' Setup 3 Colour Wall
1310 PRINT xof$; ' Transparent Mode must be off for PAPER 10 in Line 1020 to work
1320 PEN 1
1330 LOCATE x,y
1340 PRINT CHR$(240);
1350 PRINT xon$; ' Turn on Transparent Mode for last character to print
1360 PEN 2
1370 LOCATE x,y
1380 PRINT CHR$(241);
1390 RETURN


Defining the Multicoloured Graphics


Many (if not all) Character Definition programmes on the Amstrad have been setup to cater for the Standard 2 Colour definition (or pixel on/pixel off), so to get the 3 or more Colours in there becomes tricky. One book I have which focuses towards BBC BASIC for Students use examples of a 8x8 Grid (or a Multiple of it), with the values neatly organised for the Colour Groups, here's an example I've made from my Demo above:






So from that Figure "W" represents White and Blue represents Blue along the Left Side and Sky Blue (in the Centre) remains has the untouched area (PAPER 0 in that case), so when the PAPER is altered in Example 2, that's the area which is altered as long as Transparent Mode is switched off. From the information gathered, that simply becomes the SYMBOL data with Line 1000 being the White Data and 1010 being the Blue.


And here's a Screenshot of the Demo using Example 1.






There is an alternative way of creating Multicoloured graphics in BASIC through the use of Graphical Modes which I can demonstrate as part of this thread if anyone is interested.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

#1
I've been making some more colourful backdrops using Transparent Mode and have now come up with a standard (more readable) version, along with a version based on the Colourful Graphics from Fort Invincible.



100 MODE 0:BORDER 15:INK 2,15:INK 1,3
110 GOSUB 1000:DEFINT a-z
120 FOR y=1 TO 25
121   FOR x=1 TO 20
130     PEN 1:PAPER 2
140     LOCATE x,y:PRINT CHR$(255);
150     LOCATE x,y:PEN 3:PRINT CHR$(22);CHR$(1);CHR$(254);CHR$(22);CHR$(0);
155   NEXT x
160 NEXT y
170 PAPER 0:PEN 1:CALL &BB18:INK 1,26:END
1000 SYMBOL 255,255,129,129,129,129,129,129,255
1010 SYMBOL 254,0,0,60,60,60,60,0,0
1020 RETURN



This version takes a little over 15 seconds to complete, the only advantage I could see in this version was I could Fill the Entire screen with the Blocks without causing a new line to emerge at the bottom of the screen.



100 MODE 0:PAPER 2:CLS:BORDER 15:INK 2,15:INK 1,3
110 GOSUB 1000:DEFINT a-z
120 SYMBOL 255,255,129,129,129,129,129,129,255
130 SYMBOL 254,0,0,60,60,60,60,0,0
140 FOR y=1 TO 24
150   FOR x=1 TO 20
160     LOCATE x,y
170     PRINT USING"&";b$;
180   NEXT x
190 NEXT y
200 PAPER 0:PEN 1:CALL &BB18:MODE 2:END
1000 FOR n=1 TO 13
1010   READ ch
1020   b$=b$+CHR$(ch)
1030 NEXT n:RETURN
1040 DATA 15,1,14,2,255,8,15,3,22,1,254,22,0



This version completes the screen in around 9 seconds, but what happens when it reaches the 25 line, when it gets to the Last position 20,25, the screen rolls. This funnily enough wasn't the result of me emulating 464, it also occurs in 6128 mode, however with the way the PRINT USING is setup, PRINTing works across all systems despite Backspace is present in the Command Code data.


As I mentioned earlier, this technique was used in Fort Invincible for the Main Character and Hazards with good results, the data in my example are as follows:
chr$(15);chr(1) - PEN 1
chr$(14);chr$(2) - PAPER 2
chr$(255) - PRINT outer Square (Red PEN & Orange PAPER)
chr$( - Move Character Back One Space
chr$(15);chr$(3) - PEN 3
chr$(22);chr$(1) - Transparent Mode On
chr$(254) - PRINT inner Square (Bright Red)
chr$(22);chr$(0) - Transparent Mode Off



So all that information from Above gets stored into b$ string and when PRINT USING"&";b$; is applied anywhere onscreen, a multicoloured image is the result. My example here is only 8x8 in size, however Fort Invincible was able to show that Larger Graphics were possible simply by moving the cursor around accordingly, it didn't even seem to make any difference while playing the game on a 464.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Powered by SMFPacks Menu Editor Mod