matrix

package
v0.6.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package matrix contains legacy helpers for editing matrix frames and running blocking matrix effects.

Deprecated: use pkg/effects for deterministic frame generation and pkg/effects/adapters for live LAN rendering. The matrix package remains for compatibility with existing callers.

Index

Constants

View Source
const (
	AlignLeft alignment = iota
	AlignCenter
	AlignRight
)

Variables

View Source
var ErrMissingColors = errors.New("missing colors")
View Source
var ErrStopped = fmt.Errorf("manual stop")

ErrStopped is the error returned when manually stopping an effect.

Functions

func ConcentricFrames deprecated added in v0.2.5

func ConcentricFrames(m *Matrix, send SendFunc, sendIntervalMs int64, cycles int, mode ChainMode, direction AnimationDirection, colors ...packets.LightHsbk) error

ConcentricFrames iterates according to the given direction drawing frams of variadic sizes. If an optional set of colors is supplied, it is used as the frame colors, otherwise the frame color will randomly change at each iteration. It repeats for n cycles, if cycles is set to 0 it repeats indefinitely.

Deprecated: use effects.NewConcentricFrames with effects.Render for offline frames, or effects/adapters.RunEffects for live rendering.

func NewColorSlice added in v0.2.5

func NewColorSlice(length int, palette ...packets.LightHsbk) []packets.LightHsbk

NewColorSlice returns a []packets.LightHsbk of the specific length according to the palette. It the palette is shorter than the length then it rotates through it to fill up the slice.

func Rockets deprecated

func Rockets(m *Matrix, send SendFunc, sendIntervalMs int64, cycles int, mode ChainMode, colors ...packets.LightHsbk) error

Rockets sequentially applies a color to a single pixel row by row wrapping at the end. It waits for the given interval before setting the next pixel. If multiple colors are provided colors are rotated on each row. It repeats for n cycles, if cycles is set to 0 it repeats indefinitely.

Deprecated: use effects.NewRockets with effects.Render for offline frames, or effects/adapters.RunEffects for live rendering.

func Snake deprecated

func Snake(m *Matrix, send SendFunc, sendIntervalMs int64, cycles int, mode ChainMode, size int, color packets.LightHsbk) error

Snake moves n pixels along the matrix wrapping and reversing at every row. It repeats for n cycles, if cycles is set to 0 it repeats indefinitely.

Deprecated: use effects.NewSnake with effects.Render for offline frames, or effects/adapters.RunEffects for live rendering.

func Waterfall deprecated

func Waterfall(m *Matrix, send SendFunc, sendIntervalMs int64, cycles int, mode ChainMode, colors ...packets.LightHsbk) error

Waterfall applies the given colors sequentially on each row centering them, if possible. It waits for the given interval before setting the next row. It repeats for n cycles, if cycles is set to 0 it repeats indefinitely.

Deprecated: use effects.NewWaterfall with effects.Render for offline frames, or effects/adapters.RunEffects for live rendering.

func Worm deprecated

func Worm(m *Matrix, send SendFunc, sendIntervalMs int64, cycles int, mode ChainMode, size int, color packets.LightHsbk) error

Worm moves n pixels along the matrix wrapping and reversing at every row with a wave-like movement. It repeats for n cycles, if cycles is set to 0 it repeats indefinitely.

Deprecated: use effects.NewWorm with effects.Render for offline frames, or effects/adapters.RunEffects for live rendering.

Types

type AnimationDirection added in v0.3.0

type AnimationDirection int
const (
	AnimationDirectionInwards AnimationDirection = iota
	AnimationDirectionOutwards
	AnimationDirectionInOut
	AnimationDirectionOutIn
)

func ParseAnimationDirection added in v0.2.6

func ParseAnimationDirection(m int) AnimationDirection

ParseAnimationDirection converts an int to AnimationDirection. If invalid it return AnimationDirectionInwards.

type ChainMode added in v0.3.0

type ChainMode int
const (
	// ChainModeNone applies the effect to the first device in the chain.
	ChainModeNone ChainMode = iota
	// ChainModeSequential applies the effect sequentially on each chain index.
	ChainModeSequential
	// ChainModeSynced applies the effect to the whole chain.
	ChainModeSynced
)

func ParseChainMode added in v0.2.3

func ParseChainMode(m int) ChainMode

ParseChainMode converts an int to chainmode. If invalid it return ChainModeNone.

type Matrix

