Skip to content

Instantly share code, notes, and snippets.

@jeffcrouse
Created October 13, 2017 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffcrouse/13ab27ac64ce35df8b39bade23470578 to your computer and use it in GitHub Desktop.
Save jeffcrouse/13ab27ac64ce35df8b39bade23470578 to your computer and use it in GitHub Desktop.
Starting point code for Week 6
#include "ofApp.h"
#define NUM_PARTICLES 100
float radius = 10;
ofPoint pos[NUM_PARTICLES];
ofPoint vel[NUM_PARTICLES];
//--------------------------------------------------------------
void ofApp::setup(){
for(int i=0; i<NUM_PARTICLES; i++) {
pos[i].x = ofRandom( radius, ofGetWidth()-radius );
pos[i].y = ofRandom( radius, ofGetHeight()-radius );
vel[i].x = ofRandom(-10, 10);
vel[i].y = ofRandom(-10, 10);
}
}
//--------------------------------------------------------------
void ofApp::update(){
for(int i=0; i<NUM_PARTICLES; i++) {
pos[i] += vel[i];
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;
}
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(0);
for(int i=0; i<NUM_PARTICLES; i++) {
ofDrawCircle(pos[i], radius);
}
}
//--------------------------------------------------------------
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){
}
//--------------------------------------------------------------
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