It looks like 2htdp/image accepts all strings as legal color values, but "if a string or symbol color name is not recognized, black is used in its place." In particular, note that (rectangle 20 20 "solid" "#ffe303") produces the same image as (rectangle 20 20 "solid" "#000000"). Strings are interpreted as color names: support for hex strings is not built in (though it is easy to add, and I have implemented it a few times).
If you need to be able to test whether a particular string is recognized as a color, it looks like the find-color method of color-database<%> will help you, though note that 2htdp/image handles "transparent" as a special case, in addition to the strings recognized by the-color-database. The racket/class object system is not part of the teaching languages, but all of the recognized color strings are listed and illustrated in the docs ( http://docs.racket-lang.org/draw/color-database___.html), so it is easy to write a function known-color-name? in pure BSL. Here's one way to implement it: #lang htdp/BSL (define known-color-strings ;; from: (send the-color-database get-names) (list "aliceblue" "antiquewhite" "aqua" "aquamarine" "azure" "beige" "bisque" "black" "blanchedalmond" "blue" "blue violet" "blueviolet" "brown" "burlywood" "cadet blue" "cadetblue" "chartreuse" "chocolate" "coral" "cornflower blue" "cornflowerblue" "cornsilk" "crimson" "cyan" "dark gray" "dark green" "dark olive green" "dark orchid" "dark slate blue" "dark slate gray" "dark turquoise" "darkblue" "darkcyan" "darkgoldenrod" "darkgray" "darkgreen" "darkkhaki" "darkmagenta" "darkolivegreen" "darkorange" "darkorchid" "darkred" "darksalmon" "darkseagreen" "darkslateblue" "darkslategray" "darkturquoise" "darkviolet" "deeppink" "deepskyblue" "dim gray" "dimgray" "dodgerblue" "firebrick" "floralwhite" "forest green" "forestgreen" "fuchsia" "gainsboro" "ghostwhite" "gold" "goldenrod" "gray" "green" "green yellow" "greenyellow" "honeydew" "hotpink" "indian red" "indianred" "indigo" "ivory" "khaki" "lavender" "lavenderblush" "lawngreen" "lemonchiffon" "light blue" "light gray" "light steel blue" "lightblue" "lightcoral" "lightcyan" "lightgoldenrodyellow" "lightgray" "lightgreen" "lightpink" "lightsalmon" "lightseagreen" "lightskyblue" "lightslategray" "lightsteelblue" "lightyellow" "lime" "lime green" "limegreen" "linen" "magenta" "maroon" "medium aquamarine" "medium blue" "medium forest green" "medium goldenrod" "medium orchid" "medium sea green" "medium slate blue" "medium spring green" "medium turquoise" "medium violet red" "mediumaquamarine" "mediumblue" "mediumforestgreen" "mediumgoldenrod" "mediumorchid" "mediumpurple" "mediumseagreen" "mediumslateblue" "mediumspringgreen" "mediumturquoise" "mediumvioletred" "midnight blue" "midnightblue" "mintcream" "mistyrose" "moccasin" "navajowhite" "navy" "oldlace" "olive" "olivedrab" "orange" "orange red" "orangered" "orchid" "pale green" "palegoldenrod" "palegreen" "paleturquoise" "palevioletred" "papayawhip" "peachpuff" "peru" "pink" "plum" "powderblue" "purple" "red" "rosybrown" "royalblue" "saddlebrown" "salmon" "sandybrown" "sea green" "seagreen" "seashell" "sienna" "silver" "sky blue" "skyblue" "slate blue" "slateblue" "slategray" "snow" "spring green" "springgreen" "steel blue" "steelblue" "tan" "teal" "thistle" "tomato" "turquoise" "violet" "violet red" "violetred" "wheat" "white" "whitesmoke" "yellow" "yellow green" "yellowgreen")) (define (known-color-name? arg) (if (symbol? arg) (known-color-name? (symbol->string arg)) (and (string? arg) (or (member? (string-downcase arg) known-color-strings) (equal? "transparent" (string-downcase arg)))))) (check-satisfied "Transparent" known-color-name?) (check-satisfied 'grEEn known-color-name?) (check-satisfied "Red" known-color-name?) (check-expect (known-color-name? "#000000") #f) (check-expect (known-color-name? "racket") #f) (check-expect (known-color-name? 1) #f) -Philip On Tue, Mar 27, 2018 at 10:41 AM, 若草春男 <whbug...@gmail.com> wrote: > Hi, everyone. > > I'm using 2htdp/image and I wonder the color description. > > DrRacket version 6.12 > > > (require 2htdp/image) > > (image-color? "red") ; will #t > #t > > (image-color? 1) ; will #f > #f > > (image-color? (color 0 0 0 0)) ; will #t > #t > > (image-color? "pale") ; I don't know about this. > #t > > (image-color? "racket") ; will #f > #t > > (image-color? "#000000") ; I don't know about this. > #t > > And, look at the uploaded picture. > Please match the behavior between the rectangle and image-color? functions. > > Thanks, > Haruo Wakakusa > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.