// author: didier hilhorst // p5_version: 0068 BImage b; float xoff = 0.0; Circle cir1, cir2, cir3, cir4, cir5; void setup() { size(500, 500); noStroke(); b = loadImage("bg_elas.gif"); xoff = xoff + .01; float n = noise(xoff) * 2; // experimenting with this... cir1 = new Circle(mouseX, mouseY, 60, 60); cir1._inertia = 0.9; cir1._k = n; cir1._r = 119; cir1._g = 119; cir1._b = 119; cir2 = new Circle(mouseX, mouseY, 50, 50); cir2._inertia = 0.88; cir2._k = n; cir2._r = 153; cir2._g = 153; cir2._b = 153; cir3 = new Circle(mouseX, mouseY, 40, 40); cir3._inertia = 0.86; cir3._k = n; cir3._r = 187; cir3._g = 187; cir3._b = 187; cir4 = new Circle(mouseX, mouseY, 30, 30); // small_pink_circle (color only) cir4._inertia = 0.84; cir4._k = n; cir4._r = 255; cir4._g = 102; cir4._b = 153; cir5 = new Circle(mouseX, mouseY, 20, 20); cir5._inertia = 0.82; cir5._k = n; cir5._r = 85; cir5._g = 85; cir5._b = 85; } void loop() { background(b); cir1.elasPosition(mouseX-30, mouseY-30); cir2.elasPosition(mouseX-25, mouseY-25); cir3.elasPosition(mouseX-20, mouseY-20); cir4.elasPosition(mouseX-15, mouseY-15); cir5.elasPosition(mouseX-10, mouseY-10); } class Circle { float _x, _y, _width, _height, _inertia, _k, vx, vy, _r, _g, _b; Circle(float x, float y, float w, float h) { _x = x; _y = y; _width = w; _height = h; _inertia = 0.92; _k = 0.1; _r = 85; _g = 85; _b = 85; fill(_r, _g, _b); render(); } void render() { smooth(); ellipse(_x, _y, _width, _height); fill(_r, _g, _b); } void setPosition(float x, float y) { _x = x; _y = y; render(); } void elasPosition(float x, float y) { float tx = _x; float ty = _y; float dx = x - tx; float dy = y - ty; float ax = dx*_k; float ay = dy*_k; vx = vx + ax; vy = vy + ay; vx = vx * _inertia; vy = vy * _inertia; tx = tx + vx; ty = ty + vy; setPosition(tx, ty); } }