libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
color.h
Go to the documentation of this file.
1/*
2TODO:
3- Add Blend(), Scale(), etc.
4- I'd also like to change the way the Color names are accessed.
5*/
10#pragma once
11#ifndef DSY_COLOR_H
12#define DSY_COLOR_H
13#include <stdint.h>
14
15
16namespace daisy
17{
23class Color
24{
25 public:
26 Color() : red_(0.f), green_(0.f), blue_(0.f) {}
27 Color(float r, float g, float b) : red_(r), green_(g), blue_(b) {}
28 ~Color() {}
29
43
48
55 void Init(float red, float green, float blue);
56
58 inline float Red() const { return red_; }
59
61 inline float Green() const { return green_; }
62
64 inline float Blue() const { return blue_; }
65
66 inline uint8_t Red8() const { return red_ * 255; }
67 inline uint8_t Green8() const { return green_ * 255; }
68 inline uint8_t Blue8() const { return blue_ * 255; }
69
70 inline void SetRed(const float amt) { red_ = amt; }
71 inline void SetGreen(const float amt) { green_ = amt; }
72 inline void SetBlue(const float amt) { blue_ = amt; }
73
76 {
77 Color c;
78 c.Init(red_ * scale, green_ * scale, blue_ * scale);
79 return c;
80 }
81
84 {
85 float r_ = red_ + rhs.Red();
86 float g_ = green_ + rhs.Green();
87 float b_ = blue_ + rhs.Blue();
88 if(r_ > 1.f)
89 r_ = 1.f;
90 if(g_ > 1.f)
91 g_ = 1.f;
92 if(b_ > 1.f)
93 b_ = 1.f;
94 Color c(r_, g_, b_);
95 return c;
96 }
97
99 static Color Blend(const Color a, const Color b, const float amt)
100 {
101 float scalar = amt > 1.f ? 1.f : amt < 0.f ? 0.f : amt;
102 float nr = a.Red() + (b.Red() - a.Red()) * scalar;
103 float ng = a.Green() + (b.Green() - a.Green()) * scalar;
104 float nb = a.Blue() + (b.Blue() - a.Blue()) * scalar;
105
107 return new_color;
108 }
109
110
111 private:
112 static const float standard_colors[LAST][3];
113 float red_, green_, blue_;
114};
116} // namespace daisy
117
118#endif
Definition color.h:24
void Init(PresetColor c)
Color(float r, float g, float b)
Definition color.h:27
void SetBlue(const float amt)
Definition color.h:72
void Init(float red, float green, float blue)
Color()
Definition color.h:26
void SetGreen(const float amt)
Definition color.h:71
void SetRed(const float amt)
Definition color.h:70
float Green() const
Definition color.h:61
float Blue() const
Definition color.h:64
static Color Blend(const Color a, const Color b, const float amt)
Definition color.h:99
Color operator*(float scale)
Definition color.h:75
uint8_t Green8() const
Definition color.h:67
float Red() const
Definition color.h:58
uint8_t Blue8() const
Definition color.h:68
~Color()
Definition color.h:28
Color operator+(Color rhs)
Definition color.h:83
uint8_t Red8() const
Definition color.h:66
PresetColor
Definition color.h:32
@ GOLD
Definition color.h:39
@ GREEN
Definition color.h:34
@ LAST
Definition color.h:41
@ BLUE
Definition color.h:35
@ OFF
Definition color.h:40
@ WHITE
Definition color.h:36
@ RED
Definition color.h:33
@ CYAN
Definition color.h:38
@ PURPLE
Definition color.h:37
Definition leddriver.h:33
void Init(I2CHandle i2c, const uint8_t(&addresses)[numDrivers], DmaBuffer dma_buffer_a, DmaBuffer dma_buffer_b, Pin oe_pin=Pin(PORTX, 0))
Definition leddriver.h:65
Hardware defines and helpers for daisy field platform.
Definition index.h:2