Generative Design with p5.js / Sketch P_2_1_2_04 を試しながらアレンジ。
元ネタ:https://editor.p5js.org/generative-design/sketches/P_2_1_2_04
ロジックのポイント
各頂点ごとにカーソル位置に連動した移動量をランダムに生成し、もととなる正方形から変形させるように四角形を描画している。
var shiftX1 = mouseX / 20 * random(-1, 1);
var shiftY1 = mouseY / 20 * random(-1, 1);
var shiftX2 = mouseX / 20 * random(-1, 1);
var shiftY2 = mouseY / 20 * random(-1, 1);
var shiftX3 = mouseX / 20 * random(-1, 1);
var shiftY3 = mouseY / 20 * random(-1, 1);
var shiftX4 = mouseX / 20 * random(-1, 1);
var shiftY4 = mouseY / 20 * random(-1, 1);
push();
translate(posX, posY);
beginShape();
vertex(shiftX1, shiftY1);
vertex(rectSize + shiftX2, shiftY2);
vertex(rectSize + shiftX3, rectSize + shiftY3);
vertex(shiftX4, rectSize + shiftY4);
endShape();
pop();