float x,y,r; float vx,vy; float t,dt; boolean set_pos,set_vel; void setup() { size(700,500); background(0); frameRate(200); noStroke(); x = mouseX; y = mouseY; set_pos = false; set_vel = false; dt = 0.25; } void draw() { fill(34,34,68,20); rect(0,0,width,height); if (set_vel) { if (x<=r || x>width-r) vx = -vx; if (y<=r || y>height-r) vy = -vy; x += vx*dt; y += vy*dt; float u=x,v=y; float vu=vx,vv=vy; stroke(15,150,255,100); strokeWeight(4); alpha(1); for (int i=0; i<500; i++) { if (u<=r || u>width-r) vu = -vu; if (v<=r || v>height-r) vv = -vv; stroke(15,150,255,255*(1-i/500.)); line(u,v,u+vu*dt,v+vv*dt); u += vu*dt; v += vv*dt; } noStroke(); } else if (set_pos) { strokeWeight(2); line(x,y,mouseX,mouseY); noStroke(); } else { ellipse(mouseX,mouseY,20,20); } fill(50,100,255,120); ellipse(x,y,20,20); if (mousePressed && set_pos) { vx = mouseX-x; vy = mouseY-y; set_vel = true; } else if (mousePressed) { x = (int)(mouseX); y = (int)(mouseY); set_pos = true; } }