Last active
May 14, 2024 11:44
-
-
Save tado/3dd7c054b59d65134dd1812bed2bbd72 to your computer and use it in GitHub Desktop.
openFrameworks Array Animation Template
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" | |
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); | |
} |
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
#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