The different performance of noise() in processing and p5.js

I found that it is not the noise() problem, but PVector, which is the latest code, which achieves the same effect as in the Vamoss tutorial (Chapter 2).

int total = 200;
PVector [] pos;
PVector [] dir;

void setup() {
  size(800, 800);
  pixelDensity(2);
  smooth();
  background(-1);
  pos = new PVector[total];
  dir = new PVector[total];

  for (int i = 0; i < total; i ++) {
    pos[i] = new PVector(width/2, height/2);
    dir[i] = new PVector(random(TWO_PI), random(TWO_PI));
  }
}

void draw() {
  int time = millis() / 1000;

  for (int i = 0; i < total; i ++) {
    PVector p = pos[i];
    PVector d = dir[i];

    d.add(noise(p.x, p.y, time) - 0.45, noise(p.x, p.y, time) - 0.45);

    p.x += cos(d.x);
    p.y += sin(d.x);

    circle(p.x, p.y, 10);
  }
}

It just changed float dir into PVector dir . Although it solved the problem, I don’t know the principle.

2 Likes