Sketch 2015-05-12
void ofApp::setupAnim() {
maskOpacity = 255;
for(int i = 0; i < 50; i++) {
position.x = ofRandom(-width, width*2);
position.y = ofRandom(-height, height*2);
position.z = ofRandom(-400, 0);
size = ofRandom(20, 380);
thickness = size * 0.18;
ofxShape square;
square.setupHollowSquare(thickness, size);
square.setPosition(position);
square.setBlur(2);
shapes.push_back(square);
ofxShape ring;
ring.setupHollowRing(60, thickness, size);
ring.setPosition(position);
ring.rotateY(90);
ring.setBlur(2);
shapes.push_back(ring);
}
for(int i = 0; i < shapes.size(); i++) {
system.add(shapes.at(i));
}
}
void ofApp::updateAnim(){
float brightness = ofMap(sin(ofGetFrameNum() * 0.03), -1, 1, 0, 255);
ofColor color = ofColor(brightness, brightness, brightness, 100);
for(int i = 0; i < shapes.size(); i++) {
shapes.at(i).incrementRotateX(12);
shapes.at(i).incrementRotateY(0.8);
shapes.at(i).incrementRotateZ(-0.77);
shapes.at(i).incrementPositionX(4);
shapes.at(i).incrementPositionY(-6);
shapes.at(i).incrementPositionZ(12);
shapes.at(i).setColor(color);
}
}
void ofApp::drawAnim() {
ofEnableAlphaBlending();
//Swallow the trails
ofSetColor(0, 0, 0, 30);
ofRect(0, 0, width, height);
system.draw();
//Fade in
if(maskOpacity > 0 && ofGetFrameNum() < 20) {
ofSetColor(0, 0, 0, maskOpacity);
ofRect(0, 0, width, height);
maskOpacity -= 25;
}
//Fade out
if(ofGetFrameNum() > 20) {
ofSetColor(0, 0, 0, maskOpacity);
ofRect(0, 0, width, height);
maskOpacity += 25;
}
ofDisableAlphaBlending();
if(maskOpacity > 255) {
renderGif();
}
}
Going off the rails