Skip to content

Instantly share code, notes, and snippets.

@robotconscience
Created November 18, 2014 14:52
Show Gist options
  • Save robotconscience/8dc50ebb25a3fbf678fa to your computer and use it in GitHub Desktop.
Save robotconscience/8dc50ebb25a3fbf678fa to your computer and use it in GitHub Desktop.
openFrameworks SVG color sampler
#pragma once
#include "ofxSvg.h"
class SvgSampler {
public:
void load( string svgFile ){
svg.load(svgFile);
int n = svg.getNumPath();
for ( int i=0; i<n; i++){
colors.push_back( svg.getPathAt(i).getFillColor() );
}
}
int getNumColors(){
return colors.size();
}
ofColor getRandomColor(){
if ( getNumColors() > 0 ){
return colors[ floor(ofRandom(0, getNumColors()))];
} else {
static bool warned = false;
if (!warned) ofLogWarning()<<"No colors loaded";
return ofColor(255);
}
}
protected:
ofxSVG svg;
vector<ofColor> colors;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment