Skip to content

Instantly share code, notes, and snippets.

@nulltask
Created February 8, 2012 08:18
Show Gist options
  • Save nulltask/1766738 to your computer and use it in GitHub Desktop.
Save nulltask/1766738 to your computer and use it in GitHub Desktop.
ofLecture 1
#include "testApp.h"
#define MAX_NUM 1000
ofPoint points[MAX_NUM];
ofPoint direction[MAX_NUM];
float rad[MAX_NUM];
ofColor colors[MAX_NUM];
//--------------------------------------------------------------
void testApp::setup(){
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofEnableAlphaBlending();
ofBackground(0, 0, 0);
ofEnableSmoothing();
int w = ofGetWidth();
int h = ofGetHeight();
for (int i = 0; i < MAX_NUM; ++i) {
rad[i] = ofRandom(25.0, 50.0);
}
for (int i = 0; i < MAX_NUM; ++i) {
int x = ofRandom(w);
int y = ofRandom(h);
points[i].set(x, y);
}
for (int i = 0; i < MAX_NUM; ++i) {
float x = ofRandom(-5, 5);
float y = ofRandom(-5, 5);
direction[i].set(x, y);
}
for (int i = 0; i < MAX_NUM; ++i) {
colors[i].r = ofRandom(255);
colors[i].g = ofRandom(255);
colors[i].b = ofRandom(255);
colors[i].a = ofRandom(32, 64);
}
}
//--------------------------------------------------------------
void testApp::update(){
for (int i = 0; i < MAX_NUM; ++i) {
points[i].x += direction[i].x;
if (points[i].x > ofGetWidth() || points[i].x < 0) {
direction[i].x *= -1;
}
if (points[i].y > ofGetHeight() || points[i].y < 0) {
direction[i].y *= -1;
}
points[i].y += direction[i].y;
}
}
//--------------------------------------------------------------
void testApp::draw(){
for (int i = 0; i < MAX_NUM; ++i) {
ofSetColor(colors[i]);
ofCircle(points[i].x, points[i].y, rad[i]);
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
cout << key << endl;
if (key == 'c' || key == 'C') {
// r = ofRandom(255);
// g = ofRandom(255);
// b = ofRandom(255);
}
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment