Created
August 5, 2014 05:55
-
-
Save riebschlager/721c86ab8b498dd7b17f to your computer and use it in GitHub Desktop.
Noise-based Bitmap Collage
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(){ | |
numberOfSlices = 11; | |
source.loadImage("source.jpg"); | |
source.resize(1920 * 2, 1080 * 2); | |
canvas.allocate(1920 * 2, 1080 * 2, GL_RGBA); | |
canvas.begin(); | |
ofClear(0); | |
canvas.end(); | |
ofSeedRandom(); | |
for (int i = 0; i < numberOfSlices; i++) { | |
ofImage img; | |
img.loadImage("slices/slice-" + ofToString(i) + ".png"); | |
slices.push_back(img); | |
} | |
float noiseScale = 0.00085; | |
float t = ofRandom(100); | |
for (int x = 0; x < canvas.getWidth(); x++){ | |
for (int y = 0; y < canvas.getHeight(); y++) { | |
data[x][y] = ofNoise(x * noiseScale, y * noiseScale); | |
} | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
for(int i = 0; i < 1000; i++) { | |
randomPoint.x = ofRandom(canvas.getWidth()); | |
randomPoint.y = ofRandom(canvas.getHeight()); | |
int randX = floor(randomPoint.x); | |
int randY = floor(randomPoint.y); | |
float noise = data[randX][randY]; | |
ofColor c = source.getColor(floor(randomPoint.x), floor(randomPoint.y)); | |
canvas.begin(); | |
ofPushMatrix(); | |
float scale = ofMap(noise, 0, 1, 0.15, 1.5); | |
ofImage img = slices[floor(ofRandom(slices.size()))]; | |
ofTranslate(randomPoint.x - img.width / 2, randomPoint.y - img.height/2); | |
ofScale(scale, scale); | |
ofSetColor(c,ofMap(noise,0,1,0,200)); | |
ofRotate(ofMap(noise,0,1,-20,20)); | |
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA); | |
img.draw(0,0); | |
ofPopMatrix(); | |
canvas.end(); | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofEnableBlendMode(OF_BLENDMODE_ALPHA); | |
ofBackground(255, 255, 255); | |
ofSetColor(255, 255, 255); | |
canvas.draw(0,0,ofGetWidth(), ofGetHeight()); | |
} | |
void ofApp::saveFbo(){ | |
ofFbo img; | |
ofPixels pixels; | |
img.allocate(1920 * 2, 1080 * 2, GL_RGBA); | |
img.begin(); | |
ofClear(0); | |
canvas.draw(0, 0); | |
img.end(); | |
img.readToPixels(pixels); | |
ofSaveImage(pixels, "image"+ofToString(floor(ofRandom(10000)))+".tif"); | |
} | |
//-------------------------------------------------------------- | |
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