Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:19 02 Sep 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Random Colours

Author Message
asknik2022
Regular Member

Joined: 26/03/2022
Location: United Kingdom
Posts: 94
Posted: 11:27pm 02 Mar 2023
Copy link to clipboard 
Print this post

Is there a way to select a random colour eg white , red ,etc in RGB(colour)

I have tried col$="green" in rgb(col$) and get an error

Can anyone suggest a work around
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2679
Posted: 11:43pm 02 Mar 2023
Copy link to clipboard 
Print this post

The colour names are constants that represent colour numbers, not strings.

Try repeatedly:-

CLS RGB(RND*255,RND*255,RND*255)
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4068
Posted: 11:45pm 02 Mar 2023
Copy link to clipboard 
Print this post

deleted
Edited 2023-03-03 09:46 by JohnS
 
asknik2022
Regular Member

Joined: 26/03/2022
Location: United Kingdom
Posts: 94
Posted: 03:27pm 03 Mar 2023
Copy link to clipboard 
Print this post

does anyone know what the actual numbers are for the basic colours red,green etc
or is there a colour chart of some sort with the actual numbers on.
 
asknik2022
Regular Member

Joined: 26/03/2022
Location: United Kingdom
Posts: 94
Posted: 04:00pm 03 Mar 2023
Copy link to clipboard 
Print this post

Solved it via ChatGPT
Example below

'Define color lookup table
DIM colors$(3)
colors$(1)="white": colors$(2)="red": colors$(3)="blue"
DIM rgb%(3,3)
rgb%(1,1)=255: rgb%(1,2)=255: rgb%(1,3)=255
rgb%(2,1)=255: rgb%(2,2)=0: rgb%(2,3)=0
rgb%(3,1)=0: rgb%(3,2)=0: rgb%(3,3)=255

' Set color using lookup table
colorname$="red"
colorindex=0
FOR i=1 TO 3
  IF colors$(i)=colorname$ THEN colorindex=i: EXIT FOR
NEXT i
IF colorindex=0 THEN PRINT "Color not found": END
pixel 10,10,rgb(rgb%(colorindex,1),rgb%(colorindex,2),rgb%(colorindex,3))
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8043
Posted: 05:59pm 03 Mar 2023
Copy link to clipboard 
Print this post

It may look clumsy, but it's obvious what's happening:

Create an array c(0)=RGB(black) up to c(15)=RGB(white)
Now just use a random number between 0 and 15 because all the colours have simple numbers.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 455
Posted: 06:19pm 03 Mar 2023
Copy link to clipboard 
Print this post

  asknik2022 said  does anyone know what the actual numbers are for the basic colours red,green etc
or is there a colour chart of some sort with the actual numbers on.


To find a color number, you can just PRINT RGB(colorname)

> print rgb(red)
4278190335
> print rgb(green)
4278255360
> print rgb(blue)
4294901760

Each of the colors (red, green and blue) can be represented by a number from 0 to 255.You can combine them to create any color in the pallette.

print rgb(120,200,17)
Edited 2023-03-04 04:40 by toml_12953
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4068
Posted: 06:33pm 03 Mar 2023
Copy link to clipboard 
Print this post

  toml_12953 said  
  asknik2022 said  does anyone know what the actual numbers are for the basic colours red,green etc
or is there a colour chart of some sort with the actual numbers on.


To find a color number, you can just PRINT RGB(colorname)

> print rgb(red)
4278190335
> print rgb(green)
4278255360
> print rgb(blue)
4294901760

Printing HEX$() of each of those might ... illuminate :)

John
 
LucV

Regular Member

Joined: 19/02/2023
Location: Netherlands
Posts: 62
Posted: 07:02pm 03 Mar 2023
Copy link to clipboard 
Print this post

Google is your friend !!

In Google just search for color picker and





Move the dot and slider and you can pick any color you want and get RGB, CMYK, HSV and HSL values.
Luc's tech Blog
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8043
Posted: 07:08pm 03 Mar 2023
Copy link to clipboard 
Print this post

You *can* but that doesn't mean you can reproduce it on a PicoMite. :)

Look in the manual - Appendix F, I think it is.
All the available colours and their binary values are listed there.
Edited 2023-03-04 05:09 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1270
Posted: 08:00pm 03 Mar 2023
Copy link to clipboard 
Print this post

As Picomite VGA uses 4 Bit for the Color Output,
there are 16 possible Colors on the PicoMite VGA
1 Bit Red 2 Bit Green and 1 Bit Blue, but, to keep it comatible to MM Basic on other devices, the colors are selected in 24Bit Format.
.

RRGGBB
------
000000
0000FF
004000
0040FF
008000
0080FF
00FF00
00FFFF
FF0000
FF00FF
FF4000
FF40FF
FF8000
FF80FF
FFFF00
FFFFFF
Edited 2023-03-04 06:13 by Martin H.
'no comment
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025