// GE01 float pos = 130, a, x, origin, marker, oldmouse; int count = 0; boolean check= true, move = false; Ball balls[] = new Ball[200]; wave waves[] = new wave[6]; void setup() { size(1200, 230); stroke(150, 100, 0); rectMode(CENTER_DIAMETER); smooth(); cursor(HAND); // Initialise the array of vertices. for (int i = 0; i < balls.length; i++) { balls[i] = new Ball(); balls[i].x = i*width/(balls.length-1); } for (int i = 0; i < waves.length; i++) { waves[i] = new wave(); } } void loop() { background(30); if (!check && mouseY < pos) check = true; if (mouseY > pos && check) { origin = mouseX; a = mouseY - pos; for (int i = 0; i < balls.length; i++) { x = abs(balls[i].x - origin); if (x < 15*a) balls[i].y += a*(-x/(a*15)+1) * cos(5*x/(a*sqrt(-x+20*a))); } if (mouseY-oldmouse < 5*a) { move = true; if (count>4) count = 0; else count++; waves[count].var_marker = 0; check = false; waves[count].var_move = true; waves[count].var_origin = origin; waves[count].var_a = a; } } else { if (!move) for (int i = 0; i < balls.length; i++) balls[i].y = pos; } oldmouse = mouseY; beginShape(LINE_STRIP); // The first vertex on the curve curveVertex(balls[0].x, balls[0].y); // All vertices for (int i = 0; i < balls.length; i++) { curveVertex(balls[i].x, balls[i].y); } // The last vertex on the curve curveVertex(balls[balls.length - 1].x, balls[balls.length - 1].y); endShape(); for (int j = 0; j < balls.length; j++) { balls[j].y = pos; for (int i=0; i < waves.length; i++) { if (waves[i].var_move) { if (j==0) { waves[i].var_a/=1.05f; waves[i].var_marker+=10*sqrt(waves[i].var_a); } x = abs(balls[j].x - waves[i].var_origin) - waves[i].var_marker; if (x < 15*waves[i].var_a && x > -810*waves[i].var_a) { if (x==0) x = 0.1f; balls[j].y += waves[i].var_a*(-x/abs(x)*x/(waves[i].var_a*15*pow(x/abs(x)-2, 4))+1) * cos(5*x/(waves[i].var_a*sqrt(-x+20*waves[i].var_a))); } } } } } class Ball { float x, y; Ball(){ y = pos; } } class wave { boolean var_move; float var_a, var_origin, var_marker; wave() { var_move=false; } }