How to achieve a multicolored character?

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
User avatar
Arkas
Posts: 90
Joined: Sat Feb 04, 2017 12:05 am
Contact:

How to achieve a multicolored character?

Post by Arkas »

I've been struggling with this one for some time. I just can't seem to find a way to get a character or a UDG to have different colours in each pixel. It doesn't have to be many, let's say even 3. I can't even do it in Mode 7! Print CHR$ doesn't do the job either.
Is there some secret Basic command that I have overlooked?
User avatar
davidb
Posts: 3117
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: How to achieve a multicolored character?

Post by davidb »

For normal, non-MODE 7 text, you need to switch to graphics mode using VDU 5, set the graphics cursor position, then print using the graphics colour. Then switch back to text mode with VDU 4.

Code: Select all

MODE 2
VDU 5
MOVE 100,512
GCOL 0,3
PRINT "HELLO"
MOVE 100,512
GCOL 0,1
PRINT "hello"
VDU 4
User avatar
Arkas
Posts: 90
Joined: Sat Feb 04, 2017 12:05 am
Contact:

Re: How to achieve a multicolored character?

Post by Arkas »

Thanks, I'll give it a go.
User avatar
tricky
Posts: 5687
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: How to achieve a multicolored character?

Post by tricky »

I think that you will need to create UDG to use for each colour in the character of that is what you mean.
User avatar
BigEd
Posts: 4238
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: How to achieve a multicolored character?

Post by BigEd »

Is it possible to set a very small graphics window then print at graphics cursor? If that works, horizontal stripes should be relatively straightforward.
User avatar
Arkas
Posts: 90
Joined: Sat Feb 04, 2017 12:05 am
Contact:

Re: How to achieve a multicolored character?

Post by Arkas »

Something like this, only in 8 bit text
Attachments
140010937-letter-m-of-the-english-alphabet-from-multi-colored-chewing-marmalade-on-a-white-isolated-background.jpg
User avatar
tricky
Posts: 5687
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: How to achieve a multicolored character?

Post by tricky »

You could draw it white and then draw a pattern using UDG in AND mode to apply the colours. This should be fairly fast and only requires one UDG character, although you could have as many make as you like to vary the pattern.
User avatar
Arkas
Posts: 90
Joined: Sat Feb 04, 2017 12:05 am
Contact:

Re: How to achieve a multicolored character?

Post by Arkas »

Yes, but, let's take a letter for simplicity, would that work for the letter itself to contain 4 different colours?
So far I have only achived foreground, background, and the letter. That's not what I want to do, I want the letter itself to be made of 4 different colours. I'll give what you said a try.
Thanks.
User avatar
tricky
Posts: 5687
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: How to achieve a multicolored character?

Post by tricky »

Actually, my suggestion won't work as is, it would need an overlay per bit, so 4 colour two overlays, 8 colours three overlays.
User avatar
ChrisB
Posts: 159
Joined: Wed Oct 05, 2011 10:37 pm
Location: Surrey
Contact:

Re: How to achieve a multicolored character?

Post by ChrisB »

Assuming a black background you only need two characters and an OR operation for 4 colours. So something like this...?

https://bbcmic.ro/#%7B%22v%22%3A1%2C%22 ... D%2C%22%7D

Code: Select all

   10 MODE 1
   20 REM Define two characters that will be ORed together
   30 VDU 23,254,198,46,62,214,192,192,134,0
   40 VDU 23,255,2,192,204,0,134,134,64,0
   50 REM Print the two characters for demonstration purposes
   60 PRINTCHR$(254);CHR$(255)
   70 PRINT''
   80 REM We are going to print at the graphics cursor
   90 MOVE 0,31*8*4-4
  100 REM Print the first character as "set" in red
  110 GCOL 0,1
  120 VDU 5:PRINTCHR$(254)
  130 REM Move to the same location and print the second character over the first using OR
  140 MOVE 0,31*8*4-4
  150 GCOL 1,2
  160 PRINTCHR$(255)
  170 VDU 4
  180 REM Move to the second location
  190 MOVE 8*4,31*8*4-4
  200 REM Print the character as a series of VDU commands
  210 M$=CHR$(5)+CHR$(18)+CHR$(0)+CHR$(1)+CHR$(254)+CHR$(8)+CHR$(18)+CHR$(1)+CHR$(2)+CHR$(255)+CHR$(4)
  220 PRINT M$
  230 REM Produce a larger version
  240 FOR X%=0 TO 15
  250 FOR Y%=0 TO 15
  260 GCOL 0,POINT(X%*4,1023-Y%*4)
  270 MOVE 128+X%*32,800-Y%*32
  280 PLOT 0,31,0:PLOT 81,-31,31:PLOT 81,31,0
  290 NEXT,
User avatar
Arkas
Posts: 90
Joined: Sat Feb 04, 2017 12:05 am
Contact:

Re: How to achieve a multicolored character?

Post by Arkas »

Thanks Chris! This is much closer to what I want to do.
RobC
Posts: 3239
Joined: Sat Sep 01, 2007 10:41 pm
Contact:

Re: How to achieve a multicolored character?

Post by RobC »

The Micro User had a series of articles on sprites (starting in April 1989) and they definitely covered plotting multicoloured characters in BASIC before introducing machine code sprite routines. You may have to go through a few articles before they cover multicoloured characters.

The magazine scans are available at 8BS.
User avatar
Arkas
Posts: 90
Joined: Sat Feb 04, 2017 12:05 am
Contact:

