ledsgo

package module
v0.0.0-...-0aefdb2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2020 License: BSD-3-Clause Imports: 1 Imported by: 0

README

Color utilities for LED animations

This package is a collection of some utility functions for working with color. It is primarily intended for LED animations on microcontrollers using TinyGo, therefore it has been optimized for devices without FPU.

It is inspired by FastLED but does not implement any drivers for LED strips to keep development focused on fast animations.

Noise functions

This package contains a number of Simplex noise functions. Simplex noise is very similar to Perlin noise and produces naturally looking gradients as you might encounter in nature. It is commonly used as a building block for animations, especially in procedurally generated games.

Be warned that Simplex noise is patented (set to expire on 2022-01-18) so use at your own risk for computer graphics. This patent may or may not apply to LED animations, I don't know.

Animation demos

There is a demos subpackage which contains a number of simple animations that can be directly applied to surfaces implementing the Displayer interface.

License

This package is licensed under a BSD-style license, see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAlpha

func ApplyAlpha(c color.RGBA, alpha uint8) color.RGBA

ApplyAlpha scales the color with the given alpha. It can be used to reduce the intensity of a given color. The color is assumed to be linear, not sRGB.

func Blend

func Blend(bottom, top color.RGBA) color.RGBA

Blend blends two colors together, assuming the colors are linear (not sRGB). The bottom alpha is assumed to be 0xff. The top alpha is used to blend the two colors together.

func Noise1

func Noise1(x int32) int16

1D simplex noise.

The x input is a 19.12 fixed-point value. The result covers the full range of an int16 so is a 0.15 fixed-point value.

func Noise2

func Noise2(x, y int32) int16

2D simplex noise.

The x and y inputs are 19.12 fixed-point value. The result covers the full range of an int16 so is a 0.15 fixed-point value.

func Noise3

func Noise3(x, y, z int32) int16

3D simplex noise.

The x and y inputs are 19.12 fixed-point value. The result covers the full range of an int16 so is a 0.15 fixed-point value.

func Noise4

func Noise4(x, y, z, w int32) int16

4D simplex noise.

The x, y, z, and w inputs are 19.12 fixed-point value. The result covers the full range of an int16 so is a 0.15 fixed-point value.

func Sqrt

func Sqrt(x int) int

Sqrt is a fast integer square root function that returns a result at most one off of the intended result. It can be used in place of a floating-point square root function. Negative values are accepted and result in 0.

Types

type Color

type Color struct {
	H uint16 // hue
	S uint8  // saturation
	V uint8  // value
}

Color encodes a HSV color.

The hue is 16-bits to get better looking colors, as HSV→RGB conversions generally can use more than 8 hue bits for their conversion. Saturation and value are both just 8 bits because saturation is not that often used and value does not gain much precision with extra bits. This encoding has been chosen to have the best colors while still fitting in 32 bits.

func (Color) Spectrum

func (c Color) Spectrum() color.RGBA

Return the RGB version of this color, calculated with the common HSV conversion: https://github.com/FastLED/FastLED/wiki/FastLED-HSV-Colors

type Strip

type Strip []color.RGBA

The LEDs of a LED strip. Colors are represented in RGB form: 0x00rrggbb.

func (Strip) FillSolid

func (s Strip) FillSolid(color color.RGBA)

FillSolid sets all colors to the given value.

func (Strip) FillSpectrum

func (s Strip) FillSpectrum(start Color, hueinc uint16)

Fill the LED strip with a color range, using the HSV spectrum conversion. The start color is the color for the first LED. All other colors have the same saturation and value but increased (and wrapped) hue.

Directories

Path Synopsis
Package patterns implements a number of animations for small LED displays.
Package patterns implements a number of animations for small LED displays.

Jump to

Keyboard shortcuts

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