Hi everyone,

I’ve been trying to convert this sketch from openprocessing vertical fire - OpenProcessing and something seems to be wrong here. In p5 sketch, it is:

loc = new PVector(x, y);

vel = new PVector(dx,dy);

vel.normalize();

vel.mult(10+random(10));

and i have translated this to

loc = vec2(_x,_y);

vel = vec2(_dx, _dy);

vec2 velNormalize = glm::normalize(vel);

velNormalize = velNormalize*(ofRandom(10.0f)+10);

and then in p5 sketch, update(), it is:

vel.add(acc);

vel.mult(decay);

vel.limit(3);

loc.add(vel);

I would assume it is the normalized vel to be updated, hence, in my OF sketch:

velNormalize += acc;

velNormalize *= decay;

if (glm::length(velNormalize) > 3) {

velNormalize = glm::normalize( velNormalize)*3.0f;

}

loc += vel;

I am not quite sure if this is the correct syntax, if I am wrong can you please help me point out where I aam doing things wrong? Thank you!

Here is the full code:

#include “Particles.h”

Particles::Particles(){

}

//--------------------------------------------------------------

void Particles::setup(float _x, float _y, float _xOff, float _yOff, int _dx, int _dy){

```
ofEnableSmoothing();
loc = vec2(_x,_y);
vel = vec2(_dx, _dy);
std::cout << "vel " << vel << endl;
vec2 velNormalize = glm::normalize(vel);
velNormalize = velNormalize*(ofRandom(10.0f)+10);
std::cout << "velNormalize " << velNormalize << endl;
acc = vec2(0,0);
lifeSpan = int(ofRandom(30,500));
decay = ofRandom(0.2, 0.55);
weightRange = ofRandom(3,50);
hue = ofRandom(0,30);
_xOff = xOff;
_yOff = yOff;
```

}

//--------------------------------------------------------------

void Particles::update(){

if(passedLife >= lifeSpan){

isDead = TRUE;

} else {

passedLife++;

}

c= ofColor(ofLerp(hue, 60, int(passedLife/lifeSpan)%360),

10,

20,

ofLerp(0, 100, float(passedLife)/lifeSpan));

```
alpha = float(lifeSpan - passedLife) / lifeSpan * 70 + 50;
weight = float(lifeSpan - passedLife) /lifeSpan * weightRange;
acc = {0,0};
float rn = ofNoise((loc.x + ofGetFrameNum() + xOff)*.001, (loc.y + ofGetFrameNum() + yOff)*.001 - .5)*TWO_PI*4;
float mag = ofNoise((loc.y - ofGetFrameNum())*.01, (loc.y - ofGetFrameNum() + yOff)*.01);
vec2 dir = vec2((cos(rn), tan(rn)));
acc += dir;
acc *= mag;
float randomRn = ofRandom(TWO_PI);
vec2 randV = vec2(cos(randomRn), sin(randomRn));
randV *= 2.5f;
std::cout << "randV" << randV << endl;
acc += randV;
velNormalize += acc;
velNormalize *= decay;
//use this if usinng glm::vec2
if (glm::length(velNormalize) > 3) {
velNormalize = glm::normalize( velNormalize)*3.0f;
}
loc += velNormalize;
```

}

//--------------------------------------------------------------

void Particles::draw(){

// ofSetLineWidth(weight); // this will make ccircle looks clover

```
ofSetColor(c);
ofFill();
ofDrawCircle(loc.x, loc.y, weight/-1000);
ofPoint(loc.x, loc.y);
```

}