Handbook
Glossary
rgba
Colors
Next:
<rgba> ( red green blue alpha -- rgba )
Vocabulary
colors
Class description
The class of colors with red, green, blue and alpha channel components. The slots store color components, which are real numbers in the range 0 to 1, inclusive.
Definition
IN:
colors
TUPLE:
rgba
{
red
read-only
}
{
green
read-only
}
{
blue
read-only
}
{
alpha
read-only
}
;
Methods
USING:
colors
colors.cmyk
kernel
math
math.order
;
M:
rgba
>cmyka
>rgba-components
[
[
1
swap
-
]
tri@
3dup
min
min
[
[
-
0.0 1.0
clamp
]
curry
tri@
]
keep
]
dip
<cmyka>
;
USING:
colors
colors.gray
kernel
math
;
M:
rgba
>gray
>rgba-components
[
[
0.3
*
]
[
0.59
*
]
[
0.11
*
]
tri*
+
+
]
dip
<gray>
;
USING:
colors
colors.hsl
combinators
kernel
locals.backend
math
math.order
;
M:
rgba
>hsla
>rgba-components
[
3
load-locals
-2
get-local
-1
get-local
0
get-local
min
min
load-local
-3
get-local
-2
get-local
-1
get-local
max
max
load-local
-1
get-local
0
get-local
+
2
/
load-local
-1
get-local
-2
get-local
-
load-local
0
get-local
zero?
[
0.0 0.0
]
-2
get-local
-6
get-local
-5
get-local
-4
get-local
0
get-local
-1
get-local
-3
get-local
[
7
load-locals
-6
get-local
dup
-5
get-local
=
-4
get-local
-3
get-local
-2
get-local
[
3
load-locals
drop
-2
get-local
-1
get-local
-
0
get-local
/
-2
get-local
-1
get-local
<
6.0 0.0
?
+
3
drop-locals
]
curry
curry
curry
-4
get-local
-3
get-local
-5
get-local
-2
get-local
[
4
load-locals
dup
-3
get-local
=
-2
get-local
-1
get-local
0
get-local
[
3
load-locals
drop
-2
get-local
-1
get-local
-
0
get-local
/
2.0
+
3
drop-locals
]
curry
curry
curry
-2
get-local
-1
get-local
-3
get-local
0
get-local
[
4
load-locals
dup
-3
get-local
=
-2
get-local
-1
get-local
0
get-local
[
3
load-locals
drop
-2
get-local
-1
get-local
-
0
get-local
/
4.0
+
3
drop-locals
]
curry
curry
curry
[
no-case
]
if
4
drop-locals
]
curry
curry
curry
curry
if
4
drop-locals
]
curry
curry
curry
curry
if
6.0
/
-1
get-local
0.5
>
-2
get-local
-6
get-local
0
get-local
[
3
load-locals
-2
get-local
2 -1
get-local
-
0
get-local
-
/
3
drop-locals
]
curry
curry
curry
-2
get-local
-6
get-local
0
get-local
[
3
load-locals
-2
get-local
-1
get-local
0
get-local
+
/
3
drop-locals
]
curry
curry
curry
if
7
drop-locals
]
curry
curry
curry
curry
curry
curry
curry
if
-1
get-local
7
drop-locals
]
dip
<hsla>
;
USING:
colors
colors.hsv
colors.hsv.private
combinators
kernel
math
;
M::
rgba
>hsva
( rgba -- hsva )
rgba
>rgba-components
:>
( r g b a ) r g b
sort-triple
:>
( z y x ) x z
=
x
zero?
or
[
0 0 x a
<hsva>
]
[
{
{
[
r x
=
g z
=
and
]
[
5 x b
-
x z
-
/
+
]
}
{
[
r x
=
g z
>
and
]
[
1 x g
-
x z
-
/
-
]
}
{
[
g x
=
b z
=
and
]
[
1 x r
-
x z
-
/
+
]
}
{
[
g x
=
b z
>
and
]
[
3 x b
-
x z
-
/
-
]
}
{
[
b x
=
r z
=
and
]
[
3 x g
-
x z
-
/
+
]
}
{
[
b x
=
r z
>
and
]
[
5 x r
-
x z
-
/
-
]
}
}
cond
6
/
360
*
x z
-
x
/
x a
<hsva>
]
if
;
USING:
accessors
colors
colors.hsl
colors.hwb
kernel
locals.backend
math
math.order
;
M:
rgba
>hwba
>hsla
[
hue>>
]
[
>rgba-components
]
bi
5
load-locals
-3
get-local
-2
get-local
-1
get-local
min
min
load-local
-4
get-local
-3
get-local
-2
get-local
max
max
1
swap
-
load-local
-6
get-local
-1
get-local
0
get-local
-2
get-local
<hwba>
7
drop-locals
;
USING:
colors
colors.lab
colors.xyz
;
M:
rgba
>laba
>xyza
>laba
;
USING:
colors
colors.luv
colors.xyz
;
M:
rgba
>luva
>xyza
>luva
;
USING:
colors
;
M:
rgba
>rgba
;
inline
USING:
colors
colors.ryb
colors.ryb.private
kernel
;
M:
rgba
>ryba
>rgba-components
[
[
rgb>ryb
]
normalized
]
[
<ryba>
]
bi*
;
USING:
accessors
colors
colors.xyz
colors.xyz.private
kernel
locals.backend
math
;
M:
rgba
>xyza
[
[
red>>
]
[
green>>
]
[
blue>>
]
tri
[
invert-rgb-compand
]
tri@
3
load-locals
-2
get-local
0.4124564
*
-1
get-local
0.3575761
*
0
get-local
0.1804375
*
+
+
-2
get-local
0.2126729
*
-1
get-local
0.7151522
*
0
get-local
0.072175
*
+
+
-2
get-local
0.0193339
*
-1
get-local
0.119192
*
0
get-local
0.9503041
*
+
+
3
drop-locals
]
[
alpha>>
]
bi
<xyza>
;
USING:
colors
colors.yiq
math
;
M::
rgba
>yiqa
( rgba -- yiqa )
rgba
>rgba-components
:>
( r g b a ) 0.3 r
*
0.59 g
*
0.11 b
*
+
+
:>
y r y
-
:>
r-y b y
-
:>
b-y 0.74 r-y
*
0.27 b-y
*
-
:>
i 0.48 r-y
*
0.41 b-y
*
+
:>
q y i q a
<yiqa>
;
USING:
colors
colors.yuv
colors.yuv.private
math
;
M::
rgba
>yuva
( rgba -- yuva )
rgba
>rgba-components
:>
( r g b a )
Wr
r
*
Wg
g
*
Wb
b
*
+
+
:>
y
Umax
1
Wb
-
/
b y
-
*
:>
u
Vmax
1
Wr
-
/
r y
-
*
:>
v y u v a
<yuva>
;