class Particle { public float x = 0; public float y = 0; public float vx = 0; public float vy = 0; public float k = .08; public boolean lines = true; public color col = color(255, random(128)+127, 0, 20); private float grav = 0; private float angle = 0; public void Particle() { } public void move() { float dx = mouseX - x; float dy = mouseY - y; float dist = sqrt(dx*dx + dy*dy); angle += .05; if(dist < 100) { float tx = mouseX - dx / dist * (cos(angle) * 50 + 50); float ty = mouseY - dy / dist * (sin(angle) * 50 + 50); vx += (tx - x) * k; vy += (ty - y) * k; } else { float force = 2000 / (dist * dist); vx += force * dx / dist; vy += force * dy / dist; } vx += random(-1, 1); vy += random(-1.5, 1.5); vy += grav; vx *= .95; vy *= .95; x += vx; y += vy; if(x > w) { x = w; vx *= -1; } if(x<0) { x = 0; vx *= -1; } if(y > h) { y = h; vy *= -1; } if(y < 0) { y = 0; vy *= -1; } } public void render() { stroke(col); if(lines) { line(x, y, x-vx, y-vy); } else { point(x, y); } } }