Documentation ¶
Overview ¶
Package anim1d draws 1D (line) animations that are stateless.
That is, they can be played forward, backward, on multiple devices synchronized with only clock being synchronized.
It contains all the building blocks to create animations. All the animations are designed to be stateless and serializable so multiple devices can seamless synchronize.
Index ¶
- func MinMax(v, min, max int) int
- func MinMax32(v, min, max int32) int32
- type Add
- type Aurore
- type Bell
- type Chronometer
- type Color
- func (c *Color) Add(d Color)
- func (c *Color) At(x, y int) color.Color
- func (c *Color) Bounds() image.Rectangle
- func (c *Color) ColorModel() color.Model
- func (c *Color) Dim(intensity uint8)
- func (c *Color) FromRGBString(s string) error
- func (c *Color) FromString(s string) error
- func (c *Color) MarshalJSON() ([]byte, error)
- func (c *Color) Mix(d Color, gradient uint8)
- func (c *Color) Render(pixels Frame, timeMS uint32)
- func (c *Color) String() string
- func (c *Color) UnmarshalJSON(b []byte) error
- type Const
- type Crop
- type Curve
- type Dim
- type Frame
- func (f Frame) Add(r Frame)
- func (f Frame) At(x, y int) color.Color
- func (f Frame) Bounds() image.Rectangle
- func (f Frame) ColorModel() color.Model
- func (f Frame) Dim(intensity uint8)
- func (f *Frame) FromString(s string) error
- func (f Frame) MarshalJSON() ([]byte, error)
- func (f Frame) Mix(b Frame, gradient uint8)
- func (f Frame) Render(pixels Frame, timeMS uint32)
- func (f Frame) String() string
- func (f Frame) ToRGB(b []byte)
- func (f *Frame) UnmarshalJSON(b []byte) error
- type Gradient
- type Interpolation
- type Lightning
- type Loop
- type MovePerHour
- type NightStars
- type OpAdd
- type OpMod
- type OpStep
- type Pattern
- type Percent
- type PingPong
- type Rainbow
- type Rand
- type Repeated
- type Rotate
- type SPattern
- type SValue
- type Scale
- type Split
- type Subset
- type ThumbnailsCache
- type Thunderstorm
- type Transition
- type Value
- type WishingStar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Add ¶
type Add struct { Patterns []SPattern // It should be a list of Dim{} with their corresponding weight. // contains filtered or unexported fields }
Add is a generic mixer that merges the output from multiple patterns with saturation.
type Aurore ¶
type Aurore struct { }
Aurore is an experimental generator.
It starts slowly, slowly transform itself then disappear.
type Bell ¶
type Bell struct{}
Bell is a "good enough" approximation of a gaussian curve by using 2 symmetrical ease-in-out bezier curves.
It is not named Gaussian since it is not a gaussian curve; it really is a bell.
type Chronometer ¶
type Chronometer struct { Child SPattern // contains filtered or unexported fields }
Chronometer moves 3 lights to the right, each indicating second, minute, and hour passed since the start.
Child has 4 pixels used in this order: [default, second, minute, hour].
func (*Chronometer) Render ¶
func (r *Chronometer) Render(pixels Frame, timeMS uint32)
Render implements Pattern.
type Color ¶
type Color struct {
R, G, B uint8
}
Color shows a single color on all lights. It knows how to renders itself into a frame.
If you want a single dot, use a Frame of length one.
func (*Color) ColorModel ¶ added in v1.0.1
ColorModel implements image.Image.
func (*Color) Dim ¶
Dim reduces the intensity of a color/pixel to scale it on intensity.
0 means completely dark, 255 the color c is unaffected.
func (*Color) FromRGBString ¶
FromRGBString converts a "RRGGBB" encoded string to a Color.
'c' is untouched in case of error.
func (*Color) FromString ¶
FromString converts a "#RRGGBB" encoded string to a Color.
'c' is untouched in case of error.
func (*Color) MarshalJSON ¶
MarshalJSON encodes the color as a string "#RRGGBB".
func (*Color) Mix ¶
Mix blends the second color with the first.
gradient 0 means pure 'c', gradient 255 means pure 'd'.
It is the equivalent of:
c.Dim(255-gradient) d.Dim(gradient) c.Add(d)
except that this function doesn't affect d.
func (*Color) UnmarshalJSON ¶
UnmarshalJSON decodes the string "#RRGGBB" to the color.
If unmarshalling fails, 'c' is not touched.
type Const ¶
type Const int32
Const is a constant value.
func (*Const) MarshalJSON ¶
MarshalJSON encodes the const as a int.
func (*Const) UnmarshalJSON ¶
UnmarshalJSON decodes the int to the const.
If unmarshalling fails, 'c' is not touched.
type Crop ¶
type Crop struct { Child SPattern Before SValue // Starting pixels to skip After SValue // Ending pixels to skip // contains filtered or unexported fields }
Crop skips the beginning and the end of the source.
type Curve ¶
type Curve string
Curve models visually pleasing curves.
They are modeled against CSS transitions. https://www.w3.org/TR/web-animations/#scaling-using-a-cubic-bezier-curve
const ( Ease Curve = "ease" EaseIn Curve = "ease-in" EaseInOut Curve = "ease-in-out" EaseOut Curve = "ease-out" // Recommended and default value. Direct Curve = "direct" // linear mapping StepStart Curve = "steps(1,start)" StepMiddle Curve = "steps(1,middle)" StepEnd Curve = "steps(1,end)" )
All the kind of known curves.
type Dim ¶
type Dim struct { Child SPattern // Intensity SValue // 0 is transparent, 255 is fully opaque with original colors. }
Dim is a filter that dim the intensity of a buffer.
type Frame ¶
type Frame []Color
Frame is a strip of colors. It knows how to renders itself into a frame (which is recursive).
func (Frame) ColorModel ¶ added in v1.0.1
ColorModel implements image.Image.
func (*Frame) FromString ¶
FromString converts a "LRRGGBB..." encoded string to a Frame.
'f' is untouched in case of error.
func (Frame) MarshalJSON ¶
MarshalJSON encodes the frame as a string "LRRGGBB...".
func (Frame) Mix ¶
Mix blends the second frame with the first.
gradient 0 means pure 'f', gradient 255 means pure 'b'.
It is the equivalent of:
c.Dim(255-gradient) d.Dim(gradient) c.Add(d)
except that this function doesn't affect d.
func (*Frame) UnmarshalJSON ¶
UnmarshalJSON decodes the string "LRRGGBB..." to the colors.
If unmarshalling fails, 'f' is not touched.
type Gradient ¶
type Gradient struct { Left SPattern Right SPattern Curve Curve // contains filtered or unexported fields }
Gradient does a gradient between 2 patterns.
A good example is using two colors but it can also be animations.
TODO(maruel): Support N colors at M positions.
type Interpolation ¶
type Interpolation string
Interpolation specifies a way to scales a pixel strip.
const ( NearestSkip Interpolation = "nearestskip" // Selects the nearest pixel but when upscaling, skips on missing pixels. Nearest Interpolation = "nearest" // Selects the nearest pixel, gives a blocky view. Linear Interpolation = "linear" // Linear interpolation, recommended and default value. )
All the kinds of interpolations.
func (Interpolation) Scale ¶
func (i Interpolation) Scale(in, out Frame)
Scale interpolates a frame into another using integers as much as possible for reasonable performance.
type Lightning ¶
type Lightning struct { Center SValue // offset of the center, from the left HalfWidth SValue // in pixels Intensity int // the maximum intensity StartMS SValue // when it started }
Lightning is an experimental generator.
type Loop ¶
type Loop struct { Patterns []SPattern ShowMS uint32 // Duration for each pattern to be shown as pure TransitionMS uint32 // Duration of the transition between two patterns, can be 0 Curve Curve // Type of transition, defaults to EaseOut if not set // contains filtered or unexported fields }
Loop rotates between all the animations.
Display starts with one ShowMS for Patterns[0], then starts looping. timeMS is not modified so it's like as all animations continued animating behind. TODO(maruel): Add lateral transition and others.
type MovePerHour ¶
type MovePerHour SValue
MovePerHour is the number of movement per hour.
Can be either positive or negative. Maximum supported value is ±3600000, 1000 move/sec.
Sample values:
- 1: one move per hour
- 60: one move per minute
- 3600: one move per second
- 216000: 60 move per second
func (*MovePerHour) Eval ¶
func (m *MovePerHour) Eval(timeMS uint32, l int, cycle int) int
Eval is not a Value implementation but it leverages an inner one.
func (*MovePerHour) MarshalJSON ¶
func (m *MovePerHour) MarshalJSON() ([]byte, error)
MarshalJSON is because MovePerHour is a superset of SValue.
func (*MovePerHour) UnmarshalJSON ¶
func (m *MovePerHour) UnmarshalJSON(b []byte) error
UnmarshalJSON is because MovePerHour is a superset of SValue.
type NightStars ¶
type NightStars struct { C Color // contains filtered or unexported fields }
NightStars is an experimental generator.
func (*NightStars) Render ¶
func (n *NightStars) Render(pixels Frame, timeMS uint32)
Render implements Pattern.
type OpAdd ¶
type OpAdd struct {
AddMS int32
}
OpAdd adds a constant to timeMS.
func (*OpAdd) MarshalJSON ¶
MarshalJSON encodes the add as a string.
func (*OpAdd) UnmarshalJSON ¶
UnmarshalJSON decodes the add in the form of a string.
If unmarshalling fails, 'o' is not touched.
type OpMod ¶
type OpMod struct {
TickMS int32 // The cycling time. Maximum is ~25 days.
}
OpMod is a value that is cycling downward.
func (*OpMod) MarshalJSON ¶
MarshalJSON encodes the mod as a string.
func (*OpMod) UnmarshalJSON ¶
UnmarshalJSON decodes the mod in the form of a string.
If unmarshalling fails, 'o' is not touched.
type OpStep ¶
type OpStep struct {
TickMS int32 // The cycling time. Maximum is ~25 days.
}
OpStep is a value that is cycling upward.
It is useful for offsets that are increasing as a stepping function.
type Pattern ¶
type Pattern interface { // Render fills the buffer with the image at this time frame. // // The image should be derived from timeMS, which is the time since this // pattern was started. // // Calling Render() with a nil pattern is valid. Patterns should be callable // without crashing with an object initialized with default values. // // timeMS will cycle after 49.7 days. The reason it's not using time.Duration // is that int64 calculation on ARM is very slow and abysmal on xtensa, which // this code is transpiled to. Render(pixels Frame, timeMS uint32) }
Pattern is a interface to draw an animated line.
type Percent ¶
type Percent int32
Percent is a percentage of the length. It is stored as a 16.16 fixed point.
func (*Percent) MarshalJSON ¶
MarshalJSON encodes the percent as a string.
func (*Percent) UnmarshalJSON ¶
UnmarshalJSON decodes the percent in the form of a string.
If unmarshalling fails, 'p' is not touched.
type PingPong ¶
type PingPong struct { Child SPattern // [0] is the front pixel so the pixels are effectively drawn in reverse order MovePerHour MovePerHour // Expressed in number of light jumps per hour // contains filtered or unexported fields }
PingPong shows a 'ball' with a trail that bounces from one side to the other.
Can be used for a ball, a water wave or K2000 (Knight Rider) style light. The trail can be a Frame or a dynamic pattern.
To get smoothed movement, use Scale{} with a 5x factor or so. TODO(maruel): That's a bit inefficient, enable Interpolation here.
type Rainbow ¶
type Rainbow struct {
// contains filtered or unexported fields
}
Rainbow renders rainbow colors.
func (*Rainbow) MarshalJSON ¶
MarshalJSON encodes the rainbow as a string "Rainbow".
func (*Rainbow) UnmarshalJSON ¶
UnmarshalJSON decodes the string "Rainbow" to the rainbow.
type Rand ¶
type Rand struct {
TickMS int32 // The resolution at which the random value changes.
}
Rand is a value that pseudo-randomly changes every TickMS millisecond. If unspecified, changes every 60fps.
func (*Rand) MarshalJSON ¶
MarshalJSON encodes the rand as a string.
func (*Rand) UnmarshalJSON ¶
UnmarshalJSON decodes the string to the rand.
If unmarshalling fails, 'r' is not touched.
type Rotate ¶
type Rotate struct { Child SPattern MovePerHour MovePerHour // Expressed in number of light jumps per hour. // contains filtered or unexported fields }
Rotate rotates a pattern that can also cycle either way.
Use negative to go left. Can be used for 'candy bar'.
Similar to PingPong{} except that it doesn't bounce.
Use 5x oversampling with Scale{} to create smoother animation.
type SPattern ¶
type SPattern struct {
Pattern
}
SPattern is a Pattern that can be serialized.
It is only meant to be used in mixers.
func (*SPattern) MarshalJSON ¶
MarshalJSON includes the additional key "_type" to help with unmarshalling.
func (*SPattern) UnmarshalJSON ¶
UnmarshalJSON decodes a Pattern.
It knows how to decode Color, Frame or other arbitrary Pattern.
If unmarshalling fails, 's' is not touched.
type SValue ¶
type SValue struct {
Value
}
SValue is the serializable version of Value.
func (*SValue) MarshalJSON ¶
MarshalJSON includes the additional key "_type" to help with unmarshalling.
func (*SValue) UnmarshalJSON ¶
UnmarshalJSON decodes a Value.
It knows how to decode Const or other arbitrary Value.
If unmarshalling fails, 'f' is not touched.
type Scale ¶
type Scale struct { Child SPattern // Defaults to Linear Interpolation Interpolation // A buffer of this len(buffer)*RatioMilli/1000 will be provided to Child and // will be scaled; 500 means smaller, 2000 is larger. // // Can be set to 0 when Child is a Frame. In this case it is stretched to the // strip size. RatioMilli SValue // contains filtered or unexported fields }
Scale adapts a larger or smaller patterns to the Strip size
This is useful to create smoother horizontal movement animation or to scale up/down images.
type Split ¶
type Split struct { Left SPattern Right SPattern Offset SValue // Point to split between both sides. }
Split splits the strip in two.
Unlike gradient, this create 2 logical independent subsets.
type Subset ¶
type Subset struct { Child SPattern Offset SValue // Starting pixels to skip Length SValue // Length of the pixels to carry over }
Subset skips the beginning and the end of the destination.
type ThumbnailsCache ¶
type ThumbnailsCache struct { NumberLEDs int // Must be set before calling Thumbnail(). ThumbnailHz int // Must be set before calling Thumbnail(). ThumbnailSeconds int // Must be set before calling Thumbnail(). // contains filtered or unexported fields }
ThumbnailsCache is a cache of animated GIF thumbnails for each pattern.
type Thunderstorm ¶
type Thunderstorm struct {
AvgMS int // Average between lightning strikes
}
Thunderstorm creates strobe-like lightning.
func (*Thunderstorm) Render ¶
func (t *Thunderstorm) Render(pixels Frame, timeMS uint32)
Render implements Pattern.
type Transition ¶
type Transition struct { Before SPattern // Old pattern that is disappearing After SPattern // New pattern to show OffsetMS uint32 // Offset at which the transiton from Before->In starts TransitionMS uint32 // Duration of the transition while both are rendered Curve Curve // Type of transition, defaults to EaseOut if not set // contains filtered or unexported fields }
Transition changes from Before to After over time. It doesn't repeat.
In gets timeMS that is subtracted by OffsetMS.
func (*Transition) Render ¶
func (t *Transition) Render(pixels Frame, timeMS uint32)
Render implements Pattern.
type WishingStar ¶
type WishingStar struct { Duration time.Duration // Average duration of a star. AverageDelay time.Duration // Average delay between each wishing star. }
WishingStar draws a wishing star from time to time.
It will only draw one star at a time. To increase the likelihood of getting many simultaneously, create multiple instances.
func (*WishingStar) Render ¶
func (w *WishingStar) Render(pixels Frame, timeMS uint32)
Render implements Pattern.