Skip to content

Latest commit

 

History

34 Commits

Folders and files

Repository files navigation

ofxColorTheory

ofxColorTheory started as an openFrameworks addon, but the core library is generic C++ and can be used without openFrameworks.

What It Does

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).

Use With Plain C++ (No openFrameworks)

The library is template-based and works with any color type T that provides the required interface.

Required Interface For T

Your color type must provide:

  • static float limit()
  • channels: r, g, b
  • float getHue() const
  • float getHueAngle() const (degrees 0..360)
  • float getSaturation() const
  • float getBrightness() const
  • void 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.

Minimal Usage

#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);
}

C++-Only Example In This Repo

A full standalone example (custom color type + palette generation + console output) is available at:

examples/cpp_only/main.cpp

Build and run it:

cd examples/cpp_only
make run

Build (Plain C++)

c++ -std=c++17 -I./src your_app.cpp src/ColorUtil.cpp -o your_app

Use With openFrameworks

#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);

API Notes

  • Factory returns fresh instances (std::unique_ptr) to avoid shared mutable state.
  • Use ColorWheelSchemes_<T>::make(...).
  • ColorScheme_ and ColorWheelScheme_ have virtual destructors and checked accessors.
  • Integer color-space constants remain for compatibility, but ColorSpace is preferred.

Tests

Standalone C++ smoke tests (no openFrameworks required):

cd tests
make run

About

Color-theory palette generation and interpolation in C++ (with or without openFrameworks).

Topics

Resources

Stars

18 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages