Sketch 2015-06-04
//Pattern based on http://www.openprocessing.org/sketch/157035
ofxLayerMask masker;
int layerId;
float tx0, ty0, tx1, ty1;
float offset;
ofImage img;
ofTexture tex;
ofPlanePrimitive plane;
float x, y, radians;
void ofApp::setupAnim() {
masker.setup(width, height);
layerId = masker.newLayer();
ofDisableArbTex();
offset = ofRandom(3);
setupImage("face.png", &img, &tex);
plane.set(width, height);
plane.setPosition(halfWidth, halfHeight, 0);
plane.setResolution(2, 2);
}
void ofApp::setupImage(string file, ofImage *img, ofTexture *tex) {
img->loadImage(file);
*tex = img->getTextureReference();
tex->setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
}
void ofApp::drawLayer(ofTexture *tex) {
plane.mapTexCoords(tx0, ty0, tx1, ty1);
plane.mapTexCoords(tx1, ty1, tx0, ty0);
tex->bind();
plane.draw();
tex->unbind();
}
void ofApp::updateAnim(){
masker.beginLayer(layerId);
ofBackground(ofColor::black);
ofSetColor(ofColor::white);
tx0 = 1;
ty0 = ofGetFrameNum() * 0.0012 + offset;
tx1 = tx0 - 1;
ty1 = ty0 - 0.2;
drawLayer(&tex);
masker.endLayer(layerId);
masker.beginMask(layerId);
ofBackground(ofColor::black);
if(ofGetFrameNum() == 0 || ofRandom(1) > 0.6) {
ofTriangle(ofRandom(-width, width*2), ofRandom(-height, height*2),
ofRandom(-width, width*2), ofRandom(-height, height*2),
ofRandom(-width, width*2), ofRandom(-height, height*2));
} else if(ofRandom(1) > 0.3) {
offset = ofRandom(3);
}
masker.endMask(layerId);
}
void ofApp::drawAnim() {
if(ofGetFrameNum() == 0) ofBackground(ofColor::black);
ofSetColor(ofColor::white, 40);
drawLayer(&tex);
ofSetColor(ofColor::white, 15);
ofTranslate(halfWidth, halfHeight);
for (int i = 0; i < 360; i+=6) {
for (int q = 0; q < 360; q+=360) {
radians = ofDegToRad(q + i + ofGetFrameNum() * 5);
x = ofMap(sin(radians) * i, -600, -10, i, 0);
y = ofMap(cos(radians) * i, -600, -10, 0, i);
ofCircle(x, y, 2);
ofCircle(y, x, 2);
ofCircle(-x, -y, 2);
ofCircle(-y, -x, 2);
x = ofMap(sin(radians) * i, -600, -10, -i, 0);
ofCircle(x, y, 2);
ofCircle(y, x, 2);
ofCircle(-x, -y, 2);
ofCircle(-y, -x, 2);
}
}
ofTranslate(-halfWidth, -halfHeight);
masker.draw();
if(ofGetFrameNum() == 72) {
renderGif();
}
}
Frustration can be bitter sweet