Skip to content

Attributes

Attributes allow you to change parameters of your pattern while the pattern is running from the web interface, this helps create more dynamic and customizable patterns

Attributes should be initiallised before/outside of the draw() function

Attribute(name, value)

Bases: Generic[T], ABC

Only initialise attributes once in the run function

This class should not be instantiated, it is a base class

get()

Get the current value of the attribute

Returns:

Name Type Description
T T

The value of the attribute

set(value)

Set the value of the range.

The use of this is discouraged in a pattern, it is primarily an internal function

Parameters:

Name Type Description Default
value T

The value to set the attribute to

required

RangeAttr(name, value, min, max, step)

Bases: Attribute[float]

Used when you want to accept a value from a pre defined range

Parameters:

Name Type Description Default
name str

The name displayed on the interface

required
value float

The default starting value

required
min float

The minimum value accepted

required
max float

The maximum value accepted

required
step float

The resolution for the range

required
Example
speed = RangeAttr("speed", 0.2, -1, 1, 0.2)
def draw()
    print(speed.get())

ColorAttr(name, value)

Bases: Attribute[Color]

Used when you want to accept a color as an input

Parameters:

Name Type Description Default
name str

The name displayed on the interface

required
value Color

The initial color

required
Example
color1 = ColorAttr("color1", Color.red())
def draw()
    fill(color1.get())