Sketch 2015-05-17
void ofApp::setupAnim() {
ofEnableSmoothing();
masker.setup(width, height);
fadeIn = true;
fadeOut = false;
alpha = 255;
ofDisableArbTex();
setupImage("tissue-inverted.png", &img1, &tex1, &offset1);
setupImage("road.png", &img2, &tex2, &offset2);
plane.set(width, height);
plane.setPosition(width * 0.5, height * 0.5, 0);
plane.setResolution(2, 2);
}
void ofApp::updateAnim(){
masker.beginBackground();
ofBackground(0, 0, 0, 255);
masker.endBackground();
masker.beginMask();
ofEnableAlphaBlending();
ofBackground(0, 0, 0, 255);
ofSetColor(ofColor::white);
ofTranslate(0, 0, 250);
ofBackground(255, 255, 255);
for(int i = 0; i < 360; i+= 1) {
rotateScreen(i);
drawLayer(&tex1);
}
ofDisableAlphaBlending();
masker.endMask();
masker.beginForeground();
ofBackground(0, 0, 0, 255);
ofSetColor(ofColor(62, 225, 255));
tx0 = -ofGetFrameNum() * 0.030 + offset2;
ty0 = -ofGetFrameNum() * 0.030 + offset2;
tx1 = tx0 + (ofGetFrameNum() * 0.030 + offset2) * 2;
ty1 = ty0 + (ofGetFrameNum() * 0.030 + offset2) * 2;
drawLayer(&tex2);
masker.endForeground();
}
void ofApp::drawAnim() {
ofBackground(0, 0, 0);
ofSetColor(ofColor::white);
ofEnableAlphaBlending();
masker.draw();
if(fadeIn) {
alpha -= 24;
if(alpha <= 0) fadeIn = false;
}
if(fadeOut) {
alpha += 24;
if(alpha >= 300) renderGif();
}
ofSetColor(0, 0, 0, alpha);
ofRect(0, 0, width, height);
if(ofGetFrameNum() == 60) {
fadeOut = true;
}
ofDisableAlphaBlending();
}
void ofApp::drawLayer(ofTexture *tex) {
tx0 = -0.35;
ty0 = ofGetFrameNum() * 0.0128 + offset1;
tx1 = tx0 + 3;
ty1 = ty0 + 1.5;
plane.mapTexCoords(tx0, ty0, tx1, ty1);
plane.mapTexCoords(tx1, ty1, tx0, ty0);
tex->bind();
plane.draw();
tex->unbind();
}
void ofApp::setupImage(string file, ofImage *img, ofTexture *tex, float *offset) {
img->loadImage(file);
*tex = img->getTextureReference();
tex->setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
*offset = ofRandom(1);
}
void ofApp::rotateScreen(float degrees) {
ofTranslate(halfWidth, halfHeight, 0);
ofRotate(degrees);
ofTranslate(-halfWidth, -halfHeight, 0);
}
Sometimes, you just end up with... something.