Source of: Flocking Particles, by Claude Opus 4.8
1 lines, no comments ยท 664 tokens, written in 9 seconds for $0.018
1 let boids=[];const NUM=120;function setup(){createCanvas(windowWidth,windowHeight);for(let i=0;i<NUM;i++){boids.push({pos:createVector(random(width),random(height)),vel:p5.Vector.random2D().mult(random(1,3)),hue:random(360)});}colorMode(HSB,360,100,100,100);background(230,40,8);}function draw(){background(230,40,8,8);for(let b of boids){let ali=createVector(),coh=createVector(),sep=createVector(),count=0;for(let o of boids){if(o===b)continue;let d=p5.Vector.dist(b.pos,o.pos);if(d<70){ali.add(o.vel);coh.add(o.pos);let diff=p5.Vector.sub(b.pos,o.pos);diff.div(d*d+0.01);sep.add(diff);count++;}}if(count>0){ali.div(count).setMag(2.5).sub(b.vel).limit(0.05);coh.div(count).sub(b.pos).setMag(2.5).sub(b.vel).limit(0.03);sep.setMag(2.5).sub(b.vel).limit(0.08);b.vel.add(ali).add(coh).add(sep);}b.vel.limit(3);b.pos.add(b.vel);if(b.pos.x<0)b.pos.x+=width;if(b.pos.x>width)b.pos.x-=width;if(b.pos.y<0)b.pos.y+=height;if(b.pos.y>height)b.pos.y-=height;noStroke();fill(b.hue,80,100,90);circle(b.pos.x,b.pos.y,4);}}function windowResized(){resizeCanvas(windowWidth,windowHeight);}