colors.hex vocab.

db4
John Benediktsson 2010-10-28 13:34:59 -07:00
parent 675a420717
commit fdef71d2b7
5 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1 @@
John Benediktsson

View File

@ -0,0 +1,38 @@
! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: colors help.markup help.syntax strings ;
IN: colors.hex
HELP: hex>rgba
{ $values { "hex" string } { "rgba" color } }
{ $description "Converts a hexadecimal string value into a " { $link color } "." }
;
HELP: rgba>hex
{ $values { "rgba" color } { "hex" string } }
{ $description "Converts a " { $link color } " into a hexadecimal string value." }
;
HELP: HEXCOLOR:
{ $syntax "HEXCOLOR: value" }
{ $description "Parses as a " { $link color } " object with the given hexadecimal value." }
{ $examples
{ $code
"USING: colors.hex io.styles ;"
"\"Hello!\" { { foreground HEXCOLOR: 336699 } } format nl"
}
} ;
ARTICLE: "colors.hex" "HEX colors"
"The " { $vocab-link "colors.hex" } " vocabulary implements colors specified "
"by their hexidecimal value."
{ $subsections
hex>rgba
rgba>hex
POSTPONE: HEXCOLOR:
}
{ $see-also "colors" } ;
ABOUT: "colors.hex"

View File

@ -0,0 +1,12 @@
! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: colors colors.hex tools.test ;
IN: colors.hex.test
[ HEXCOLOR: 000000 ] [ 0.0 0.0 0.0 1.0 <rgba> ] unit-test
[ HEXCOLOR: FFFFFF ] [ 1.0 1.0 1.0 1.0 <rgba> ] unit-test
[ HEXCOLOR: abcdef ] [ "abcdef" hex>rgba ] unit-test
[ HEXCOLOR: abcdef ] [ "ABCDEF" hex>rgba ] unit-test
[ "ABCDEF" ] [ HEXCOLOR: abcdef rgba>hex ] unit-test

View File

@ -0,0 +1,16 @@
! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: accessors colors formatting grouping kernel lexer math
math.parser sequences ;
IN: colors.hex
: hex>rgba ( hex -- rgba )
2 group [ hex> 255 /f ] map first3 1.0 <rgba> ;
: rgba>hex ( rgba -- hex )
[ red>> ] [ green>> ] [ blue>> ] tri
[ 255 * >integer ] tri@ "%02X%02X%02X" sprintf ;
SYNTAX: HEXCOLOR: scan hex>rgba suffix! ;

View File

@ -0,0 +1 @@
Hexadecimal colors