Code Monkey home page Code Monkey logo

ledsgo's Introduction

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 the MIT license, just like the FastLED library. See the LICENSE file for details. Some code has been copied from the FastLED library, this is indicated in the code.

ledsgo's People

Contributors

aykevl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ledsgo's Issues

Blend: even for low values of top.A, bottom color appears mixed with top color

From my understanding the top color should have a minimal impact on the result for small values of top.A, or a zero impact if top.A == 0. Instead, in these cases top color values appear to be added to bottom color values.

Judging from my experiments with an LED strip, multiplying top color values with top.A seems to improve the result.

Color.Rainbow looks fainter than Color.Spectrum by a factor of Color.V/256

When comparing Color.Rainbow and Color.Spectrum using an LED strip,
I found that colors look quite dim when using the first function on the same HSV Color values.

This appears to be caused by a code sequence at the end of Color.Rainbow(), where color values get scaled down:

ledsgo/ledsgo.go

Lines 192 to 208 in bd2e91b

val = scale8_video(val, val)
if val == 0 {
r = 0
g = 0
b = 0
} else {
// nscale8x3_video( r, g, b, val);
if r != 0 {
r = scale8(r, val)
}
if g != 0 {
g = scale8(g, val)
}
if b != 0 {
b = scale8(b, val)
}
}

In this sequence, val is multiplicated twice with the resulting color values, by applying both scale8_video and scale8 with val arguments.

If, for instance, the V value of the original color was 80, the brightness of an RGB color calculated with Color.Spectrum will still be around 80. With color.Rainbow though, brightness will be around (80/255*80/255)*255 โ‰ˆ 25 only.
For an original Color.V value of 20, the color.Rainbow brightness will be < 2 (20*20/256).
See also this playground example: https://go.dev/play/p/i6Mi9ggVjq5

This behaviour appears to be implemented in FastLED already.
As a workaround, when using color.Rainbow, I'm multiplying the resulting R, G, B values
with 256 / V with V being the original Color.V value.
I guess it could be fixed by just deleting line 192, val = scale8_video(val, val), which would skip one extra multiplication with val. Since scale8_video only returns zero if both arguments are zero -- in this case, if val is zero --, deleting that line would preserve this feature.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.