Scripton / Docs

Colors

You'll frequently see shapes accept two color parameters:

  • fill: The color used to fill the inside of the shape.
  • stroke: The color used to for the shape's outline.
canvas.draw_rect( x=100, y=75, width=100, height=50, # White rectangle with a red outline fill='#ffffff', stroke='#ff0000' )

For both fill and stroke, you can specify most valid CSS colors as strings. Briefly, these include —

  • RGB hex values of the form #RRGGBB:

    red = '#ff0000' crimson = '#dc143c'
  • You can also use the contracted #RGB variant that is equivalent to #RRGGBB:

    salmon = '#fab' # Same as #ffaabb white = '#fff' # Same as #ffffff
  • RGB tuples of the form rgb(R, G, B) where each component is a value between 0 and 255:

    crimson = 'rgb(220, 20, 60)' black = 'rgb(0, 0, 0)'
  • For semi-opaque colors, rgba(R, G, B, A) and #RRGGBBAA forms are accepted:

    # Alpha value as a normalized fraction in [0, 1] translucent_green = 'rgba(0, 255, 0, 0.5)' # Alpha value as a percentage translucent_red = 'rgba(255, 0, 0, 50%)' # Alpha value as hex translucent_blue = '#0000FF80'
  • HSL (Hue-Saturation-Lightness) values can be specified as hsl(H, S, L).

    # Hue expressed in degrees [0, 360°] # Saturation and Lightness expressed as percentages navy = 'hsl(240, 100%, 25%)'
  • You can also use one of the named colors:

    sea_green = 'seagreen' royal_blue = 'royalblue'