xxxxxxxxxx
/*
Taken from:https://www.youtube.com/watch?v=sZBfLgfsvSk
*/
let particles = [];//Liste, wo die Partikel gespeichert werden, die sich über den Screen bewegen
const num = 1000; //Anzahl der Partikel, die erzeugt werden
let noiseScale = 0.01/2; //
function setup() {
createCanvas(400, 400);
for(let i = 0; i < num; i ++) {
particles.push(createVector(random(width), random(height)));
/*num Partikel, werden als Vektoren erstellt, die random auf dem Screen gesetzt werden - random(width)=x, random(height)=y*/
}
stroke(255);
// For a cool effect try uncommenting this line
// And comment out the background() line in draw
// stroke(255, 50);
clear();
}
function draw() {
background(0, 10);
for(let i = 0; i < num; i ++) {
let p = particles[i];
point(p.x, p.y);//zeichne dort einen Punkt, wo der Vektor/Patikel ist
let n = noise(p.x * noiseScale, p.y * noiseScale, frameCount * noiseScale * noiseScale);//Bewegung der Punkte mit Hilfe der noise Funkiton
let a = TWO_PI * n; //lasse diese Bewegung in einem Winkel verlaufen
p.x += cos(a);//durch cos und sin wird die neue Position des Partikels berechnet
p.y += sin(a);
if(!onScreen(p)) {
p.x = random(width);
p.y = random(height);
}
}
}
function mouseReleased() {
noiseSeed(millis());//verändert den Noise wert beim clicken der Maus
}
function onScreen(v) {
return v.x >= 0 && v.x <= width && v.y >= 0 && v.y <= height; //checkt, ob der Partikel noch auf dem Screen ist
}