xxxxxxxxxx
let num = 10000; // particle sayısı
let particles = [];
let noiseScale = 900, noiseStrength = 11;
let colors = ['#e54233', '#4b8c38', '#fac855', '#edb9ea']; //kırmızı,sarı,hardal, pembe
function setup() {
createCanvas(800, 800);
smooth(8); // better quality için
noStroke();
// karenin sınırları partice sınırlamak için
let squareX = 200, squareY = 200, squareSize = 400;
for (let i = 0; i < num; i++) {
let angle = random(TWO_PI); // random açılar particle için
let x = squareX + random(squareSize); // Ensuring particles spawn within the square
let y = squareY + random(squareSize);
let loc = createVector(x, y);
let dir = createVector(cos(angle), sin(angle));
let speed = random(0.3, 2); // particle hızları random
let col = colors[int(random(colors.length))]; // renklerden rastgele bir renk
particles.push(new Particle(loc, dir, speed, col)); // renkleri rastgele atayarak partikülleri oluşturur
}
}
function draw() {
fill(0, 10);
rect(0, 0, width, height);
// Draw the confining square without filling it and without stroke
// stroke(255); //white color for kare
noStroke();
rect(200, 200, 400, 400); // Only the square's area is drawn without a border
noStroke(); // No border for the particles
for (let i = 0; i < particles.length; i++) {
particles[i].run();
}
}
class Particle {
constructor(loc, dir, speed, col) {
this.loc = loc;
this.dir = dir;
this.speed = speed;
this.col = col; // Constructor içinde renk ataması
}
run() {
this.move();
this.checkEdges();
this.update();
}
move() {
let angle = noise(this.loc.x / noiseScale, this.loc.y / noiseScale) * TWO_PI * noiseStrength;
this.dir.x = cos(angle);
this.dir.y = sin(angle);
let vel = this.dir.copy();
vel.mult(this.speed);
this.loc.add(vel);
}
checkEdges() {
if (this.loc.x < 200 || this.loc.x > 600 || this.loc.y < 200 || this.loc.y > 600) {
this.loc.x = random(200, 600);
this.loc.y = random(200, 600);
}
}
update() {
fill(this.col); // Her partikül kendi rengi ile çizilir
ellipse(this.loc.x, this.loc.y, 2, 2); // particle boyutu
}
}