Learn about how to create and assign colors

Colors can be set for all objects in the window. All have a color method that can be used to get and set colors, for example:

# Create a new, green square 'green')

# Create a square, then set its color later
s =
s.color = 'blue'

# Use hexadecimal values to set a color
s.color = '#ff0000'

# Use red, green, blue, alpha values to set the color
s.color = [1, 0.5, 0.2, 1]

Colors are represented by the Color class. Colors can be created from keywords (based on css), a hexadecimal value or an array containing a collection of red, green, blue, and alpha (transparency) values expressed as a Float from 0.0 to 1.0. Here are some examples for creating colors:<keyword>)<hex>)[r, g, b, a])
# Where...
#   `r` is red
#   `g` is green
#   `b` is blue
#   `a` is the alpha channel, which affects opacity

A color keyword can be any one of the following: navy blue aqua teal olive green lime yellow orange red brown fuchsia purple maroon white silver gray black

Additionally, use 'random' to produce a random color value.


Change the opacity, or transparency, of an object by using the opacity method:

square.color.opacity = 0.5

Continue to the next topic ▸

✏️ Suggest an edit to this page