Skip to content

Instantly share code, notes, and snippets.

@tado
Last active May 14, 2024 11:44
Show Gist options
  • Save tado/3dd7c054b59d65134dd1812bed2bbd72 to your computer and use it in GitHub Desktop.
Save tado/3dd7c054b59d65134dd1812bed2bbd72 to your computer and use it in GitHub Desktop.
openFrameworks Array Animation Template
#include "ofApp.h"
void ofApp::setup() {
}
void ofApp::update() {
for (int i = 0; i < location.size(); i++) {
location[i] += velocity[i];
if (location[i].x < 0 || location[i].x > ofGetWidth()) {
velocity[i].x *= -1;
}
if (location[i].y < 0 || location[i].y > ofGetHeight()) {
velocity[i].y *= -1;
}
}
}
void ofApp::draw() {
for (int i = 0; i < location.size(); i++) {
ofDrawCircle(location[i], 5);
}
ofDrawBitmapStringHighlight(
"Num = " + ofToString(location.size()), 20, 20);
ofDrawBitmapStringHighlight(
"FPS = " + ofToString(ofGetFrameRate()), 20, 40);
}
void ofApp::mouseDragged(int x, int y, int button) {
glm::vec2 loc = glm::vec2(x, y);
location.push_back(loc);
glm::vec2 vel = glm::vec2(ofRandom(-2, 2), ofRandom(-2, 2));
velocity.push_back(vel);
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void mouseDragged(int x, int y, int button);
static const int NUM = 100;
vector<glm::vec2> location;
vector<glm::vec2> velocity;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment