class Particle { public float x = 0; public float y = 0; public float vx = 0; public float vy = 0; public float k = .01; public boolean lines = false; public void Particle() { } public void move() { float dx = mouseX - x; float dy = mouseY - y; float dist = sqrt(dx*dx + dy*dy); if(dist < 100) { float tx = mouseX - dx / dist * 20; float ty = mouseY - dy / dist * 100; vx += (tx - x) * k; vy += (ty - y) * k; } vx += random(-1, 1); vy += random(-1, 1); vy += .1; 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(255, 128); if(lines) { line(x, y, x-vx, y-vy); } else { point(x, y); } } }