class Particle { Particle(float _x, float _y, float _r, int _h) { x = _x; y = _y; dt = 0.04; vx = 0; vy = 0; or = _r; r = _r; if(h != 0) { colorMode(HSB, 255); c = color(h + random(30), 200 + random(55), 50 + random(205), 4); colorMode(RGB, 255); } else { c = color(random(255), random(255), random(255), 4); } } void Interact(float _x, float _y) { ax = _x - x; ay = _y - y; vx += ax * dt; vy += ay * dt; if(sqrt(vx*vx + vy*vy) > 5*r) { vx *= 0.1; vy *= 0.1; } x += vx * dt; y += vy * dt; vx *= 0.9; vy *= 0.9; if(x < 0) x = width - 1; if(y < 0) y = height - 1; if(x > width) x = 0; if(y > height) y = 0; r = or + 0.25*or*cos(millis() * 0.0001); } void Render() { fill(c); pushMatrix(); translate(x, y, 0); rotateZ(PI*0.5 + atan2(vy, vx)); beginShape(TRIANGLES); vertex(0, -r, 0); vertex(-r, r, 0); vertex(r, r, 0); endShape(); popMatrix(); } int c; float or, r; float x, y; float vx, vy, ax, ay; float dt; }