Moved Color3, Color4, and Colors table to this project.
This commit is contained in:
38
include/Color3.hpp
Normal file
38
include/Color3.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
using u8 = uint8_t;
|
||||
|
||||
/// Represents a 3-channel color value, with Red, Green and Blue components.
|
||||
class Color3 {
|
||||
public:
|
||||
u8 r;
|
||||
u8 g;
|
||||
u8 b;
|
||||
public:
|
||||
/// Explicitly constructs a Color3 from the given Red, Green, and Blue values.
|
||||
Color3(u8 R, u8 G, u8 B);
|
||||
/// Returns a Color3 parsed from the given hexadecimal string.
|
||||
static Color3 FromHex(const std::string& hexCode);
|
||||
|
||||
Color3() = default;
|
||||
public:
|
||||
/// Returns a Color3 that is somewhere in-between this and the given Color3, determined by the alpha [0-1].
|
||||
Color3 Lerp(const Color3& rhs, float alpha) const;
|
||||
|
||||
/// Returns the red channel [0-255].
|
||||
u8 RedChannel () const;
|
||||
/// Returns the green channel [0-255].
|
||||
u8 GreenChannel() const;
|
||||
/// Returns the blue channel [0-255].
|
||||
u8 BlueChannel () const;
|
||||
/// Returns the red channel normalized from [0-255] to [0-1].
|
||||
float RedChannelNormalized () const;
|
||||
/// Returns the green channel normalized from [0-255] to [0-1].
|
||||
float GreenChannelNormalized() const;
|
||||
/// Returns the blue channel normalized from [0-255] to [0-1].
|
||||
float BlueChannelNormalized() const;
|
||||
|
||||
};
|
45
include/Color4.hpp
Normal file
45
include/Color4.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
/// Represents a 4-channel color value, with Red, Green, Blue, and Alpha components.
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <Color3.hpp>
|
||||
|
||||
|
||||
using u8 = uint8_t;
|
||||
|
||||
|
||||
class Color4 {
|
||||
public:
|
||||
u8 r;
|
||||
u8 g;
|
||||
u8 b;
|
||||
u8 a;
|
||||
public:
|
||||
Color4() = default;
|
||||
explicit Color4(const Color3& color3, u8 alpha = 255);
|
||||
Color4(u8 red, u8 green, u8 blue, u8 alpha = 255);
|
||||
static Color4 FromColor3(const Color3& color3, u8 alpha = 255);
|
||||
static Color4 FromHex(const std::string& hexCode, u8 alpha = 255);
|
||||
|
||||
public:
|
||||
u8 RedChannel() const;
|
||||
u8 GreenChannel() const;
|
||||
u8 BlueChannel() const;
|
||||
u8 AlphaChannel() const;
|
||||
|
||||
float RedChannelNormalized() const;
|
||||
float GreenChannelNormalized() const;
|
||||
float BlueChannelNormalized() const;
|
||||
float AlphaChannelNormalized() const;
|
||||
|
||||
[[nodiscard]] float RN() const { return RedChannelNormalized(); }
|
||||
[[nodiscard]] float GN() const { return GreenChannelNormalized(); }
|
||||
[[nodiscard]] float BN() const { return BlueChannelNormalized(); }
|
||||
|
||||
|
||||
int* ptr() { return reinterpret_cast<int *>(&r);}
|
||||
[[nodiscard]] const int* ptr() const { return reinterpret_cast<const int *>(&r);}
|
||||
};
|
174
include/Colors.hpp
Normal file
174
include/Colors.hpp
Normal file
@@ -0,0 +1,174 @@
|
||||
#pragma once
|
||||
|
||||
#include <Color4.hpp>
|
||||
|
||||
namespace Colors {
|
||||
namespace Primary {
|
||||
static const Color4 Red{255, 0, 0};
|
||||
static const Color4 Green{0, 255, 0};
|
||||
static const Color4 Blue{0, 0, 255};
|
||||
static const Color4 White{255, 255, 255};
|
||||
static const Color4 Black{0, 0, 0};
|
||||
static const Color4 Gray{128, 128, 128};
|
||||
static const Color4 DarkGray{192, 192, 192};
|
||||
static const Color4 LightGray{64, 64, 64};
|
||||
static const Color4 Yellow{255, 255, 0};
|
||||
}
|
||||
using namespace Primary;
|
||||
namespace Reds {
|
||||
static const Color4 Fuchsia {255, 0, 255};
|
||||
static const Color4 LightSalmon{255, 160, 122};
|
||||
static const Color4 Salmon{250, 128, 114};
|
||||
static const Color4 DarkSalmon{233, 150, 122};
|
||||
static const Color4 LightCoral{240, 128, 128};
|
||||
static const Color4 IndianRed{205, 92, 92};
|
||||
static const Color4 Crimson{220, 20, 60};
|
||||
static const Color4 Firebrick{178, 34, 34};
|
||||
static const Color4 DarkRed{139, 0, 0};
|
||||
}
|
||||
namespace Oranges {
|
||||
static const Color4 Coral{255, 127, 80};
|
||||
static const Color4 Tomato{255, 99, 71};
|
||||
static const Color4 OrangeRed{255, 69, 0};
|
||||
static const Color4 Gold{255, 215, 0};
|
||||
static const Color4 Orange{255, 165, 0};
|
||||
static const Color4 DarkOrange{255, 140, 0};
|
||||
}
|
||||
namespace Yellows {
|
||||
static const Color4 LightYellow{255, 255, 224};
|
||||
static const Color4 LemonChiffon{255, 250, 205};
|
||||
static const Color4 LightGoldenrodYellow{250, 250, 210};
|
||||
static const Color4 PapayaWhip{255, 239, 213};
|
||||
static const Color4 Moccasin{255, 228, 181};
|
||||
static const Color4 PeachPuff{255, 218, 185};
|
||||
static const Color4 PaleGoldenrod{238, 232, 170};
|
||||
static const Color4 Khaki{240, 230, 140};
|
||||
static const Color4 DarkKhaki{189, 183, 107};
|
||||
}
|
||||
namespace Greens {
|
||||
static const Color4 LawnGreen{124, 252, 0};
|
||||
static const Color4 Chartreuse{127, 255, 0};
|
||||
static const Color4 LimeGreen{50, 205, 50};
|
||||
static const Color4 ForestGreen{34, 139, 34};
|
||||
static const Color4 DarkGreen{0, 100, 0};
|
||||
static const Color4 GreenYellow{173, 255, 47};
|
||||
static const Color4 YellowGreen{154, 205, 50};
|
||||
static const Color4 SpringGreen{0, 255, 127};
|
||||
static const Color4 MediumSpringGreen{0, 250, 154};
|
||||
static const Color4 LightGreen{144, 238, 144};
|
||||
static const Color4 PaleGreen{152, 251, 152};
|
||||
static const Color4 DarkSeaGreen{143, 188, 143};
|
||||
static const Color4 MediumSeaGreen{60, 179, 113};
|
||||
static const Color4 SeaGreen{46, 139, 87};
|
||||
static const Color4 DarkOliveGreen{85, 107, 47};
|
||||
static const Color4 OliveDrab{107, 142, 35};
|
||||
static const Color4 Lime{0, 255, 0};
|
||||
static const Color4 Olive{128, 128, 0};
|
||||
}
|
||||
namespace Cyans {
|
||||
static const Color4 LightCyan{224, 255, 255};
|
||||
static const Color4 Cyan{0, 255, 255};
|
||||
static const Color4 Aqua{0, 255, 255};
|
||||
static const Color4 Aquamarine{127, 255, 212};
|
||||
static const Color4 MediumAquamarine{102, 205, 170};
|
||||
static const Color4 PaleTurquoise{175, 238, 238};
|
||||
static const Color4 Turquoise{64, 224, 208};
|
||||
static const Color4 MediumTurquoise{72, 209, 204};
|
||||
static const Color4 DarkTurquoise{0, 206, 209};
|
||||
static const Color4 LightSeaGreen{32, 178, 170};
|
||||
static const Color4 CadetBlue{95, 158, 160};
|
||||
static const Color4 DarkCyan{0, 139, 139};
|
||||
static const Color4 Teal{0, 128, 128};
|
||||
}
|
||||
namespace Blues {
|
||||
static const Color4 PowderBlue{176, 224, 230};
|
||||
static const Color4 LightBlue{173, 216, 230};
|
||||
static const Color4 LightSkyBlue{135, 206, 250};
|
||||
static const Color4 SkyBlue{135, 206, 235};
|
||||
static const Color4 DeepSkyBlue{0, 191, 255};
|
||||
static const Color4 LightSteelBlue{176, 196, 222};
|
||||
static const Color4 DodgerBlue{30, 144, 255};
|
||||
static const Color4 CornflowerBlue{100, 149, 237};
|
||||
static const Color4 SteelBlue{70, 130, 180};
|
||||
static const Color4 RoyalBlue{65, 105, 225};
|
||||
static const Color4 MediumBlue{0, 0, 205};
|
||||
static const Color4 DarkBlue{0, 0, 139};
|
||||
static const Color4 Navy{0, 0, 128};
|
||||
static const Color4 MidnightBlue{25, 25, 112};
|
||||
static const Color4 MediumSlateBlue{123, 104, 238};
|
||||
static const Color4 SlateBlue{106, 90, 205};
|
||||
static const Color4 DarkSlateBlue{72, 61, 139};
|
||||
}
|
||||
|
||||
|
||||
namespace Purples {
|
||||
static const Color4 Lavender{230, 230, 250};
|
||||
static const Color4 Thistle{216, 191, 216};
|
||||
static const Color4 Plum{221, 160, 221};
|
||||
static const Color4 Violet{238, 160, 221};
|
||||
static const Color4 Orchid{218, 112, 214};
|
||||
static const Color4 Fuchsia{255, 0, 255};
|
||||
static const Color4 Magenta{255, 0, 255};
|
||||
static const Color4 MediumOrchid{186, 85, 211};
|
||||
static const Color4 MediumPurple{147, 112, 219};
|
||||
static const Color4 BlueViolet{138, 43, 226};
|
||||
static const Color4 DarkViolet{148, 0, 211};
|
||||
static const Color4 DarkOrchid{153, 50, 204};
|
||||
static const Color4 DarkMagenta{139, 0, 128};
|
||||
static const Color4 Purple{128, 0, 128};
|
||||
static const Color4 Indigo{75, 0, 130};
|
||||
}
|
||||
namespace Pinks {
|
||||
static const Color4 Pink{255, 129, 203};
|
||||
static const Color4 LightPink{255, 182, 193};
|
||||
static const Color4 HotPink{255, 105, 180};
|
||||
static const Color4 DeepPink{255, 20, 147};
|
||||
static const Color4 PaleVioletRed{219, 112, 147};
|
||||
static const Color4 MediumVioletRed{199, 21, 133};
|
||||
}
|
||||
namespace Whites {
|
||||
static const Color4 Snow{255, 250, 250};
|
||||
static const Color4 Honeydew{240, 255, 240};
|
||||
static const Color4 MintCream{245, 255, 250};
|
||||
static const Color4 Azure{240, 255, 255};
|
||||
static const Color4 AliceBlue{240, 248, 255};
|
||||
static const Color4 GhostWhite{248, 248, 255};
|
||||
static const Color4 WhiteSmoke{245, 245, 245};
|
||||
static const Color4 SeaShell{255, 245, 238};
|
||||
static const Color4 Beige{245, 245, 220};
|
||||
static const Color4 OldLace{253, 245, 230};
|
||||
static const Color4 FloralWhite{255, 250, 240};
|
||||
static const Color4 Ivory{255, 255, 240};
|
||||
static const Color4 AntiqueWhite{250, 240, 215};
|
||||
static const Color4 Linen{250, 240, 230};
|
||||
static const Color4 LavenderBlush{255, 240, 245};
|
||||
static const Color4 MistyRose{255, 228, 255};
|
||||
}
|
||||
namespace Grays {
|
||||
static const Color4 Gainsboro{220, 220, 220};
|
||||
static const Color4 LightGray{211, 211, 211};
|
||||
static const Color4 Silver{192, 192, 192};
|
||||
static const Color4 DimGray{105, 105, 105};
|
||||
static const Color4 LightSlateGray{119, 136, 153};
|
||||
static const Color4 SlateGray{112, 128, 144};
|
||||
static const Color4 DarkSlateGray{47, 79, 79};
|
||||
}
|
||||
namespace Browns {
|
||||
static const Color4 CornSilk{255, 248, 220};
|
||||
static const Color4 BlanchedAlmond{255, 235, 205};
|
||||
static const Color4 Bisque{255, 228, 196};
|
||||
static const Color4 NavajoWhite{255, 222, 173};
|
||||
static const Color4 Wheat{254, 222, 179};
|
||||
static const Color4 BurlyWood{222, 184, 135};
|
||||
static const Color4 Tan{210, 180, 140};
|
||||
static const Color4 RosyBrown{188, 143, 143};
|
||||
static const Color4 SandyBrown{244, 164, 96};
|
||||
static const Color4 GoldenRod{218, 165, 32};
|
||||
static const Color4 Peru{205, 133, 63};
|
||||
static const Color4 Chocolate{210, 105, 30};
|
||||
static const Color4 SaddleBrown{139, 69, 19};
|
||||
static const Color4 Sienna{160, 82, 45};
|
||||
static const Color4 Brown{164, 42, 42};
|
||||
static const Color4 Maroon{128, 0, 0};
|
||||
}
|
||||
}
|
21
src/Color3.cpp
Normal file
21
src/Color3.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <Color3.hpp>
|
||||
|
||||
u8 Color3::RedChannel() const { return r; }
|
||||
|
||||
u8 Color3::GreenChannel() const { return g; }
|
||||
|
||||
u8 Color3::BlueChannel() const { return b; }
|
||||
|
||||
float Color3::RedChannelNormalized() const { return static_cast<float>(r) / 255.f;}
|
||||
|
||||
float Color3::BlueChannelNormalized() const { return static_cast<float>(b) / 255.f;}
|
||||
|
||||
float Color3::GreenChannelNormalized() const { return static_cast<float>(g) / 255.f;}
|
||||
|
||||
Color3::Color3(u8 R, u8 G, u8 B) : r(R), g(G), b(B) {}
|
||||
|
||||
Color3 Color3::FromHex(const std::string &hexCode) {
|
||||
u8 r, g, b;
|
||||
std::sscanf(hexCode.c_str(), "#%02x%02x%02x", &r, &g, &b);
|
||||
return {r, g, b};
|
||||
}
|
28
src/Color4.cpp
Normal file
28
src/Color4.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <Color4.hpp>
|
||||
|
||||
Color4::Color4(u8 red, u8 green, u8 blue, u8 alpha) : r(red), g(green), b(blue), a(alpha) {}
|
||||
|
||||
Color4::Color4(const Color3 &color3, u8 alpha) {r = color3.r; g = color3.g; b = color3.b; a = alpha;}
|
||||
|
||||
Color4 Color4::FromColor3(const Color3 &color3, u8 alpha) {return Color4(color3, alpha);}
|
||||
|
||||
u8 Color4::RedChannel() const { return r;}
|
||||
|
||||
u8 Color4::GreenChannel() const { return g;}
|
||||
|
||||
u8 Color4::BlueChannel() const {return b;}
|
||||
|
||||
u8 Color4::AlphaChannel() const {return a;}
|
||||
|
||||
float Color4::RedChannelNormalized() const {return static_cast<float>(r/255.f); }
|
||||
|
||||
float Color4::GreenChannelNormalized() const {return static_cast<float>(g/255.f); }
|
||||
|
||||
float Color4::BlueChannelNormalized() const {return static_cast<float>(b/255.f); }
|
||||
|
||||
float Color4::AlphaChannelNormalized() const {return static_cast<float>(a/255.f); }
|
||||
Color4 Color4::FromHex(const std::string &hexCode, u8 alpha) {
|
||||
u8 r, g, b;
|
||||
std::sscanf(hexCode.c_str(), "#%02x%02x%02x", &r, &g, &b);
|
||||
return {r, g, b, alpha};
|
||||
}
|
Reference in New Issue
Block a user