Re: How to achieve a multicolored character?

Post by Arkas »

Thanks, I'll read through them.
User avatar
archie456
Posts: 86
Joined: Sat Sep 07, 2019 4:22 pm
Location: Chelmsford
Contact:

Re: How to achieve a multicolored character?

Post by archie456 »

FWIW, this is my BASIC sprite plotter... very slow. I put it together to try to start learning ASM.

It plots an apple in case your wondering!

Code: Select all

L.

   10REM KB Sprite Plotter
   20MODE 2
   30OFSETX = 500
   40OFSETY = 500
   50FOR YPOS = 1 TO 16
   60FOR XPOS = 1 TO 8
   70READ PIXDATA
   80GCOL0,PIXDATA
   90PLOT 69,OFSETX + (XPOS*8), OFSETY - (YPOS*4)
  100NEXT XPOS
  110NEXT YPOS
  120DATA 0,0,0,2,2,0,0,0
  130DATA 0,0,0,0,0,2,0,0
  140DATA 0,0,0,0,0,2,0,0
  150DATA 0,0,6,4,4,0,2,0
  160DATA 0,6,4,0,0,0,2,0
  170DATA 0,4,4,0,0,2,0,0
  180DATA 0,4,0,0,2,0,0,0
  190DATA 0,0,0,2,0,0,0,0
  200DATA 0,1,1,2,0,1,1,0
  210DATA 1,1,1,1,1,3,1,1
  220DATA 1,1,1,1,5,5,3,1
  230DATA 1,1,1,1,1,5,3,1
  240DATA 1,1,1,1,1,1,3,1
  250DATA 1,1,1,1,1,1,1,1
  260DATA 0,1,1,1,1,1,1,0
  270DATA 0,0,1,0,0,1,0,0
>
Soruk
Posts: 932
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: How to achieve a multicolored character?

Post by Soruk »

Here's a conversion of something I initially did for Matrix Brandy, converted to BASIC 2 and removed all RISC OS-isms....

Code: Select all

REM Draw a text string on screen
REM Parameters:
REM   t$: The string to print.
REM   xp%: X position in OS units. Use -1 to centre it (not accurate in proportional mode)
REM   yp%: Y position in OS units.
REM   xs:  X scale (MODE 0 uses 1, MODE 1 use 2, mode 2 use 4)
REM   ys:  Y scale (Always use 2 on pre-RISC OS)
REM   mc%: Non-zero if multi-colour, value is the highest value to use (e.g. MODE 1 use 3)
REM   ps%: TRUE for proportional spacing
DEFPROCdrawstring(t$,xp%,yp%,xs,ys,mc%,ps%)
LOCAL oswd%
DIM oswd% 10
IF xp%=-1 THEN xp%=640-((LEN(t$)*16*xs)/2): REM 640 good for BBC modes and RISC OS 0-15,18-21, 25-28
xpos% = xp%
FOR p%=1 TO LEN(t$)
  ?oswd%=ASC(MID$(t$,p%,1))
  A%=10:X%=oswd%: Y%=oswd% DIV 256: CALL &FFF1
  left%=7: right%=0
  IF ps% THEN left%=FNpsleft(oswd%): right%=FNpsright(oswd%)
  IF left% < 7 THEN left%=left%+1
  IF left% = 4 AND right% = 3 THEN right%=1: REM Space character
  FOR row%=1 TO 8
    bits%=oswd%?row%
    FOR b%=left% TO right% STEP -1
      IF mc% THEN GCOL 0,RND(mc%)
      IF ((bits% DIV (2^b%)) AND 1) THEN PLOT &45, xpos% + (2*(xs*(left%-b%))),yp%-(2*(ys*row%))
    NEXT
  NEXT
  xpos% = xpos% + (2*(1+left%-right%)*xs)
NEXT
ENDPROC

DEF FNpsleft(def%)
  LOCAL fail%
  fail%=0
  l%=7
  REPEAT
   IF (def%?1 AND 2^l%)=0 AND (def%?2 AND 2^l%)=0 AND (def%?3 AND 2^l%)=0 AND (def%?4 AND 2^l%)=0 AND (def%?5 AND 2^l%)=0 AND (def%?6 AND 2^l%)=0 AND (def%?7 AND 2^l%)=0 AND (def%?8 AND 2^l%)=0 AND l%>3 THEN l%=l%-1 ELSE fail%=1
  UNTIL fail%
=l%

DEF FNpsright(def%)
  LOCAL fail%
  fail%=0
  r%=0
  REPEAT
   IF (def%?1 AND 2^r%)=0 AND (def%?2 AND 2^r%)=0 AND (def%?3 AND 2^r%)=0 AND (def%?4 AND 2^r%)=0 AND (def%?5 AND 2^r%)=0 AND (def%?6 AND 2^r%)=0 AND (def%?7 AND 2^r%)=0 AND (def%?8 AND 2^r%)=0 AND r%<3 THEN r%=r%+1 ELSE fail%=1
  UNTIL fail%
=r%
Tested on jsbeeb, it is a tad slow but it works. You also get proportional text plotting as an option!
Matrix Brandy BASIC VI (work in progress)
User avatar
Arkas
Posts: 90
Joined: Sat Feb 04, 2017 12:05 am
Contact:

Re: How to achieve a multicolored character?

Post by Arkas »

Thanks, that worked great!
Post Reply

Return to “programming”