type Matrix struct {
	Width       int
	Height      int
	Size        int
	Colors      [][]packets.LightHsbk
	ChainLength int
}

Matrix represents a LIFX device with matrix capability.

func New

func New(width, height, chainLength int) *Matrix

New creates a Matrix of the given size and chain length.

func (*Matrix) Clear

func (m *Matrix) Clear(pixels ...Pixel)

Clear sets pixels colors to their default value. If no pixels are given, it clears the whole matrix.

func (*Matrix) CopyRow added in v0.2.5

func (m *Matrix) CopyRow(dstY, srcY int)

CopyRow applies the colors of a src row to the dst row. If dstY or srcY are invalid it does nothing.

func (*Matrix) DrawSquare added in v0.2.5

func (m *Matrix) DrawSquare(x, y, length int, palette ...packets.LightHsbk)

func (*Matrix) Flatten added in v0.3.0

func (m *Matrix) Flatten() []packets.LightHsbk

Flatten flattens the matrix into a slice of LightHsbk colors.

func (*Matrix) FlattenColors

func (m *Matrix) FlattenColors() [64]packets.LightHsbk

FlattenColors converts the Colors' matrix into a 64-byte array that can be used with the LIFX protocol. DEPRECATED Use Flatten instead.

func (*Matrix) MaxPadding added in v0.2.5

func (m *Matrix) MaxPadding() int

func (*Matrix) MaxX

func (m *Matrix) MaxX() int

MaxX is the last valid row index.

func (*Matrix) MaxY

func (m *Matrix) MaxY() int

MaxY is the last valid column index.

func (*Matrix) ParseColors added in v0.2.10

func (m *Matrix) ParseColors(colors [64]packets.LightHsbk)

func (*Matrix) SetBorder added in v0.2.5

func (m *Matrix) SetBorder(padding int, colors ...packets.LightHsbk)

func (*Matrix) SetColors

func (m *Matrix) SetColors(x, y int, cs ...packets.LightHsbk)

SetColors sets the given colors starting at the given position and, if necessary, wrapping to the next row.

func (*Matrix) SetCorners

func (m *Matrix) SetCorners(palette ...packets.LightHsbk)

SetCorners sets the corners of a matrix to the given palette. It accepts up to 4 colors and if fewer are provided it rotates through them.

func (*Matrix) SetHorizontalSegment added in v0.2.5

func (m *Matrix) SetHorizontalSegment(x, y, length int, palette ...packets.LightHsbk)

SetHorizontalSegment sets a section of row y to the given palette starting at column x.

func (*Matrix) SetPixel

func (m *Matrix) SetPixel(x, y int, c packets.LightHsbk)

SetPixel sets a single pixel to the given color

func (*Matrix) SetVerticalSegment added in v0.2.5

func (m *Matrix) SetVerticalSegment(x, y, length int, palette ...packets.LightHsbk)

SetVerticalSegment sets a section of a column x to the given palette starting at row y.

func (*Matrix) SetXForAlignment added in v0.2.5

func (m *Matrix) SetXForAlignment(a alignment, length int) int

SetXForAlignment sets x according to the given alignment.

type Pixel

type Pixel struct {
	X, Y int
}

type PixelCache

type PixelCache struct {
	// contains filtered or unexported fields
}

PixelCache is a convenience structure to cache pixels.

func NewPixelCache

func NewPixelCache(size int) *PixelCache

NewPixelCache initialises a PixelCache.

func (*PixelCache) GetPixel

func (c *PixelCache) GetPixel(i int) *Pixel

GetPixel returns the Pixel pointer at the given index It panics if the given index is not between 0 and size.

func (*PixelCache) IsSet

func (c *PixelCache) IsSet(i int) bool

IsSet returns true if a pixel at the given index is set.

func (*PixelCache) Pixels

func (c *PixelCache) Pixels() []Pixel

Pixels returns a slice of Pixel values as set in the cache. Any nil value is returned as a Pixel with default values.

func (*PixelCache) SetPixel

func (c *PixelCache) SetPixel(i, x, y int)

SetPixel sets the Pixel at the given index. It panics if the given index is not between 0 and size.

type SendFunc

type SendFunc = func(msg *protocol.Message) error

SendFunc is an interface for sending protocol messages.

func SendWithStop added in v0.2.2

func SendWithStop(send SendFunc) (SendFunc, *atomic.Bool)

SendWithStop wraps a SendFunc with an atomic.Bool to manually stop the sender at the next cycle.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL