xxxxxxxxxx
37
// Perlin noise: generates smoothly varying, pseudo-random values based on the input coordinates.
let particles = []; // variable for the particles
const num = 2000 // how many particles will be displayed
const noiseScale = 0.01000000
function setup() {
createCanvas(800, 600);
for(let i = 0; i < num; i++) {
particles.push(createVector(random(width), random(height)));
}
stroke(random(255),random(255), random(255))
strokeWeight(0.5)
}
function draw() {
background;
for(let i = 0; i < num; i++) {
let p = particles[i];
square(p.x, p.y,2)
let n = noise(p.x * noiseScale, p.y * noiseScale ); //Multiplies the x-coordinate of the point p by a value noiseScale.... Multiplies the y-coordinate of the point p by the same value noiseScale.
let a = TAU * n; //TAU = 2PI & n = value calculated in previous line
p.x += cos(a) // incrementing the x and y coordinates of a point based on the cosine and sine of angle (a)
p.y+= sin(a)
// function mousePressed() {
// particles.push(createVector(mouseX, mouseY));
}
}