- Top Stats

Top Posters Top Topic Starters Top Topics
arnoldemu 1128
TFM 1124
ervin 746
ronaldo 406
arnoldemu 51
ervin 42
EgoTrip 35
Arnaud 33
FutureOS corner - 71863 Views TFM/FS 07:12, 01 October 10
Example Z80 as... - 67213 Views arnoldemu 10:59, 04 April 10
#CPCtelera 1.4... - 33782 Views ronaldo 13:59, 11 May 15
BASIC programm... - 31810 Views arnoldemu 16:23, 22 May 09
CHAMP Assemble... - 25444 Views Bruce Abbo... 12:59, 16 January 14

Author Topic: Multicoloured Graphics in BASIC discuss.  (Read 132 times)

0 Members and 1 Guest are viewing this topic.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.598
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 863
Multicoloured Graphics in BASIC discuss.
« on: 08:29, 26 May 19 »
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.

Code: [Select]
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$;
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
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);

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.
« Last Edit: 08:33, 26 May 19 by AMSDOS »
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)