Git Product home page Git Product logo

npbcolorlib's Introduction

NPBColorLib

Color representations and operations for NeoPixelBus.

The intention (of the author, me, Jack Jansen) is that Makuna will incorporate this into NeoPixelBus. License is LGPL.

Note: As of this writing the xxxFColor objects mimic the NeoPixelBus xxxColor objects, but this is open to change. Maybe the interpolation functions and such are useless and need to go. Also, HslFColor is included because I have a slight preference for HSL over HSB/HSV, but it can go.

Description

For all color representation objects I have tried to follow the API of NeoPixelBus as much as possible, with all uint8_t parameters replaced by float. This does have one significant drawback: if someone inadvertantly passes an uint8_t value it will result in pretty bright colors...

RgbFColor

RgbFColor represents an RGB color as three floating point numbers between 0.0 and 1.0. It can be casted to and from RgbColor.

RgbwFColor

RgbwFColor represents an RGBW color as four floating point numbers between 0.0 and 1.0. It can be casted to and from RgbwColor.

HslFColor

HslFColor represents a Hue, Saturation, Lightness color as 3 floats. The difference between HSL and HSV/HSB is that HSL has the 100% saturated colors at L=0.5, with L=1.0 being maximum light. HSV/HSB have 100% saturated colors at V=1.0, meaning that the total amount of light is dependent not only on L (or V or B) but also on the Hue and Saturation. HSL is more suitable for lighting applications.

TemperatureFColor

TemperatureFColor represents a color as two floating point numbers WTemperature (the black body temperature, usually between 2500 and 7000) and WBrightness, a value between 0.0 and 1.0. It can be casted to RgbFColor and RgbColor (but not the reverse). This conversion assumes that the white point of the RGB values is at 6500K (also known as D65).

Colorspace

Colorspace represents an RGBW colorspace, and is used to convert xxxFColor objects to either RgbColor or RgbwColor for sending to the LED strip.

In the constructor you provide:

  • the temperature of the White LED (usually 3000 for Warm, 4000 for Neutral and 5000 for Cool, but check the specifications of your LED strip)
  • the relative power of your White LED (default of 1.0 means the White LED has the same number of Lumen as the R, G and B LEDs combined. Again, check the specifications of your strip),
  • whether you want the conversion to maintain the hue as much as possible, or whether you prefer to maintain the brightness as much as possible,
  • whether you want to gamma-correct the RGB and RGBW values (you proabbly should).

An RgbwSpace object has a numnber of methods:

  • toRgbw() converts any of the xxxFColor objects to RgbwColor
  • toRgb() converts any of the xxxFColor objects to RgbColor (for use with RGB strips)
  • a convert(from, to) method with various signatures to convert in-place with as little copying as possible.

Examples

There are two examples:

  • whitecalibrate is actually more of a utility than an example: it allows you to determine the relative power of your white LED and its color temperature by flashing white color with first only RGB leds and then only White leds.
  • ledstripserver is a web server that allows interactive changing of colors of a LED strip (or scripted changing through use of curl or similar programs). It should be runnable on an esp32 or esp8266 and with a bit of work maybe also on Arduino hardware with a WiFi card.

npbcolorlib's People

Contributors

jackjansen avatar

Watchers

 avatar

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.