class Particle { public float x = 0; public float y = 0; public float vx = 0; public float vy = 0; public float k = .01; public float er = random(1,8); public boolean lines = false; public void Particle() { } public void move1() { float dx = mouseX - x; float dy = mouseY - y; float dist = sqrt(dx*dx + dy*dy); if(dist < 150) { float tx = mouseX + dx / dist * 20; float ty = mouseY + dy / dist * 20; vx += (tx - x) * k; vy += (ty - y) * k; } vx += random(-1, 1); vy += random(-1, 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 move2() { float dx = mouseX - x; float dy = mouseY - y; float distSQ = dx*dx + dy*dy; float dist = sqrt(distSQ); float force = 500 / distSQ; vx += force * dx / dist; vy += force * dy / dist; vx += random(-1, 1); vy += random(-1, 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 render1() { if(lines) { stroke(b,c,d,20); line(x, y, x-vx, y-vy); float sw1 = random(1,3); //float sw1 = noise(0)*3; strokeWeight(sw1); line(x, y, x-vx, y-vy); float sw2 = random(1,6); //float sw2 = noise(0)*6; strokeWeight(sw2); line(x, y, x-vx, y-vy); float sw3 = random(1,9); //float sw3 = noise(0)*9; strokeWeight(sw3); line(x, y, x-vx, y-vy); } else { noStroke(); fill(b,c,d,10); float e1=random(3,30); ellipse(x,y,e1,e1); float e2= random(3,18); ellipse(x,y,e2,e2); float e3= random(3,9); ellipse(x,y,e3,e3); ellipse(x,y,3,3); } } public void render2() { if(lines) { strokeWeight(1); stroke(b,c,d); line(x, y, x-vx, y-vy); } else { noStroke(); fill(b,c,d,30); ellipse(x,y,er,er); } } }