マウスを画像上で動かしてマトリックスを隠したり表示したりします。マウスから各円までの距離を測定し、サイズを比例的に設定します。
dist distance 2D
Math Interaction
View Source Code
/*
* @name Distance 2D
* @arialabel The user’s mouse creates a gradient of circles that decrease in size the closer they are to the mouse as it moves across the screen
* @description Move the mouse across the image to obscure
* and reveal the matrix. Measures the distance from the mouse
* to each circle and sets the size proportionally.
*/
let max_distance;
function setup() {
// createCanvas(710, 400);
createCanvas(windowWidth, windowHeight);
noStroke();
max_distance = dist(0, 0, width, height);
}
function draw() {
background(0);
for (let i = 0; i <= width; i += 20) {
for (let j = 0; j <= height; j += 20) {
let size = dist(mouseX, mouseY, i, j);
size = (size / max_distance) * 66;
ellipse(i, j, size, size);
}
}
}
License
Source code is available on GitHub p5.js website legacy.
All examples are licensed under CC BY-NC-SA 4.0.