Sketch 2015-05-19
void ofApp::setupAnim() {
ofEnableSmoothing();
ofSetLineWidth(4);
masker.setup(width, height);
img1.loadImage("newyork.png");
img2.loadImage("flight.png");
for(int i = 0; i < 40; i++) {
ofxAnimatableFloat animHeight;
animHeight.reset(ofRandom(90));
heights.push_back(animHeight);
ofxAnimatableFloat opacity;
opacity.reset(ofMap(i, 0, 300, 120, 255));
opacities.push_back(opacity);
ofxAnimatableFloat target;
target.reset(ceil(ofRandom(-height, height * 2)));
targets.push_back(target);
ofxAnimatableFloat position;
position.reset(createDistinct(target.val()));
position.setCurve(SWIFT_GOOGLE);
position.setRepeatType(LOOP_BACK_AND_FORTH);
position.setDuration(ceil(ofRandom(4)) * 0.5);
position.animateTo(targets.at(i).val());
positions.push_back(position);
}
}
float ofApp::createDistinct(float from) {
float candidate;
do candidate = ceil(ofRandom(-height, height * 2));
while(abs(candidate - from) < 150);
return candidate;
}
void ofApp::updateAnim(){
ofEnableAlphaBlending();
masker.beginBackground();
img1.draw(0, 0);
ofSetColor(ofColor(ofColor::black, 40));
ofRect(0, 0, width, height);
masker.endBackground();
masker.beginMask();
ofBackground(ofColor::black);
for(int i = 0; i < positions.size(); i++) {
positions.at(i).update(0.05);
ofSetColor(ofColor::white, opacities.at(i).val());
ofRect(0, positions.at(i).val(), width, heights.at(i).val());
}
masker.endMask();
masker.beginForeground();
img2.draw(0, 0);
ofSetColor(ofColor(ofColor::black, 40));
ofRect(0, 0, width, height);
masker.endForeground();
ofDisableAlphaBlending();
}
void ofApp::drawAnim() {
masker.draw();
bool allFinished = true;
for(int i = 0; i < positions.size(); i++) {
if(positions.at(i).getPlayCount() < 1) {
allFinished = false;
}
}
if(allFinished) renderGif();
}
Leaving NYC for Miami. Plane delayed.