ofxColorTheory started as an openFrameworks addon, but the core library is generic C++ and can be used without openFrameworks.
Generates color palettes from classic color-theory rules:
- Analogous
- Complementary
- SplitComplementary
- Compound
- FlippedCompound
- Monochrome
- Tetrad
- Triad
Interpolation supports RGB, HSB, and CIELCh (ColorSpace::Rgb, ColorSpace::Hsb, ColorSpace::Lch).
The library is template-based and works with any color type T that provides the required interface.
Your color type must provide:
static float limit()- channels:
r,g,b float getHue() constfloat getHueAngle() const(degrees 0..360)float getSaturation() constfloat getBrightness() constvoid setHue(float)void setSaturation(float)void setBrightness(float)static T fromHsb(float hue, float sat, float bri)T& lerp(const T& other, float amt)
A complete reference implementation is in tests/color_theory_tests.cpp.
#include "ColorWheelSchemes.h"
int main() {
auto scheme = ofxColorTheory::ColorWheelSchemes_<MyColor>::make(ofxColorTheory::ColorRule::Triad);
scheme->setPrimaryColor(MyColor(/* ... */));
scheme->regenerate();
auto palette = scheme->interpolate(64, ofxColorTheory::ColorSpace::Lch);
}A full standalone example (custom color type + palette generation + console output) is available at:
Build and run it:
cd examples/cpp_only
make runc++ -std=c++17 -I./src your_app.cpp src/ColorUtil.cpp -o your_app#include "ColorWheelSchemes.h"
auto scheme = ofxColorTheory::ColorWheelSchemes_<ofColor>::make(ofxColorTheory::ColorRule::Triad);
scheme->setPrimaryColor(ofColor::orange);
scheme->regenerate();
std::vector<ofColor> palette = scheme->interpolate(64, ofxColorTheory::ColorSpace::Lch);- Factory returns fresh instances (
std::unique_ptr) to avoid shared mutable state. - Use
ColorWheelSchemes_<T>::make(...). ColorScheme_andColorWheelScheme_have virtual destructors and checked accessors.- Integer color-space constants remain for compatibility, but
ColorSpaceis preferred.
Standalone C++ smoke tests (no openFrameworks required):
cd tests
make run