xxxxxxxxxx
let particles = [];
let numParticles = 25000;
let snakePosition;
let bgColor;
let squareX = 200, squareY = 200, squareSize = 400;
function setup() {
createCanvas(800, 800);
bgColor = color(255); // Beyaz arka plan
background(bgColor);
noStroke();
// Random konumlandırma ile partikülleri oluştur, ancak sadece belirlenen kare içinde
for (let i = 0; i < numParticles; i++) {
let x = random(squareX, squareX + squareSize);
let y = random(squareY, squareY + squareSize);
particles.push(new Particle(x, y, 2));
}
// Başlangıç pozisyonu
snakePosition = createVector(width / 2, height / 2);
}
function draw() {
fill(bgColor);
rect(0, 0, width, height); // Arka planı sürekli beyaz ile doldur
for (let particle of particles) {
particle.update(snakePosition);
particle.show();
}
updateSnakePosition();
}
function updateSnakePosition() {
let speed = 0.2;
let noiseScale = 0.04;
let targetX = noise(frameCount * noiseScale) * width;
let targetY = noise(frameCount * noiseScale + 1000) * height;
let target = createVector(targetX, targetY);
snakePosition.x += (target.x - snakePosition.x) * speed;
snakePosition.y += (target.y - snakePosition.y) * speed;
}
class Particle {
constructor(x, y, size) {
this.pos = createVector(x, y);
this.size = size;
this.velocity = createVector(random(-1, 1), random(-1, 1));
}
update(target) {
let force = p5.Vector.sub(target, this.pos);
force.setMag(0.5); // Çekim kuvvetini azalt
this.velocity.add(force);
this.velocity.limit(3); // Hız limiti
this.pos.add(this.velocity);
// Partiküllerin kare içinde kalmasını sağla
this.pos.x = constrain(this.pos.x, squareX, squareX + squareSize);
this.pos.y = constrain(this.pos.y, squareY, squareY + squareSize);
}
show() {
stroke(0); // Siyah noktalar
strokeWeight(this.size);
point(this.pos.x, this.pos.y);
}
}