! Col utils

Post Reply
User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

! Col utils

Post by Dutchman » Tue Nov 19, 2019 9:07 pm

Functions for color generation and handling.
Col_FB(i,C()) extracts a color set (r,g,b,A) from series in a list.
Col_Plot((CM()) sets saturated color in range 0-7 with ascending luminance which simplifies color choice on light or dark backgrounds.
# Col_plot test.bb is the testprogram

Code: Select all

' {/Extensions/Graphics/! Col_ utils}
[ colour utilities for graphics ]
'
[––––––––––––––––––––––– Functions –––––––––––––––––––––––––
Col_FB|4(i,C())
return colourset from colour parameters 'C()'
C() should contain at least 2 colour sets
each colour set has 4 values for r,g,b,A
i determines which set is returned
e.g. Font or Background, Fill or Border etc.
–––
Col_Plot(CM())
C=CM(0) : M=CM(1)
C sets color in range 0-7
generates saturated colors for graph lines
with inversion facility for dark or light background
luminance increases with C if inverse=0 else decreases
colours for Inverse=0:
	Black,Blue,Red,Magenta,Green,Cyan,Yellow,White
M determines magnitude, 0 to 1
Set local 'Inverse' before use, if desired
–––
End of function description –––––––––––]
'
[–––––––––––––––––––––– Implementation ––––––––––––––––––––––]
DEF Col_FB(i,C()) ' by Ton Nillesen, November 2019
n=4*i
RETURN C(n),C(n+1),,C(n+2),C(n+3)
END DEF
'
DEF Col_Plot(CM()) ' by Ton Nillesen, November 2019
C=CM(0) : M=CM(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
IF Inverse THEN RETURN 1-r,1-g,1-b
RETURN r g b
END DEF
'
It is still a long way to go

Post Reply