leddraw

package
v0.0.0-...-b509ac4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntensityFunc

type IntensityFunc func(distance float64) float64

IntensityFunc is a function that calculates the intensity of a pixel based on the distance between the pixel and the nearest LED. The intensity is a value between 0 and 1, where 0 is the lowest intensity and 1 is the highest intensity.

For examples of intensity functions visualized, see https://www.desmos.com/calculator/thw9ho0ivd.

func NewCubicIntensity

func NewCubicIntensity(maxDistance float64) IntensityFunc

NewCubicIntensity creates a new IntensityFunc that calculates the intensity of a pixel based on the distance between the pixel and the nearest LED. The intensity is calculated using a cubic function.

func NewLinearIntensity

func NewLinearIntensity(maxDistance float64) IntensityFunc

NewLinearIntensity creates a new IntensityFunc that calculates the intensity of a pixel based on the distance between the pixel and the nearest LED. The intensity is calculated using a linear function.

func NewStepIntensity

func NewStepIntensity(maxDistance float64) IntensityFunc

NewStepIntensity creates a new IntensityFunc that calculates the intensity of a pixel based on the distance between the pixel and the nearest LED. The intensity is 1 if the distance is less than the max distance, and 0 otherwise.

type LEDCanvas

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

LEDCanvas is a canvas of LED points.

func NewLEDCanvas

func NewLEDCanvas(ledPositions []image.Point, opts LEDCanvasOpts) (*LEDCanvas, error)

NewLEDCanvas creates a new LEDCanvas from the given LED positions.

ledPositions is a slice of points, where each point represents the position of an LED.

func (*LEDCanvas) CanvasBounds

func (c *LEDCanvas) CanvasBounds() image.Rectangle

Bounds returns the bounds of the image canvas.

func (*LEDCanvas) Clear

func (c *LEDCanvas) Clear()

Clear clears the LED canvas.

func (*LEDCanvas) LEDBounds

func (c *LEDCanvas) LEDBounds() image.Rectangle

LEDBounds returns the boundary box of the LEDs on the LED canvas. The boundary box is the smallest rectangle that contains all LEDs.

func (*LEDCanvas) LEDs

func (c *LEDCanvas) LEDs() LEDStrip

LEDs returns the internal buffer of the LED canvas.

func (*LEDCanvas) Render

func (c *LEDCanvas) Render(src *image.RGBA) error

Render renders the given image to the LED canvas. The alpha channel of the image is ignored.

func (*LEDCanvas) Stride

func (c *LEDCanvas) Stride() int

Stride returns the stride of the LED canvas.

type LEDCanvasAnimated

type LEDCanvasAnimated struct {
	C <-chan animation.Frame[LEDStrip]
	// contains filtered or unexported fields
}

LEDCanvas wraps an LEDCanvas and provides animation capabilities. Frames are sent to the C channel.

func NewLEDCanvasAnimated

func NewLEDCanvasAnimated(ledPositions []image.Point, opts LEDCanvasOpts) (*LEDCanvasAnimated, error)

NewLEDCanvasAnimated creates a new LEDCanvasAnimated.

func (*LEDCanvasAnimated) AddFrames

func (c *LEDCanvasAnimated) AddFrames(ctx context.Context, images []animation.Frame[*image.RGBA]) error

AddFrames adds frames to the animated canvas.

func (*LEDCanvasAnimated) Run

func (c *LEDCanvasAnimated) Run(ctx context.Context) error

Run starts the animated canvas player.

type LEDCanvasOpts

type LEDCanvasOpts struct {
	// Intensity is the intensity function used to calculate the intensity of a
	// pixel based on the distance between the pixel and the nearest LED.
	Intensity IntensityFunc
	// Average is the averaging function used to average the colors of the
	// pixels that are within the radius of an LED.
	Average xcolor.AveragingFunc
	// PPI is the number of pixels per inch of the final LED canvas. The higher
	// the PPI, the higher the resolution of the final LED canvas.
	PPI float64
}

LEDCanvasOpts is a set of options for creating a new LEDCanvas.

type LEDStrip

type LEDStrip []xcolor.RGB

LEDStrip is a strip of LEDs. It is represented as a slice of colors, where each color represents the color of an LED.

func (LEDStrip) Clear

func (s LEDStrip) Clear()

Clear clears the LED strip.

func (LEDStrip) Set

func (s LEDStrip) Set(i int, c color.Color)

Set sets the color of the LED at index i.

func (LEDStrip) SetRGBA

func (s LEDStrip) SetRGBA(i int, c color.RGBA)

Setxcolor.RGBA sets the xcolor.RGBA color of the LED at index i. Alpha is ignored.

type PtDistance

type PtDistance struct {
	Pt1, Pt2 image.Point
	Distance float64
}

PtDistance is a pair of points and the distance between them.

func FindMinDistance

func FindMinDistance(points []image.Point) PtDistance

FindMinDistance returns the pair of points with the smallest distance between them. It runs in O(n^2) time.

Jump to

Keyboard shortcuts

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