Colors

- XLogo library of procedures

xlogo

These procedures output a new color. Use them to change the pen color eg. SetPC Light Blue.

Download complete library of all color procedures.

Aqua
Return aqua color.

To Aqua
  Output [0 128 255]     # return aqua rgb color
End

Dark (also see Light)
Set the pen color to half way between the current pen color and black.
Also try a reduction value of 1.414 (Root2). Note that 'Dark Dark' will exactly halve each rgb value.

To Dark :Hue
  # output rgb list midway between :hue and black
  Repeat 3 [
    Make "Hue ButFirst LPut Int (First :Hue)/2 :Hue]
  Output :Hue
End

To Test
  # test procedure
  SetPC Gray Print PenColor
  SetPC Dark Gray Print PenColor
End

Hex
Return an RGB list of Hex value (must be contained in a list), where A=10, B=11, C=12, D=13, E=14 and F=15. Hex letters can be upper or lower case. Error if outside range.

To Hex :Num
  # convert hexadecimal value to RGB list
  If Not (Count :Num)=1 [Print [Hex value must be single number!] StopAll]
  ForEach "Hex First :Num [
    If Not Number? :Hex [
      Make "Hex Unicode :Hex
      If (:Hex>96) [Make "Hex :Hex-87]     # A to F
      If (:Hex>64) [Make "Hex :Hex-55]     # a to f
      If Or (:Hex<10) (:Hex>15) [Print [Hex value 0-9 and a-f only!] StopAll]]
    Make "Num LPut 17*:Hex :Num]
  Output ButFirst :Num
End

To Test
  # test procedure
  Make "Num [a7F]
  SetPC Hex :Num
  Print (Sentence [RGB PenColor value of] :Num [is] PenColor)
End

Hue
Return a color as an RGB list depending on an input angle. eg SetPC Hue 100. For blue, an angle of 220 can give a better color spread than 240. See resulting palette at RGB Colors.

To Hue :Theta
  # Output RGB hue list from angle :Theta
  Make "Red Round 127.5*(1+Sin :Theta)
  Make "Green Round 127.5*(1+Sin (:Theta+120))
  Make "Blue Round 127.5*(1+Sin (:Theta+240))
  Output (List :Red :Green :Blue)
End

Hue2
Return a color as an RGB list depending on an input angle. eg SetPC Hue2 150. See resulting palette at RGB Colors.

To Hue2 :Theta
  # Output RGB hue list from angle :Theta
  Make "Red Abs 255*Sin :Theta
  Make "Green Abs 255*Sin (:Theta+120)
  Make "Blue Abs 255*Sin (:Theta+240)
  Output (List :Red :Green :Blue)
End

Invert Color
Return inverted or negative color. Test by typing: SetSC Invert Red

To Invert :Color
  # return invert or negative color
  LocalMake "Red 128+(127-Item 1 :Color)
  LocalMake "Green 128+(127-Item 2 :Color)
  LocalMake "Blue 128+(127-Item 3 :Color)
  Output (List :Red :Green :Blue)
End

Leaf
Return leaf color.
Used in Swatch and YinYang.

To Leaf
  Output [0 255 128]     # return leaf rgb color
End

Light (also see Dark)
Set the pen color to half way between the current pen color and white.
Also try a value of 1.414 (Root2).

To Light :Hue
  # output rgb list midway between :hue and white
  Repeat 3 [
    Make "Hue ButFirst LPut Int (255+(First :Hue))/2 :Hue]
  Output :Hue
End

To Test
  # test procedure
  SetPC Gray Print PenColor
  SetPC Light Gray Print PenColor
End

Lime
Return lime color.

To Lime
  Output [128 255 0]     # return lime rgb color
End

RandHue
Return random color from list of favourite eleven.

To RandHue
  # return a random color of 11 hues
  Output Pick [
    [0 153 255] [0 170 0] [0 100 100] [0 255 170]
    [85 0 170] [127 63 63] [170 0 0] [170 85 255]
    [255 85 170] [255 100 0] [255 204 102] ]
End

RandRGB
Return random color list. Each value between 0 and 255, in steps of 255/:Ord-1. So if :Ord=4, then step size is 85. This gives 4 possible values of 0, 85, 171 or 255.

To RandRGB :Ord
  # return random RGB color
  Output (List Val :Ord Val :Ord Val :Ord)
End
To Val :Ord
  # return random value 0-255 in steps of 255/:Ord-1
  Output Int (Random :Ord)*(255/(:Ord-1))
End

Rose
Return rose color.

To Rose
  Output [255 0 128]     # return rose rgb color
End

xlogo
XLogo