Created
October 13, 2017 19:26
-
-
Save jeffcrouse/e85adc11c7d4faba116f4a7fde7dc493 to your computer and use it in GitHub Desktop.
mid-point code for Week 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
#define NUM_PARTICLES 100 | |
float radius = 5; | |
vector<ofPoint> pos; | |
vector<ofPoint> vel; | |
vector<float> alpha; | |
ofPoint lastMousePos; | |
//-------------------------------------------------------------- | |
void ofApp::setup(){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
for(int i=pos.size()-1; i>=0; i--) { | |
pos[i] += vel[i]; | |
alpha[i] *= 0.99; | |
if(pos[i].x > ofGetWidth()-radius) { | |
pos[i].x = ofGetWidth()-radius; | |
vel[i].x *= -1; | |
} | |
if(pos[i].y > ofGetHeight()-radius) { | |
pos[i].y = ofGetHeight()-radius; | |
vel[i].y *= -1; | |
} | |
if(pos[i].x < radius) { | |
pos[i].x = radius; | |
vel[i].x *= -1; | |
} | |
if(pos[i].y < radius) { | |
pos[i].y = radius; | |
vel[i].y *= -1; | |
} | |
if(alpha[i] < 1) { | |
pos.erase(pos.begin()+i); | |
vel.erase(vel.begin()+i); | |
alpha.erase(alpha.begin()+i); | |
} | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
for(int i=0; i<pos.size(); i++) { | |
ofSetColor(0, alpha[i]); | |
ofDrawCircle(pos[i], radius); | |
} | |
ofSetColor(0); | |
ofDrawBitmapString(ofToString(pos.size()) + "\n" + ofToString(ofGetFrameRate()), 10, 20); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
ofPoint p(x,y); | |
pos.push_back( p ); | |
ofPoint v = p-lastMousePos; | |
v.limit(5); | |
v.x += ofRandom(-4, 4); | |
v.y += ofRandom(-4, 4); | |
vel.push_back( v ); | |
alpha.push_back(255); | |
lastMousePos.set(x,y); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseEntered(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseExited(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment