diff --git a/src/line.cpp b/src/line.cpp new file mode 100644 index 0000000..e63f226 --- /dev/null +++ b/src/line.cpp @@ -0,0 +1,10 @@ +#include "line.h" + +Line::Line() +{ +} + + +Line::~Line() +{ +} diff --git a/src/line.h b/src/line.h new file mode 100644 index 0000000..2db1ad1 --- /dev/null +++ b/src/line.h @@ -0,0 +1,16 @@ +#pragma once + +#include "ofMain.h" + +class Line +{ +public: + Line(); + ~Line(); + + ofPolyline lines; + + ofPoint a; + ofPoint b; +}; + diff --git a/src/particle.cpp b/src/particle.cpp new file mode 100644 index 0000000..4c30988 --- /dev/null +++ b/src/particle.cpp @@ -0,0 +1,148 @@ + +// particle.cpp +// particleSystem +// + +#include "particle.h" +#include "ofApp.h" + +Particle::Particle() +{ + +} + +//-------------------------------------------------------------------------------------- + +Particle::~Particle() +{ + +} + +//-------------------------------------------------------------------------------------- + + +void Particle::setup(ofVec2f _position) { + + this->position = _position; + + vel.set(ofRandom(-3.0, 3.0), ofRandom(-3.0, 3.0)); + + age = 0.0; + maxLife = 12.0; + + color.set(250, 250, 250); + + size = ofRandom(4.0, 0.01); + + mass = ofRandom(100, 250); + + tex.load("img/overlay.png"); + +} + + + +//-------------------------------------------------------------------------------------- + +void Particle::update(float deltaT, vector* attractors) { + + ofVec2f force; + counterOfActiveAttractors = 0; + for (int i = 0; i < attractors->size(); i++) { + if (attractors->at(i)->getX() == 0 && attractors->at(i)->getY() == 0) { + force = 0 * force.getNormalized(); + vel += force; + vel = mass * vel.getNormalized(); + break; + } + + counterOfActiveAttractors++; + force.set(attractors->at(i)->getX() - position.x, attractors->at(i)->getY() - position.y); + + if (force.length() < 150) { + force = 60 * force.getNormalized(); + size = size + ofRandom(.01, 0.01); + + vel += force; + vel = mass * vel.getNormalized(); + } + else { + force = 0 * force.getNormalized(); + vel += force; + vel = mass * vel.getNormalized(); + } + } + + age += deltaT * .5; + position += (vel * deltaT); + + // *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION + + //if (position.x <= 0 || position.x >= ofGetWidth()) { + //vel.x = -vel.x; + //position += (vel * deltaT); + //} + //else if (position.y <= 0 || position.y >= ofGetHeight()) { + //vel.y = -vel.y; + //position += (vel * deltaT); + //} + //else { + //position += (vel * deltaT); + //} + + + //void thParticle::update(float deltaT, ofVec2f attractor){ + // + // + // age += deltaT; + // + // ofVec2f force = attractor - position; + // color.set(250,250, 250, (1 - age / maxLife) * 255); + // + // if( force.length() < 40 && force.length() > 11 ){ + // velocity = velocity.getNormalized() * mass; + // velocity += 0.01 * force ; + // + // }else if(force.length() < 12){ + // velocity = velocity.getNormalized() * mass; + // velocity += 5 * force ; + // + // }else{ + // + // velocity = velocity.getNormalized() * mass; + // velocity += 0.12 * force ; + // } + // position += velocity * deltaT; + //} +} + +//-------------------------------------------------------------------------------------- + +void Particle::draw() { + + color.set(getAgeNorm() * 241,241/ getAgeNorm() ,219); + + ofSetColor(color, (1 - getAgeNorm()) * 255); + //tex.setColor(color); + //tex.draw(position, size, size); + + ofDrawCircle(position, size); +} + +//-------------------------------------------------------------------------------------- + + +float Particle::getAgeNorm() { + return age / maxLife; +} + + +//-------------------------------------------------------------------------------------- + + +float Particle::getMaxLife() { + return 1; +} + + +//-------------------------------------------------------------------------------------- \ No newline at end of file