Documentation ¶
Overview ¶
anim1d is a package to draw 1D (line) animations.
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 FloatToUint8(x float32) uint8
- func Marshal(p Pattern) []byte
- type Aurore
- type Color
- type Crop
- type Cycle
- type Frame
- type Gradient
- type Loop
- type Mixer
- type NightSky
- type NightStar
- type NightStars
- type Painter
- type Pattern
- type PingPong
- type Rainbow
- type Repeated
- type Rotate
- type SPattern
- type Scale
- type ScalingType
- type Strip
- type ThumbnailsCache
- type Transition
- type TransitionType
- type WishingStar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FloatToUint8 ¶
Types ¶
type Aurore ¶
type Aurore struct { }
Aurore commence lentement, se transforme lentement et éventuellement disparait.
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) Add ¶
Add adds two color together with saturation, mixing according to the alpha channel.
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'.
func (*Color) UnmarshalJSON ¶
UnmarshalJSON decodes the string "#RRGGBB" to the color.
If unmarshalling fails, 'c' is not touched.
type Crop ¶
type Crop struct { Child SPattern Start int // Starting pixels to skip Length int // Length of the pixels to affect }
Crop draws a subset of a strip, not touching the rest.
type Cycle ¶
Cycle cycles between multiple patterns. It can be used as an animatable looping frame.
TODO(maruel): Blend between frames with TransitionType, defaults to step. TODO(maruel): Merge with Loop.
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) 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'.
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 Transition TransitionType // 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 Loop ¶
type Loop struct { Patterns []SPattern DurationShowMS uint32 // Duration for each pattern to be shown as pure DurationTransitionMS uint32 // Duration of the transition between two patterns Transition TransitionType // Type of transition, defaults to EaseOut if not set // contains filtered or unexported fields }
Loop rotates between all the animations.
Display starts with one DurationShow for Patterns[0], then starts looping. timeMS is not modified so it's like as all animations continued animating behind.
type Mixer ¶
type Mixer struct { Patterns []SPattern Weights []float32 // In theory Sum(Weights) should be 1 but it doesn't need to. For example, mixing a night sky will likely have all of the Weights set to 1. // contains filtered or unexported fields }
Mixer is a generic mixer that merges the output from multiple patterns.
It doesn't animate.
type NightSky ¶
type NightSky struct { Stars []Cycle Frequency float32 // Number of explosions by second. // contains filtered or unexported fields }
NightSky has:
- Stars
- WishingStar
- Aurores
- Super nova.
- Rotation de la terre?
- Station Internationale?
type NightStars ¶
type NightStars struct { Stars []NightStar Seed int // Change it to create a different pseudo-random animation. // contains filtered or unexported fields }
func (*NightStars) NextFrame ¶
func (e *NightStars) NextFrame(pixels Frame, timeMS uint32)
type Painter ¶
type Painter struct {
// contains filtered or unexported fields
}
Painter handles the "draw frame, write" loop.
func MakePainter ¶
MakePainter returns a Painter that manages updating the Patterns to the Strip.
func (*Painter) SetPattern ¶
SetPattern changes the current pattern to a new one.
The pattern is in JSON encoded format. The function will return an error if the encoding is bad. The function is synchronous, it returns only after the pattern was effectively set.
type Pattern ¶
type Pattern interface { // NextFrame 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 NextFrame() 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. NextFrame(pixels Frame, timeMS uint32) }
Pattern is a interface to draw an animated line.
type PingPong ¶
type PingPong struct { Child SPattern // [0] is the front pixel so the pixels are effectively drawn in reverse order. // TODO(maruel): PerMoveMS uint32 MovesPerSec float32 // Expressed in number of light jumps per second. // 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 ScalingType here.
type Rainbow ¶
type Rainbow struct {
// contains filtered or unexported fields
}
MakeRainbow 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 Rotate ¶
type Rotate struct { Child SPattern MovesPerSec float32 // Expressed in number of light jumps per second. // 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 ¶
func (*SPattern) UnmarshalJSON ¶
UnmarshalJSON decodes a Pattern.
It knows how to decode Color, Frame or other arbitrary Pattern.
If unmarshalling fails, 'f' is not touched.
type Scale ¶
type Scale struct { Child SPattern Scale ScalingType // Defaults to ScalingLinear Length int // A buffer of this length will be provided to Child and will be scaled to the actual pixels length Ratio float32 // Scaling ratio to use, <1 means smaller, >1 means larger. Only one of Length or Ratio can be used // contains filtered or unexported fields }
Scale adapts a larger or smaller patterns to the Strip size
This is useful to create smoother animations or scale down images.
type ScalingType ¶
type ScalingType string
ScalingType specifies a way to scales a pixel strip.
const ( ScalingNearestSkip ScalingType = "nearestskip" // Selects the nearest pixel but when upscaling, skips on missing pixels. ScalingNearest ScalingType = "nearest" // Selects the nearest pixel, gives a blocky view. ScalingLinear ScalingType = "linear" // Linear interpolation, recommended and default value. ScalingBilinear ScalingType = "bilinear" // Bilinear interpolation, usually overkill for 1D. )
type Strip ¶
type Strip interface { io.Closer // Write writes a new frame. Write(pixels Frame) error // MinDelay returns the minimum delay between each draw refresh. MinDelay() time.Duration }
Strip is an 1D output device.
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 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 DurationMS uint32 // Duration of the transition while both are rendered Transition TransitionType // 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) NextFrame ¶
func (t *Transition) NextFrame(pixels Frame, timeMS uint32)
type TransitionType ¶
type TransitionType string
TransitionType models visually pleasing transitions.
They are modeled against CSS transitions. https://www.w3.org/TR/web-animations/#scaling-using-a-cubic-bezier-curve
const ( TransitionEase TransitionType = "ease" TransitionEaseIn TransitionType = "ease-in" TransitionEaseInOut TransitionType = "ease-in-out" TransitionEaseOut TransitionType = "ease-out" // Recommended and default value. TransitionLinear TransitionType = "linear" TransitionStepStart TransitionType = "steps(1,start)" TransitionStepMiddle TransitionType = "steps(1,middle)" TransitionStepEnd TransitionType = "steps(1,end)" )
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 and use Mixer with Weights of 1.
func (*WishingStar) NextFrame ¶
func (w *WishingStar) NextFrame(pixels Frame, timeMS uint32)