Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color names (with and without underscores) #1309

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions src/Kaleidoscope-Colors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Kaleidoscope-Colors -- Color names for Kaleidoscope
* Copyright (C) 2019 JD Lien
* Copyright (C) 2017 Keyboard.io, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <kaleidoscope/colors.h>
286 changes: 286 additions & 0 deletions src/kaleidoscope/colors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
#pragma once

namespace kaleidoscope {
namespace colors {

// Here's a big list of color names based on the CSS color names.
constexpr cRGB warm_white = CRGB(255, 250, 200);
constexpr cRGB alice_blue = CRGB(240, 248, 255);
constexpr cRGB antique_white = CRGB(250, 235, 215);
constexpr cRGB aqua = CRGB(0, 255, 255);
constexpr cRGB aquamarine = CRGB(127, 255, 212);
constexpr cRGB azure = CRGB(240, 255, 255);
constexpr cRGB beige = CRGB(245, 245, 220);
constexpr cRGB bisque = CRGB(255, 228, 196);
constexpr cRGB black = CRGB(0, 0, 0);
constexpr cRGB blanched_almond = CRGB(255, 235, 205);
constexpr cRGB blue = CRGB(0, 0, 255);
constexpr cRGB blue_violet = CRGB(138, 43, 226);
constexpr cRGB brown = CRGB(165, 42, 42); //Looks more like dim red
constexpr cRGB burlywood = CRGB(222, 184, 135);
constexpr cRGB cadet_blue = CRGB(95, 158, 160);
constexpr cRGB chartreuse = CRGB(127, 255, 0);
constexpr cRGB chocolate = CRGB(210, 105, 30);
constexpr cRGB coral = CRGB(255, 127, 80);
constexpr cRGB cornflower_blue = CRGB(100, 149, 237);
constexpr cRGB cornsilk = CRGB(255, 248, 220);
constexpr cRGB crimson = CRGB(220, 20, 60);
constexpr cRGB cyan = CRGB(0, 255, 255);
constexpr cRGB dark_blue = CRGB(0, 0, 139);
constexpr cRGB dark_cyan = CRGB(0, 139, 139);
constexpr cRGB dark_goldenrod = CRGB(184, 134, 11);
constexpr cRGB dark_gray = CRGB(169, 169, 169);
constexpr cRGB dark_grey = CRGB(169, 169, 169);
constexpr cRGB dark_green = CRGB(0, 100, 0);
constexpr cRGB dark_khaki = CRGB(189, 183, 107);
constexpr cRGB dark_magenta = CRGB(139, 0, 139);
constexpr cRGB dark_olivegreen = CRGB(85, 107, 47);
constexpr cRGB dark_orange = CRGB(255, 140, 0);
constexpr cRGB dark_orchid = CRGB(153, 50, 204);
constexpr cRGB dark_red = CRGB(139, 0, 0);
constexpr cRGB dark_salmon = CRGB(233, 150, 122);
constexpr cRGB dark_sea_green = CRGB(143, 188, 143);
constexpr cRGB dark_slate_blue = CRGB(72, 61, 139);
constexpr cRGB dark_slate_gray = CRGB(47, 79, 79);
constexpr cRGB dark_slategrey = CRGB(47, 79, 79);
constexpr cRGB dark_turquoise = CRGB(0, 206, 209);
constexpr cRGB dark_violet = CRGB(148, 0, 211);
constexpr cRGB deep_pink = CRGB(255, 20, 147);
constexpr cRGB deep_skyblue = CRGB(0, 191, 255);
constexpr cRGB dim_gray = CRGB(105, 105, 105);
constexpr cRGB dim_grey = CRGB(105, 105, 105);
constexpr cRGB dodger_blue = CRGB(30, 144, 255);
constexpr cRGB fire_brick = CRGB(178, 34, 34);
constexpr cRGB floral_white = CRGB(255, 250, 240);
constexpr cRGB forest_green = CRGB(34, 139, 34);
constexpr cRGB fuchsia = CRGB(255, 0, 255);
constexpr cRGB gainsboro = CRGB(220, 220, 220);
constexpr cRGB ghost_white = CRGB(248, 248, 255);
constexpr cRGB gold = CRGB(255, 215, 0);
constexpr cRGB goldenrod = CRGB(218, 165, 32);
constexpr cRGB gray = CRGB(128, 128, 128);
constexpr cRGB grey = CRGB(128, 128, 128);
constexpr cRGB green = CRGB(0, 128, 0);
constexpr cRGB green_yellow = CRGB(173, 255, 47);
constexpr cRGB honeydew = CRGB(240, 255, 240);
constexpr cRGB hot_pink = CRGB(255, 105, 180);
constexpr cRGB indian_red = CRGB(205, 92, 92);
constexpr cRGB indigo = CRGB(75, 0, 130);
constexpr cRGB ivory = CRGB(255, 255, 240);
constexpr cRGB khaki = CRGB(240, 230, 140);
constexpr cRGB lavender = CRGB(230, 230, 250);
constexpr cRGB lavender_blush = CRGB(255, 240, 245);
constexpr cRGB lawn_green = CRGB(124, 252, 0);
constexpr cRGB lemon_chiffon = CRGB(255, 250, 205);
constexpr cRGB light_blue = CRGB(173, 216, 230);
constexpr cRGB light_coral = CRGB(240, 128, 128);
constexpr cRGB light_cyan = CRGB(224, 255, 255);
constexpr cRGB light_goldenrod_yellow = CRGB(250, 250, 210);
constexpr cRGB light_gray = CRGB(211, 211, 211);
constexpr cRGB light_grey = CRGB(211, 211, 211);
constexpr cRGB light_green = CRGB(144, 238, 144);
constexpr cRGB light_pink = CRGB(255, 182, 193);
constexpr cRGB light_salmon = CRGB(255, 160, 122);
constexpr cRGB light_sea_green = CRGB(32, 178, 170);
constexpr cRGB light_sky_blue = CRGB(135, 206, 250);
constexpr cRGB light_slate_gray = CRGB(119, 136, 153);
constexpr cRGB light_slate_grey = CRGB(119, 136, 153);
constexpr cRGB light_steel_blue = CRGB(176, 196, 222);
constexpr cRGB light_yellow = CRGB(255, 255, 224);
constexpr cRGB lime = CRGB(0, 255, 0);
constexpr cRGB lime_green = CRGB(50, 205, 50);
constexpr cRGB linen = CRGB(250, 240, 230);
constexpr cRGB magenta = CRGB(255, 0, 255);
constexpr cRGB maroon = CRGB(128, 0, 0);
constexpr cRGB medium_aquamarine = CRGB(102, 205, 170);
constexpr cRGB medium_blue = CRGB(0, 0, 205);
constexpr cRGB medium_orchid = CRGB(186, 85, 211);
constexpr cRGB medium_purple = CRGB(147, 112, 219);
constexpr cRGB medium_seagreen = CRGB(60, 179, 113);
constexpr cRGB medium_slate_blue = CRGB(123, 104, 238);
constexpr cRGB medium_spring_green = CRGB(0, 250, 154);
constexpr cRGB medium_turquoise = CRGB(72, 209, 204);
constexpr cRGB medium_violet_red = CRGB(199, 21, 133);
constexpr cRGB midnight_blue = CRGB(25, 25, 112);
constexpr cRGB mint_cream = CRGB(245, 255, 250);
constexpr cRGB misty_rose = CRGB(255, 228, 225);
constexpr cRGB moccasin = CRGB(255, 228, 181);
constexpr cRGB navajo_white = CRGB(255, 222, 173);
constexpr cRGB navy = CRGB(0, 0, 128);
constexpr cRGB old_lace = CRGB(253, 245, 230);
constexpr cRGB olive = CRGB(128, 128, 0);
constexpr cRGB olive_drab = CRGB(107, 142, 35);
constexpr cRGB orange = CRGB(255, 165, 0);
// The original orangered looked exactly like red to me, so I adjusted
//cRGB orangered = CRGB(255, 69, 0);
constexpr cRGB orange_red = CRGB(255, 100, 0);
constexpr cRGB orchid = CRGB(218, 112, 214);
constexpr cRGB pale_goldenrod = CRGB(238, 232, 170);
constexpr cRGB pale_green = CRGB(152, 251, 152);
constexpr cRGB pale_turquoise = CRGB(175, 238, 238);
constexpr cRGB pale_violet_red = CRGB(219, 112, 147);
constexpr cRGB papaya_whip = CRGB(255, 239, 213);
constexpr cRGB peach_puff = CRGB(255, 218, 185);
constexpr cRGB peru = CRGB(205, 133, 63);
constexpr cRGB pink = CRGB(255, 192, 203);
constexpr cRGB plum = CRGB(221, 160, 221);
constexpr cRGB powder_blue = CRGB(176, 224, 230);
constexpr cRGB purple = CRGB(128, 0, 128);
constexpr cRGB rebecca_purple = CRGB(102, 51, 153);
constexpr cRGB red = CRGB(255, 0, 0);
constexpr cRGB rosy_brown = CRGB(188, 143, 143);
constexpr cRGB royal_blue = CRGB(65, 105, 225);
constexpr cRGB saddle_brown = CRGB(139, 69, 19);
constexpr cRGB salmon = CRGB(250, 128, 114);
constexpr cRGB sandy_brown = CRGB(244, 164, 96);
constexpr cRGB sea_green = CRGB(46, 139, 87);
constexpr cRGB sea_shell = CRGB(255, 245, 238);
constexpr cRGB seashell = CRGB(255, 245, 238);
constexpr cRGB sienna = CRGB(160, 82, 45);
constexpr cRGB silver = CRGB(192, 192, 192);
constexpr cRGB sky_blue = CRGB(135, 206, 235);
constexpr cRGB slate_blue = CRGB(106, 90, 205);
constexpr cRGB slate_gray = CRGB(112, 128, 144);
constexpr cRGB slate_grey = CRGB(112, 128, 144);
constexpr cRGB snow = CRGB(255, 250, 250);
constexpr cRGB spring_green = CRGB(0, 255, 127);
constexpr cRGB steel_blue = CRGB(70, 130, 180);
constexpr cRGB tan = CRGB(210, 180, 140);
constexpr cRGB teal = CRGB(0, 128, 128);
constexpr cRGB thistle = CRGB(216, 191, 216);
constexpr cRGB tomato = CRGB(255, 99, 71);
constexpr cRGB turquoise = CRGB(64, 224, 208);
constexpr cRGB violet = CRGB(238, 130, 238);
constexpr cRGB wheat = CRGB(245, 222, 179);
constexpr cRGB white = CRGB(255, 255, 255);
constexpr cRGB white_smoke = CRGB(245, 245, 245);
constexpr cRGB yellow = CRGB(255, 255, 0);
constexpr cRGB yellow_green = CRGB(154, 205, 50);

// Alternate spellings without underscores
// Sometimes it's non-obvious if underscores belong between words
// since these names come from CSS which doesn't have word separators)
constexpr cRGB warmwhite = CRGB(255, 250, 200);
constexpr cRGB aliceblue = CRGB(240, 248, 255);
constexpr cRGB antiquewhite = CRGB(250, 235, 215);
constexpr cRGB blanchedalmond = CRGB(255, 235, 205);
constexpr cRGB blueviolet = CRGB(138, 43, 226);
constexpr cRGB cadetblue = CRGB(95, 158, 160);
constexpr cRGB cornflowerblue = CRGB(100, 149, 237);
constexpr cRGB darkblue = CRGB(0, 0, 139);
constexpr cRGB darkcyan = CRGB(0, 139, 139);
constexpr cRGB darkgoldenrod = CRGB(184, 134, 11);
constexpr cRGB darkgray = CRGB(169, 169, 169);
constexpr cRGB darkgrey = CRGB(169, 169, 169);
constexpr cRGB darkgreen = CRGB(0, 100, 0);
constexpr cRGB darkkhaki = CRGB(189, 183, 107);
constexpr cRGB darkmagenta = CRGB(139, 0, 139);
constexpr cRGB darkolivegreen = CRGB(85, 107, 47);
constexpr cRGB darkorange = CRGB(255, 140, 0);
constexpr cRGB darkorchid = CRGB(153, 50, 204);
constexpr cRGB darkred = CRGB(139, 0, 0);
constexpr cRGB darksalmon = CRGB(233, 150, 122);
constexpr cRGB darkseagreen = CRGB(143, 188, 143);
constexpr cRGB darkslateblue = CRGB(72, 61, 139);
constexpr cRGB darkslategray = CRGB(47, 79, 79);
constexpr cRGB darkslategrey = CRGB(47, 79, 79);
constexpr cRGB darkturquoise = CRGB(0, 206, 209);
constexpr cRGB darkviolet = CRGB(148, 0, 211);
constexpr cRGB deeppink = CRGB(255, 20, 147);
constexpr cRGB deepskyblue = CRGB(0, 191, 255);
constexpr cRGB dimgray = CRGB(105, 105, 105);
constexpr cRGB dimgrey = CRGB(105, 105, 105);
constexpr cRGB dodgerblue = CRGB(30, 144, 255);
constexpr cRGB firebrick = CRGB(178, 34, 34);
constexpr cRGB floralwhite = CRGB(255, 250, 240);
constexpr cRGB forestgreen = CRGB(34, 139, 34);
constexpr cRGB ghostwhite = CRGB(248, 248, 255);
constexpr cRGB greenyellow = CRGB(173, 255, 47);
constexpr cRGB hotpink = CRGB(255, 105, 180);
constexpr cRGB indianred = CRGB(205, 92, 92);
constexpr cRGB lavenderblush = CRGB(255, 240, 245);
constexpr cRGB lawngreen = CRGB(124, 252, 0);
constexpr cRGB lemonchiffon = CRGB(255, 250, 205);
constexpr cRGB lightblue = CRGB(173, 216, 230);
constexpr cRGB lightcoral = CRGB(240, 128, 128);
constexpr cRGB lightcyan = CRGB(224, 255, 255);
constexpr cRGB lightgoldenrodyellow = CRGB(250, 250, 210);
constexpr cRGB lightgray = CRGB(211, 211, 211);
constexpr cRGB lightgrey = CRGB(211, 211, 211);
constexpr cRGB lightgreen = CRGB(144, 238, 144);
constexpr cRGB lightpink = CRGB(255, 182, 193);
constexpr cRGB lightsalmon = CRGB(255, 160, 122);
constexpr cRGB lightseagreen = CRGB(32, 178, 170);
constexpr cRGB lightskyblue = CRGB(135, 206, 250);
constexpr cRGB lightslategray = CRGB(119, 136, 153);
constexpr cRGB lightslategrey = CRGB(119, 136, 153);
constexpr cRGB lightsteelblue = CRGB(176, 196, 222);
constexpr cRGB lightyellow = CRGB(255, 255, 224);
constexpr cRGB limegreen = CRGB(50, 205, 50);
constexpr cRGB mediumaquamarine = CRGB(102, 205, 170);
constexpr cRGB mediumblue = CRGB(0, 0, 205);
constexpr cRGB mediumorchid = CRGB(186, 85, 211);
constexpr cRGB mediumpurple = CRGB(147, 112, 219);
constexpr cRGB mediumseagreen = CRGB(60, 179, 113);
constexpr cRGB mediumslateblue = CRGB(123, 104, 238);
constexpr cRGB mediumspringgreen = CRGB(0, 250, 154);
constexpr cRGB mediumturquoise = CRGB(72, 209, 204);
constexpr cRGB mediumvioletred = CRGB(199, 21, 133);
constexpr cRGB midnightblue = CRGB(25, 25, 112);
constexpr cRGB mintcream = CRGB(245, 255, 250);
constexpr cRGB mistyrose = CRGB(255, 228, 225);
constexpr cRGB navajowhite = CRGB(255, 222, 173);
constexpr cRGB oldlace = CRGB(253, 245, 230);
constexpr cRGB olivedrab = CRGB(107, 142, 35);
constexpr cRGB orangered = CRGB(255, 100, 0);
constexpr cRGB palegoldenrod = CRGB(238, 232, 170);
constexpr cRGB palegreen = CRGB(152, 251, 152);
constexpr cRGB paleturquoise = CRGB(175, 238, 238);
constexpr cRGB palevioletred = CRGB(219, 112, 147);
constexpr cRGB papayawhip = CRGB(255, 239, 213);
constexpr cRGB peachpuff = CRGB(255, 218, 185);
constexpr cRGB powderblue = CRGB(176, 224, 230);
constexpr cRGB rebeccapurple = CRGB(102, 51, 153);
constexpr cRGB rosybrown = CRGB(188, 143, 143);
constexpr cRGB royalblue = CRGB(65, 105, 225);
constexpr cRGB saddlebrown = CRGB(139, 69, 19);
constexpr cRGB sandybrown = CRGB(244, 164, 96);
constexpr cRGB seagreen = CRGB(46, 139, 87);
constexpr cRGB seashell = CRGB(255, 245, 238);
constexpr cRGB skyblue = CRGB(135, 206, 235);
constexpr cRGB slateblue = CRGB(106, 90, 205);
constexpr cRGB slategray = CRGB(112, 128, 144);
constexpr cRGB slategrey = CRGB(112, 128, 144);
constexpr cRGB springgreen = CRGB(0, 255, 127);
constexpr cRGB steelblue = CRGB(70, 130, 180);
constexpr cRGB whitesmoke = CRGB(245, 245, 245);
constexpr cRGB yellowgreen = CRGB(154, 205, 50);

// Function to dim the color from 0-255 (by default) or over a specified range
// dims the specified color from 0 (off) to 255 (full)
inline constexpr float brightnessScale(byte brightness, byte range = 255) {
return float(brightness) / float(range);
}

// dimLimit prevents small adjustments from completely shutting colors off, as they are not visible below 28.
//if brightness is over about 51, and the *original* value for an rgb was over 80, set the new value to 28 if it would otherwise fall below that.
inline constexpr byte dimLimit(byte brightness, byte rgbByte, byte range = 255) {
//Uncomment this line to bypass the dimming limiting that prevents lights from blacking out at moderate values
//return brightnessScale(brightness, range) * rgbByte;
return byte(brightnessScale(brightness, range) >= 0.20 && rgbByte >= 80 && brightnessScale(brightness, range) * rgbByte < 28) ? 28 : brightnessScale(brightness, range) * rgbByte;
}

//Note that in practice, on the model01, 28 is the lowest value that actually lights up at all
__attribute__((always_inline))
inline constexpr cRGB dim(const cRGB &color, byte brightness, byte range = 255) {
return CRGB(uint8_t(dimLimit(brightness, color.r, range)),
uint8_t(dimLimit(brightness, color.g, range)),
uint8_t(dimLimit(brightness, color.b, range)));
}

inline constexpr bool isColorMatch(cRGB color1, cRGB color2) {
return (color1.r == color2.r && color1.g == color2.g && color1.b == color2.b) ? true : false;
}

} // namespace colors
} // namespace kaleidoscope
4 changes: 4 additions & 0 deletions src/kaleidoscope/plugin/LEDEffect-SolidColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class LEDSolidColor : public Plugin,
public LEDModeInterface {
public:

LEDSolidColor(cRGB color)
: r_(color.r), g_(color.g), b_(color.b)
{}

LEDSolidColor(uint8_t r, uint8_t g, uint8_t b)
: r_(r), g_(g), b_(b)
{}
Expand Down