#include "testApp.h" //-------------------------------------------------------------- void testApp::setup(){ ofSetVerticalSync(true); ofSetFrameRate(60); ofBackground(0, 0, 0); setRandScreenPos(); unsigned int num_particles = 500; for (int i = 0; i < num_particles; i++){ // position float pos_x = mRandPosX; float pos_y = mRandPosY; float pos_z = 0; // velocity float vel_x = 0; float vel_y = 0; float vel_z = 0; // force (circular force ..?) float theta = (i / (float) num_particles) * TWO_PI; float magnitude = ofRandom(0.1, 3.0); float frc_x = cos(theta) * magnitude; float frc_y = sin(theta) * magnitude; float frc_z = 0; particle particleNeue; particleNeue.init( pos_x, pos_y, pos_z, vel_x, vel_y, vel_z, frc_x, frc_y, frc_z ); particles.push_back(particleNeue); } // timer for firing works mTimer = 0; } //-------------------------------------------------------------- void testApp::update(){ for (int i = 0; i < particles.size(); i++){ particles[i].resetForce(); particles[i].addDampin(); particles[i].update(); } mTimer++; if (100 == mTimer){ restart(); mTimer = 0; } sprintf(debugTxt, "timer: %i", mTimer ); } //-------------------------------------------------------------- void testApp::restart(){ setRandScreenPos(); for (int i = 0; i < particles.size(); i++){ particles[i].rebegin(); // position float pos_x = mRandPosX; float pos_y = mRandPosY; float pos_z = 0; // velocity float vel_x = 0; float vel_y = 0; float vel_z = 0; // force (circular force ..?) float theta = (i / (float) particles.size()) * TWO_PI; float magnitude = ofRandom(0.1, 3.0); float frc_x = cos(theta) * magnitude; float frc_y = sin(theta) * magnitude; float frc_z = 0; particles[i].init( pos_x, pos_y, pos_z, vel_x, vel_y, vel_z, frc_x, frc_y, frc_z ); } } //-------------------------------------------------------------- void testApp::draw(){ ofSetColor(0x333333); ofDrawBitmapString(debugTxt, 40, 40); for (int i = 0; i < particles.size(); i++){ particles[i].draw(); } } //-------------------------------------------------------------- void testApp::setRandScreenPos(){ mRandPosX = ofRandom(50, ofGetWidth()-50); mRandPosY = ofRandom(50, ofGetHeight()-50); }