processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.49k stars 3.29k forks source link

Noise never gets close to 0.0 nor 1.0 #3558

Closed Mamboleoo closed 5 years ago

Mamboleoo commented 5 years ago

Nature of issue?

Most appropriate sub-area of p5.js?

Which platform were you using when you encountered this?

Details about the bug:

Hey there, I'm currently playing with the noise function to make some demos and I noticed that whenever I call the noise() function it never returns a number close to 0.0 or 1.0. I'm making dots moving around the screen by multiplying the noise value by the width & height of the canvas.

this.x = noise(millis() * 0.0003) * width;
this.y = noise(10 + millis() * 0.0003) * height;

But as you can see on this screenshot, my dots are always gathering in the center of my screen. image

You can access this live demo on CodePen. If you press on the window I'm switching from P5's native noise function to another one I found online and it's quite clear that the external algorithm is returning more extended values. https://codepen.io/Mamboleoo/pen/WmwOKe

I'm not 100% sure this is a proper 'bug' or the way P5's noise algorithm is supposed to work but in my case it doesn't really export nice results.

Thanks for your help! Louis

Ajayneethikannan commented 5 years ago

Hey @Mamboleoo ! I think it's the intended behavior due to the bell curve distribution of the function, mentioned by Dan in this video, https://www.youtube.com/watch?v=YcdldZ1E9gU

Mamboleoo commented 5 years ago

Oh I see, so I guess I only have two solutions then.

b2renger commented 5 years ago

@Mamboleoo if you want you could use noise as a speed instead of as a position ie use the noise to add something to both coordinates

hellonearthis commented 5 years ago

there is a nice Open simplex noise library here. https://github.com/blindman67/SimplexNoiseJS Not as fast at the perlin noise, so map() might be a better choice. @shiffman did a great live show last week on simplex noise in Java but was good to see the difference between the two noise types.