Created
December 31, 2014 21:16
-
-
Save riebschlager/14370c41f1035257f606 to your computer and use it in GitHub Desktop.
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
#include "ofApp.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
randomSeed = ofRandom(100000); | |
for(int i = 0; i < COLOR_SOURCES; i++) { | |
ofImage img; | |
img.loadImage("color-source/color-source-" + ofToString(i) + ".jpg"); | |
img.resize(CANVAS_WIDTH, CANVAS_HEIGHT); | |
colorSources.push_back(img); | |
} | |
for(int i = 0; i < SHAPE_SOURCES; i++) { | |
ofImage img; | |
img.loadImage("shape-source/shape-source-" + ofToString(i) + ".png"); | |
img.resize(CANVAS_WIDTH, CANVAS_HEIGHT); | |
shapeSources.push_back(img); | |
} | |
for(int i = 0; i < NUMBER_OF_SCRAPS; i++) { | |
ofImage img; | |
img.loadImage("scraps/scrap-" + ofToString(i) + ".png"); | |
scraps.push_back(img); | |
} | |
// for (int i = 0; i < SHAPE_SOURCES; i++) { | |
// shapePoints.push_back(vector<ofPoint>()); | |
// for(int x = 0; x < shapeSources[i].width; x++) { | |
// for(int y = 0; y < shapeSources[i].height; y++){ | |
// if(shapeSources[i].getColor(x, y) == ofColor(255,255,255) ){ | |
// shapePoints[i].push_back(ofPoint(x,y)); | |
// } | |
// } | |
// } | |
// } | |
for (int i = 0; i < SHAPE_SOURCES; i++) { | |
shapePoints.push_back(vector<ofPoint>()); | |
for(int x = 0; x < shapeSources[i].width; x+= 1) { | |
for(int y = 0; y < shapeSources[i].height; y+= 100){ | |
//if(shapeSources[i].getColor(x, y) == ofColor(255,255,255) ){ | |
shapePoints[i].push_back(ofPoint(x,y)); | |
//} | |
} | |
} | |
} | |
canvas.allocate(CANVAS_WIDTH, CANVAS_HEIGHT, GL_RGBA); | |
canvas.begin(); | |
ofBackground(0, 0, 255); | |
ofPoint r1, r2; | |
r1.x = floor(ofRandom(colorSources[0].width)); | |
r1.y = floor(ofRandom(colorSources[0].height)); | |
r2.x = floor(ofRandom(colorSources[0].width)); | |
r2.y = floor(ofRandom(colorSources[0].height)); | |
ofColor colorOne = colorSources[0].getColor(r1.x, r1.y); | |
ofColor colorTwo = colorSources[0].getColor(r2.x, r2.y); | |
ofBackground(colorOne); | |
canvas.end(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::render(int index){ | |
//randomPoint.x = ofRandom(0, CANVAS_WIDTH); | |
//randomPoint.y = ofRandom(0, CANVAS_HEIGHT); | |
randomPoint = shapePoints[index][floor(ofRandom(shapePoints[index].size()))]; | |
//randomPoint = shapePoints[0][0]; | |
float frame = ofGetFrameNum() + randomSeed; | |
float noise = ofNoise(randomPoint.x * NOISE_SCALE, randomPoint.y * NOISE_SCALE, frame * NOISE_SCALE); | |
//ofColor color = colorSources[index].getColor(randomPoint.x, randomPoint.y); | |
ofColor color = colorSources[index].getColor(ofRandom(colorSources[index].width), ofRandom(colorSources[index].height)); | |
//int scrapIndex = floor(ofRandom(NUMBER_OF_SCRAPS)); | |
//int scrapIndex = floor(ofMap(noise,0,1,0,NUMBER_OF_SCRAPS)); | |
int scrapIndex = index; | |
float scale = ofMap(noise,0,1,SCALE_MIN,SCALE_MAX); | |
canvas.begin(); | |
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | |
//glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
ofSetColor(color, ofRandom(ALPHA_MIN, ALPHA_MAX)); | |
ofPushMatrix(); | |
float scaledX = randomPoint.x - (scraps[scrapIndex].width / 2) * scale; | |
float scaledY = randomPoint.y - (scraps[scrapIndex].height / 2) * scale; | |
//ofTranslate(scaledX, scaledY); | |
ofTranslate(randomPoint.x, randomPoint.y); | |
ofScale(scale, scale); | |
ofRotate(ofMap(noise,0,1,ROTATION_MIN, ROTATION_MAX)); | |
scraps[scrapIndex].draw(0,0); | |
//float r = ofRandom(200); | |
//ofSetColor(color, ofRandom(100)); | |
//ofEllipse(0, 0, r, r); | |
//ofFill(); | |
//ofRect(0,0,5,300); | |
//ofNoFill(); | |
//ofSetColor(color, 50); | |
//ofRect(0,0,15,400); | |
ofPopMatrix(); | |
canvas.end(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::saveFbo(){ | |
ofFbo img; | |
ofPixels pixels; | |
img.allocate(CANVAS_WIDTH, CANVAS_HEIGHT, GL_RGBA); | |
img.begin(); | |
ofBackground(255, 255, 255); | |
canvas.draw(0,0); | |
img.end(); | |
img.readToPixels(pixels); | |
ofSaveImage(pixels, "output/image-" + ofToString(ofGetUnixTime()) + ".tif"); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
for(int i = 0; i < 100; i++) { | |
for(int index = 0; index < SHAPE_SOURCES; index++){ | |
render(index); | |
} | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofBackground(255, 255, 255); | |
ofSetColor(255, 255, 255); | |
canvas.draw(0,0, ofGetWidth(), ofGetHeight()); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
if(key == 's') { | |
saveFbo(); | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment