## Plot Color function

For finished programs
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

### Plot Color function

For a plot program I created a "Plot_Color" function where the ascending value of the parameter generates saturated colors with ascending luminance values.
The following code is a demo program:

Code: Select all

``````'Plot_color test
'by Ton Nillesen, October 2019
' plotcolors with increasing luminance
'
'==== Presets ====
OPTION TAB 5
PRINT "  R","  G","  B","  Y"
sw,sh=SCRSIZE|2
radius=sw/18
dx=2*radius
'
'=== Examples ===
bg=0.5 'background  r g b
M=1 ' magnitude
DRAW CLEAR bg,bg,bg
FOR i=0 TO 7
C=i
r,g,b=Plot_Color|3(C,M)
y=Plot_Color.y
DRAW COLOR Plot_Color|3(C,M)
PRINT  Fn(r),Fn(g),Fn(b),Fn(y)
DRAW FCIRC (i+1)*dx,sh/2,radius
NEXT i
END

DEF Fn(n)
RETURN STRTEXT n "0.00"
END DEF

DEF Plot_Color(C,M)
' C sets color in range 0-7
' with increasing luminance Y
' Black,Blue,Red,Magenta,Green,Cyan,Yellow,White
' M determines magnitude, 0 to 1
B=M*BITAND 1,C
R=M*(BITAND 2,c)/2
G=M*(BITAND 4,c)/4
Y=0.3*R+0.59*G+0.11*B
RETURN r g b
END DEF
``````
.
The image is composed of three runs with different backgrounds.
.
Plot colours on different backgrounds.JPG (36.98 KiB) Viewed 1147 times
.
It clearly shows which colors are preferred on various backgrounds.

The code is also a nice demo of the BITAND function.
Output on console:

Code: Select all

``````  R    G    B    Y
0.00 0.00 0.00 0.00
0.00 0.00 1.00 0.11
1.00 0.00 0.00 0.30
1.00 0.00 1.00 0.41
0.00 1.00 0.00 0.59
0.00 1.00 1.00 0.70
1.00 1.00 0.00 0.89
1.00 1.00 1.00 1.00
``````
It is still a long way to go