void ofApp::setupAnim() {
shapeSystem.setup();
shape1.setupGradientSquare(halfWidth*0.15, halfWidth*0.85);
shape2.setupGradientSquare(halfWidth*0.15, halfWidth*0.85);
shape3.setupGradientSquare(halfWidth*0.15, halfWidth*0.85);
shape4.setupGradientSquare(halfWidth*0.15, halfWidth*0.85);
shape1.setPosition(halfWidth*0.5, halfHeight*0.5);
shapeSystem.add(shape1);
shape2.setPosition(halfWidth*0.5+halfWidth, halfHeight*0.5);
shapeSystem.add(shape2);
shape3.setPosition(halfWidth*0.5, halfHeight*0.5+halfHeight);
shapeSystem.add(shape3);
shape4.setPosition(halfWidth*0.5+halfHeight, halfHeight*0.5+halfHeight);
shapeSystem.add(shape4);
masker.setup(width, height);
layer1 = masker.newLayer();
layer2 = masker.newLayer();
ofDisableArbTex();
offset = ofRandom(3);
setupImage("foil.png", &img1, &tex1);
setupImage("glass.png", &img2, &tex2);
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(layer1);
if(ofRandom(1) > 0.4) ofBackground(ofColor::black);
ofSetColor(ofColor::white);
tx0 = -ofGetFrameNum() * 0.00006 + offset + ofRandom(-0.09, 0.09);
ty0 = ofGetFrameNum() * 0.005;
tx1 = tx0 - 1;
ty1 = ty0 - 0.25;
drawLayer(&tex1);
masker.endLayer(layer1);
masker.beginMask(layer1);
ofBackground(ofColor::black);
if(ofGetFrameNum() == 0 || ofRandom(1) > 0.2) {
ofSetColor(ofColor::white, 32);
for(int i = 0; i < 30; i++) {
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.15) {
offset = ofRandom(3);
}
masker.endMask(layer1);
masker.beginMask(layer2);
if(ofRandom(1) > 0.4) ofBackground(ofColor::black);
ofSetColor(ofColor::white);
tx0 = ofGetFrameNum() * 0.00006 + offset;
tx1 = tx0 - 1;
ofTranslate(-halfWidth, -halfHeight, 0);
drawLayer(&tex1);
masker.drawLayer(layer1);
ofTranslate(width, 0, 0);
drawLayer(&tex1);
masker.drawLayer(layer1);
ofTranslate(0, height, 0);
drawLayer(&tex1);
masker.drawLayer(layer1);
ofTranslate(-width, 0, 0);
drawLayer(&tex1);
masker.drawLayer(layer1);
ofTranslate(halfWidth, -halfHeight, 0);
shapeSystem.draw();
masker.endMask(layer2);
masker.beginLayer(layer2);
ofSetColor(ofColor::white, 32);
tx0 = ofGetFrameNum() * 0.005;
ty0 = -ofGetFrameNum() * 0.00006 + offset + ofRandom(-0.09, 0.09);
tx1 = tx0 - 0.25;
ty1 = ty0 - 1;
drawLayer(&tex2);
masker.endLayer(layer2);
}
void ofApp::drawAnim() {
ofBackground(ofColor::black);
masker.draw();
if(ofGetFrameNum() == 72) {
renderGif();
}
}