Skip to content

Instantly share code, notes, and snippets.

@jeffcrouse
Created October 6, 2017 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffcrouse/9bdc0fdd575514f2eaa0da14e80c95bd to your computer and use it in GitHub Desktop.
Save jeffcrouse/9bdc0fdd575514f2eaa0da14e80c95bd to your computer and use it in GitHub Desktop.
Starting code for Week 5 lesson about particle systems
#include "ofApp.h"
ofPoint velocity;
ofPoint position;
ofColor color;
float radius = 20;
//--------------------------------------------------------------
void ofApp::setup(){
ofSetWindowShape(1024, 768);
ofSetWindowTitle("particle-starter");
ofSetFrameRate(60);
ofBackground(255, 255, 255);
ofEnableSmoothing();
ofSetCircleResolution(40);
velocity.x = ofRandom(-6, 6);
velocity.y = ofRandom(-6, 6);
position.x = ofGetWidth() / 2.0;
position.y = ofGetHeight() / 2.0;
color.set(100, 100, 100);
}
//--------------------------------------------------------------
void ofApp::update(){
position += velocity;
if(position.x < radius) {
position.x = radius;
velocity.x *= -1;
}
if(position.x > ofGetWidth()-radius) {
position.x =ofGetWidth()-radius;
velocity.x *= -1;
}
if(position.y < radius) {
position.y = radius;
velocity.y *= -1;
}
if(position.y > ofGetHeight()-radius) {
position.y = ofGetHeight()-radius;
velocity.y *= -1;
}
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(color);
ofDrawCircle(position, 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