Created
November 18, 2014 14:52
-
-
Save robotconscience/8dc50ebb25a3fbf678fa to your computer and use it in GitHub Desktop.
openFrameworks SVG color sampler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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