Skip to content

Tree

Contains all the methods you need to change the tree. (Where the magic happens)

Tree()

This is a class which holds the tree data, it shouldn't be used directly

init(tree_file)

For internal use Initialise / reset the tree

height()

The height of the tree

Examples:

if pixel.z < height() / 2: pixel.set_rgb(255, 255, 255)

num_pixels()

The number of pixels, equivelant to len(pixels()) but faster

pixels(n=None)

pixels() -> list[Pixel]
pixels(n: int) -> Pixel

The main way of accessing pixels

Parameters:

Name Type Description Default
n Optional[int]

Grab only the nth pixel

None

Examples:

for pixel in pixels(): pixel.set_rgb(255, 255, 255)

for i in range(num_pixels()): pixels(i).set_rgb(255, 255, 255)

set_pixel(n, color)

Set the Nth light in the strip to the specified color

Parameters:

Name Type Description Default
n int

The light you want to set

required
color Color

The color that you want to set the light to

required
Example
set_pixel(2, Color.black())

set_fps(fps)

Allows you to change the speed that you want the animation to run at. If unset, the default fps is 45

Parameters:

Name Type Description Default
fps int

target fps for the animation.

required
Example
set_fps(30)
def draw():
    pass # called 30 times per second

fade(n=10)

Fade the entire tree. fades the tree to black over n frames Args: n (int, optional): Unknown. Defaults to 10 Example:

def draw():
    fade(10)

background(c)

Set the background color of the tree if a pixel hasn't been directly set or no shape overlaps the pixel, it will be drawn as the background color.

removes any fading or lerping that might be applying

example:

background(Color.black())
def draw():
    set_pixel(1, Color.white())

fill(color)

Set all lights on the tree to one color

This differs from background as it is part of the 1st rendering layer, directly setting pixels

Parameters:

Name Type Description Default
color Color

The color you want to set the tree to

required

lerp(color, frames, fn=linear)

Lerp the entire tree from its current color to the target color over the specified amount of frames

Once lerp has been called, it will automatically interpolate every frame to the target. Subsequent calls with the same parameters will continue the lerp, not reset.

Parameters:

Name Type Description Default
color Color

Target color

required
frames int

The number of frames to perform the lerp over

required
fn Callable[[float], float]

Timing function from the Util module. Defaults to linear.

linear
Example
def draw():
    lerp(Color.black(), 10) # similar to fade

coords()

An array of 3d coordinates mapped directly to the pixels coords()[10] gives the xyz tuple of the 10th pixel in the strip equivelant to pixels(10).xyz

sleep(n)

sleep for n frames

example
def draw():
    lerp(Color.black(), 10)
    yield from sleep(10)

frame()

The current frame number since the start of the pattern example:

def draw():
    f = frame() # 1, 2, 3
    print(f"{f} frames since the pattern started")

seconds()

The number of seconds since the start of the pattern

millis()

The number of milliseconds since the start of the pattern

example
def draw():
    s = seconds()
    m = millis()
    print(f"{s}:{m} since the pattern started")