Skip to content

Instantly share code, notes, and snippets.

@roxlu
Created December 7, 2011 11:53
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 roxlu/1442538 to your computer and use it in GitHub Desktop.
Save roxlu/1442538 to your computer and use it in GitHub Desktop.
#include "Particle.h"
// constructor function - executed directly!
Particle::Particle() {
velocity.set(1,2);
position.set(0,0);
mass = ofRandom(0.2,10);
forces.set(0.4,0.1);
}
void Particle::draw() {
// forces calculations
ofVec2f affect = forces / mass;
velocity = velocity + affect;
position = position + velocity;
forces.set(0,0);
// drawing
ofCircle(position.x,position.y,mass);
}
void Particle::addForce(ofVec2f force) {
forces = forces + force;
}
void Particle::setPosition(int x, int y) {
position.set(x,y);
velocity.set(0,0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment