====== Toile mobile ====== Solution du TD [[nsi:tds:animation:toile_mobile|Toile mobile]] final int N = 100; final float d = 10; final float k = 0.01; final float Rmax = 50; final float mu = 0.9999; Node[] nodes = new Node[N]; void setup() { size(800, 600); fill(255); stroke(255); for (int i=0; i height) { y = 2*height - y; vy = -vy; } else if (y< 0) { y = -y; vy = - vy; } if (x > width) { x = 2*width - x; vx = -vx; } else if (x< 0) { x = -x; vx = - vx; } } void acceleration(Node n) { // modifie vx et vy selon les particules proches float dist2 = (x-n.x)*(x-n.x) + (y - n.y)*(y - n.y); if (dist2 > Rmax*Rmax) { return; } float dvx = (n.x - x) * k; float dvy = (n.y - y) * k; vx += dvx; vy += dvy; n.vx -= dvx; n.vy -= dvy; } void drawLine(Node n) { float dist2 = (x-n.x)*(x-n.x) + (y - n.y)*(y - n.y); if (dist2 < Rmax*Rmax) { line(x, y, n.x, n.y); } } void display() { circle(x, y, d); } }