${ "cafebabe" hex>rgba } [ COLOR: #cafebabe value>> ] unit-test
${ "112233" hex>rgba } [ COLOR: #112233 value>> ] unit-test
${ "11223344" hex>rgba } [ COLOR: #11223344 value>> ] unit-test
+
+{ "#00000000" } [ transparent color>hex ] unit-test
+{ "#cafebabe" } [ COLOR: #cafebabe color>hex ] unit-test
+{ "#112233" } [ COLOR: #112233 color>hex ] unit-test
+{ "#11223344" } [ COLOR: #11223344 color>hex ] unit-test
[ drop invalid-hex-color ]
} case <rgba> ;
+: component>hex ( f -- s )
+ 255 * round >integer >hex
+ 2 CHAR: 0 pad-head ;
+
+: (color>hex) ( seq -- hex )
+ [ component>hex ] map concat
+ "#" prepend ;
+
PRIVATE>
+: color>hex ( color -- hex )
+ [ >rgba-components 4array ] [ opaque? ] bi
+ [ but-last ] when
+ (color>hex) ;
+
: named-colors ( -- keys ) colors keys ;
ERROR: no-such-color name ;
CONSTANT: full-block-string $[ 10 CHAR: full-block <string> ]
-: rgba>hex ( rgba -- hex )
- [ red>> ] [ green>> ] [ blue>> ] tri
- [ 255 * round >integer ] tri@ "%02X%02X%02X" sprintf ;
-
PRIVATE>
M: color-renderer filled-column
[ red>> "%.5f" sprintf ]
[ green>> "%.5f" sprintf ]
[ blue>> "%.5f" sprintf ]
- [ rgba>hex ]
+ [ color>hex ]
} cleave
] output>array ;