xxxxxxxxxx
52
/*
----- Coding Tutorial by Patt Vira -----
Name: Persistence of Vision Effect
Video Tutorial: https://youtu.be/qO6A8iZZM04
Connect with Patt: @pattvira
https://www.pattvira.com/
----------------------------------------
*/
let cols; let rows; let size = 5;
let grid = [];
let b;
function setup() {
createCanvas(400, 400);
cols = width/size;
rows = height/size;
for (let i=0; i<cols; i++) {
grid[i] = [];
for (let j=0; j<rows; j++) {
grid[i][j] = floor(random(2));
}
}
b = new Block();
}
function draw() {
background(220);
let x = floor(mouseX / size);
let y = floor(mouseY / size);
for (let i=0; i<cols; i++) {
for (let j=0; j<rows; j++) {
if (grid[i][j] == 0) {
fill(255);
} else {
fill(0);
}
noStroke();
rect(i*size, j*size, size, size);
}
}
b.display(grid);
}