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

**URL:** <https://discourse.processing.org/t/the-different-performance-of-noise-in-processing-and-p5-js/32019>\
**Category:** Beginners\
**Created:** [August 31, 2021, 3:18am UTC](https://discourse.processing.org/t/the-different-performance-of-noise-in-processing-and-p5-js/32019 "2021-08-31T03:18:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![niuuin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/niuuin/32/7517_2.png) [@niuuin](https://discourse.processing.org/u/niuuin)\
**Post date:** [August 31, 2021, 3:18am UTC](https://discourse.processing.org/t/the-different-performance-of-noise-in-processing-and-p5-js/32019/1 "2021-08-31T03:18:44Z")

</div>

I am learning a tutorial from [Vamoss](https://openprocessing.org/sketch/1036179/) and trying to implement it with Processing.

> **[Organic Trail Tutorial - OpenProcessing](https://openprocessing.org/sketch/1036179/)**

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/496371c405dc828ca5f241afe3f42d72ee22bb16.png)

But I encountered a problem in the noise() part of Chapter 2, which resulted in a different result from Vamoss.

This is my code:

```auto
int total = 200;
PVector [] pos;
float [] dir;

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

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

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

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

    d += noise(p.x, p.y, time) - 0.5; 

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

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

```

I have checked it many times, and the code logic is ok, may I ask what went wrong? thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![niuuin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/niuuin/32/7517_2.png) [@niuuin](https://discourse.processing.org/u/niuuin)\
**Post date:** [August 31, 2021, 3:51am UTC](https://discourse.processing.org/t/the-different-performance-of-noise-in-processing-and-p5-js/32019/2 "2021-08-31T03:51:01Z")

</div>

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](https://openprocessing.org/sketch/1036179/) (Chapter 2).

```auto
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.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 31, 2021, 5:37am UTC](https://discourse.processing.org/t/the-different-performance-of-noise-in-processing-and-p5-js/32019/3 "2021-08-31T05:37:39Z")

</div>

> [@niuuin](#):
>
> Although it solved the problem, I don’t know the principle.

In Java we create objects outta existing classes via keyword `new`. We can’t use JS `{}` syntax for it.
