vector<ofColor> ofxColourTheory::createRangeFromAnalogous(ofColor src){ vector<ofVec2f> tones; tones.push_back(ofVec2f(1, 2.2f)); tones.push_back(ofVec2f(2, 1)); tones.push_back(ofVec2f(-1, -0.5f)); tones.push_back(ofVec2f(-2, 1)); float contrast = 0.25f; float theta = 10 *PI / 180.0; contrast = clipNormalized(contrast); vector<ofColor> colList; colList.push_back(src); for (int i=0;i<tones.size();i++) { ofColor c = rotateRYB(src,(int) (theta * tones[i].x)); float t = 0.44f - tones[i].y * 0.1f; if ((float) src.getBrightness()/255.0 - contrast * tones[i].y < t) { c.setBrightness(t*255.0); } else { c.setBrightness(src.getBrightness() - (contrast * tones[i].y)*255.0); } c.setSaturation(c.getSaturation()-0.05f*255.0); colList.push_back(c); } return colList; }
float distanceBetween(ofColor a,ofColor b) { float hue = a.getHue()/255.0f *TWO_PI; float hue2 = b.getHue()/255.0f * TWO_PI; ofVec3f v1((cos(hue) * a.getSaturation()/255.0f), (sin(hue) * a.getSaturation()/255.0f), a.getBrightness()/255.0f); ofVec3f v2((cos(hue2) * b.getSaturation()/255.0f), (sin(hue2) * b.getSaturation()/255.0f), b.getBrightness()/255.0f); return v1.distance(v2); }
ofColor rotateRYB(ofColor col,int theta) { float h = (float) col.getHue()/255.0 * 360; vector<float> hsb; hsb.push_back((float) col.getHue()/255.0) ; hsb.push_back((float) col.getSaturation()/255.0) ; hsb.push_back((float) col.getBrightness()/255.0) ; theta %= 360; float resultHue = 0; vector<ofVec2f> RYB_WHEEL = getRYB_WHEEL(); for (int i = 0; i < RYB_WHEEL.size() - 1; i++) { ofVec2f p = RYB_WHEEL[i]; ofVec2f q = RYB_WHEEL[i + 1]; if (q.y < p.y) { q.y += 360; } if (p.y <= h && h <= q.y) { resultHue = p.x + (q.x - p.x) * (h - p.y) / (q.y - p.y); break; } } //fmod = %, ie remainder // And the user-given angle (e.g. complement). resultHue = fmod((resultHue + theta),360); // For the given angle, find out what hue is // located there on the artistic color wheel. for (int i = 0; i < RYB_WHEEL.size() - 1; i++) { ofVec2f p = RYB_WHEEL[i]; ofVec2f q = RYB_WHEEL[i + 1]; if (q.y < p.y) { q.y += 360; } if (p.x <= resultHue && resultHue <= q.x) { h = p.y + (q.y - p.y) * (resultHue - p.x) / (q.x - p.x); break; } } hsb[0] = fmod(h, 360) / 360.0f; ofColor newCol; newCol.setHsb(hsb[0]*255, hsb[1]*255, hsb[2]*255); return newCol; }
void testApp::drawCube(float x_,float y_,float z_,ofColor top_, ofColor bottom_, ofColor front_, ofColor back_, ofColor left_, ofColor right_){ float x = x_/2; float y = y_/2; float z = z_/2; glBegin(GL_QUADS); pSetHSV(top_.getHue(),top_.getSaturation(),top_.getBrightness()); glColor3f(cols[0],cols[1],cols[2]); glVertex3f( x, y,-z); // Top Right Of The Quad (Top) glVertex3f(-x, y,-z); // Top Left Of The Quad (Top) glVertex3f(-x, y, z); // Bottom Left Of The Quad (Top) glVertex3f( x, y, z); // Bottom Right Of The Quad (Top) pSetHSV(bottom_.getHue(),bottom_.getSaturation(),bottom_.getBrightness()); glColor3f(cols[0],cols[1],cols[2]); glVertex3f( x,-y, z); // Top Right Of The Quad (Bottom) glVertex3f(-x,-y, z); // Top Left Of The Quad (Bottom) glVertex3f(-x,-y,-z); // Bottom Left Of The Quad (Bottom) glVertex3f( x,-y,-z); // Bottom Right Of The Quad (Bottom) pSetHSV(front_.getHue(),front_.getSaturation(),front_.getBrightness()); glColor3f(cols[0],cols[1],cols[2]); glVertex3f( x, y, z); // Top Right Of The Quad (Front) glVertex3f(-x, y, z); // Top Left Of The Quad (Front) pSetHSV(60,100,100); glColor3f(cols[0],cols[1],cols[2]); glVertex3f(-x,-y, z); // Bottom Left Of The Quad (Front) glVertex3f( x,-y, z); // Bottom Right Of The Quad (Front) pSetHSV(back_.getHue(),back_.getSaturation(),back_.getBrightness()); glColor3f(cols[0],cols[1],cols[2]); glVertex3f( x,-y,-z); // Bottom Left Of The Quad (Back) glVertex3f(-x,-y,-z); // Bottom Right Of The Quad (Back) glVertex3f(-x, y,-z); // Top Right Of The Quad (Back) glVertex3f( x, y,-z); // Top Left Of The Quad (Back) pSetHSV(left_.getHue(),left_.getSaturation(),left_.getBrightness()); glColor3f(cols[0],cols[1],cols[2]); glVertex3f(-x, y, z); // Top Right Of The Quad (Left) glVertex3f(-x, y,-z); // Top Left Of The Quad (Left) glVertex3f(-x,-y,-z); // Bottom Left Of The Quad (Left) glVertex3f(-x,-y, z); // Bottom Right Of The Quad (Left) pSetHSV(right_.getHue(),right_.getSaturation(),right_.getBrightness()); glColor3f(cols[0],cols[1],cols[2]); glVertex3f( x, y,-z); // Top Right Of The Quad (Right) glVertex3f( x, y, z); // Top Left Of The Quad (Right) glVertex3f( x,-y, z); // Bottom Left Of The Quad (Right) glVertex3f( x,-y,-z); // Bottom Right Of The Quad (Right) glEnd(); // Done Drawing The Quad }
void ofPixels::setColor(int x, int y, ofColor color) { int index = getPixelIndex(x, y); if( bytesPerPixel == 1 ){ pixels[index] = color.getBrightness(); }else if( bytesPerPixel == 3 ){ pixels[index] = color.r; pixels[index+1] = color.g; pixels[index+2] = color.b; }else if( bytesPerPixel == 4 ){ pixels[index] = color.r; pixels[index+1] = color.g; pixels[index+2] = color.b; pixels[index+3] = color.a; } }
//-------------------------------------------------------------- // sort by brightness function bool sortBrightness( ofColor a, ofColor b){ return( a.getBrightness() < b.getBrightness() ); }
//-------------------------------------------------------------- //Sort function for stl::sort http://www.cplusplus.com/reference/algorithm/sort/ bool sortColorFunction (ofColor i,ofColor j) { return (i.getBrightness()<j.getBrightness()); }