Color.st
changeset 7910 303d43b7c688
parent 7909 c5f82e9429f9
child 7964 00097a2433d1
equal deleted inserted replaced
7909:c5f82e9429f9 7910:303d43b7c688
   992 
   992 
   993     "
   993     "
   994      (Color green:50) inspect
   994      (Color green:50) inspect
   995     "
   995     "
   996 
   996 
       
   997 !
       
   998 
       
   999 htmlName:colorName
       
  1000     "see https://en.wikipedia.org/wiki/Web-safe#HTML_color_names
       
  1001      The web defines 16 standard color names, which are returned here. 
       
  1002      Attention:
       
  1003         these are not the same colors as those built into X-servers;
       
  1004         eg. (Color name:'green') returns a bright green,
       
  1005         whereas (Color htmlName:'green') returns a dark green, and 'lime' would be the X-green.
       
  1006         Sigh"
       
  1007 
       
  1008     ^ self
       
  1009         htmlName:colorName
       
  1010         ifIllegal:[
       
  1011             InvalidColorNameSignal
       
  1012                 raiseRequestWith:colorName errorString:' : ' , colorName
       
  1013         ]
       
  1014 
       
  1015     "
       
  1016      Color htmlName:'lime'
       
  1017 
       
  1018      Color htmlName:'green'
       
  1019      Color name:'green'
       
  1020     "
       
  1021 
       
  1022     "Created: / 17-02-2017 / 12:41:17 / cg"
       
  1023 !
       
  1024 
       
  1025 htmlName:colorName ifIllegal:errorBlock
       
  1026     "see https://en.wikipedia.org/wiki/Web-safe#HTML_color_names
       
  1027      The web defines 16 standard color names, which are returned here. 
       
  1028      If aString is not a valid color name,
       
  1029      return the result from evaluating errorBlock.
       
  1030      Attention:
       
  1031         these are not the same colors as those built into X-servers;
       
  1032         eg. (Color name:'green') returns a bright green,
       
  1033         whereas (Color htmlName:'green') returns a dark green, and 'lime' would be the X-green.
       
  1034         Sigh"
       
  1035 
       
  1036     |nameLowercase|
       
  1037 
       
  1038     nameLowercase := colorName asLowercase.
       
  1039     ^ #(
       
  1040         ('silver'  16rC0C0C0)
       
  1041         ('maroon'  16r800000)
       
  1042         ('olive'   16r808000)
       
  1043         ('lime'    16r00FF00)
       
  1044         ('green'   16r008000)
       
  1045         ('aqua'    16r00FFFF)
       
  1046         ('teal'    16r008080)
       
  1047         ('navy'    16r000080)
       
  1048         ('fuchsia' 16rFF00FF)
       
  1049         ('purple'  16r800080)
       
  1050     ) 
       
  1051         detect:[:e | e first = nameLowercase]
       
  1052         thenCompute:[:e | self rgbValue:(e second)]
       
  1053         ifNone:[ self name:colorName ifIllegal:errorBlock ]
       
  1054 
       
  1055     "
       
  1056      Color htmlName:'lime'
       
  1057 
       
  1058      Color htmlName:'green'
       
  1059      Color name:'green'
       
  1060     "
       
  1061 
       
  1062     "Created: / 17-02-2017 / 12:42:01 / cg"
   997 !
  1063 !
   998 
  1064 
   999 hue:h light:l saturation:s
  1065 hue:h light:l saturation:s
  1000     "return a color from hue, light and saturation values.
  1066     "return a color from hue, light and saturation values.
  1001      Hue is in degrees (0..360); light and saturation are
  1067      Hue is in degrees (0..360); light and saturation are