You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let's say I'm going to pick random values over time to start with.
let's say I'm going to pick them very 10 units of time
And I'm to pick those random values with some amplitude, between something like 0~100
Now, the next thing I want to do is to an interpolation function.
so here is the start of my Perlin noise function.
Now, the next thing I want to do is to an interpolation function.
ANd let's just pretend I also had to pick a value a 0, which let's say I picked this 1
Now I'm going to do that again. This time, however, I'm going to pick those random values every 5 units of time.
and instead of picking between 0 and 100, I'm just going to pick between 0 and 50.
double freq, halve amplitude.
repeat the process, every 2.5 units of time, and values between 0 and 25
...
Now, what if I were to do this prossibly 8 times, 16 times, 25 times, however many times I want, and each time I'm halving essentially the sampling time interval, and also halving the amplitude ? What then if I take all of these and add them together ?
THis is essentially how Perlin noise is calculated. And these, what the above pictures show, by the way, are known as octaves.
So Perlin noise is calculated over a number of octaves. And essentially it's a bunch of random waveforms.
the more ocatves that you have, the more fine detail you're getting.
the smaller the shrinking factor is (currently 0.5), the smoother the graph has..
2. noise() vs random()
perlin noise function needs a parameter: the offset in x-axis, in float.
calling noise(100) always return same value until reinitialize
4. 2D noise
// 2D Noise// The Coding Train / Daniel Shiffman// https://thecodingtrain.com/learning/noise/0.5-2d-noise.html// https://youtu.be/ikwNrFvnL3g// https://editor.p5js.org/codingtrain/sketches/2_hBcOBrF// This example has been updated to use es6 syntax. To learn more about es6 visit: https://thecodingtrain.com/Tutorials/16-javascript-es6letinc=0.01;functionsetup(){createCanvas(200,200);pixelDensity(1);}functiondraw(){letyoff=0;loadPixels();for(lety=0;y<height;y++){letxoff=0;for(letx=0;x<width;x++){letindex=(x+y*width)*4;// let r = random(255);letr=noise(xoff,yoff)*255;pixels[index+0]=r;pixels[index+1]=r;pixels[index+2]=r;pixels[index+3]=255;xoff+=inc;}yoff+=inc;}updatePixels();//noLoop();}
6. Coding Challenge #24: Perlin Noise Flow Field
instead of having a grayscale value for each pixel, what I want to have is a vector, an arrow pointing in some direction according to Perlin noise.
letinc=0.1;varscl=10;varcols,rows;varfr;functionsetup(){createCanvas(200,200);pixelDensity(1);cols=floor(width/scl);rows=floor(height/scl);fr=createP("")}functiondraw(){background(255);letyoff=0;// loadPixels(); // no pixel for this demofor(lety=0;y<rows;y++){letxoff=0;for(letx=0;x<cols;x++){letindex=(x+y*width)*4;// let r = random(255);letangle=noise(xoff,yoff)*TWO_PI;varv=p5.Vector.fromAngle(angle);// horizontal right xoff+=inc;// fill(r);// rect(x*scl, y*scl, scl, scl);stroke(0);push();translate(x*scl,y*scl);// move to grid left-bottom cornerrotate(v.heading());// rotate // draw vector lineline(0,0,scl,0);// draw horizontal linepop();}yoff+=inc;}// updatePixels();//noLoop();fr.html(floor(frameRate()));}
flow field animation
3D perlin noise. one dimension is the x axis, another dimension is the y axis.
imagine a z dimension as slices. we though the z axis is the time, every frame of the animation.
letinc=0.1;varscl=10;varcols,rows;varzoff=0;varfr;functionsetup(){createCanvas(200,200);pixelDensity(1);cols=floor(width/scl);rows=floor(height/scl);fr=createP("")}functiondraw(){background(255);letyoff=0;// loadPixels(); // no pixel for this demofor(lety=0;y<rows;y++){letxoff=0;for(letx=0;x<cols;x++){letindex=(x+y*width)*4;// let r = random(255);letangle=noise(xoff,yoff,zoff)*TWO_PI;varv=p5.Vector.fromAngle(angle);// horizontal right xoff+=inc;// fill(r);// rect(x*scl, y*scl, scl, scl);stroke(0);push();translate(x*scl,y*scl);// move to grid left-bottom cornerrotate(v.heading());// rotate // draw vector lineline(0,0,scl,0);// draw horizontal linepop();}yoff+=inc;}zoff+=0.05;// updatePixels();//noLoop();fr.html(floor(frameRate()));}
particles
for every particles location look up the vector that's nearest to it and then apply that as a force.
If you draw a circle with noised vertex , normaly the last vertex won't match the first vertex.
To solve this problem, we use 2d perlin noise instead.
we pick the noise along the circle in 2D perlin plane
but now it is weirdly symmetrical, why ?
because cos(a), sin(a) are [-1,1], but perlin noise space are all positive, it doesn't exists in negative space.
let's simply fix it
we can parameterize the maximum noise value
letxoff=map(cos(a),-1,1,0,noiseMax);
add a phase to make it rotating
again, you can use z-axis of perlin noise to make animation
IDEA:
I have perlin noise values in 1D space, but they don't loop.
Why not take those looping values along the path of circle which is in 2D perlin plane, and then unfold them back into the sort of 1D line, and use those to apply to any value in any visualization to make perfect GIF loop.