xxxxxxxxxx
function setup() {
createCanvas(windowWidth, windowHeight);
background(220);
}
const connectedCubeArray = [];
function draw() {}
function keyPressed() {
const cube = connectedCubeArray[0];
if (keyCode === 32 /* Space Key */ ) {
const targetMat = P5tId.SimpleTileMat;
// const targetMat = P5tId.ColorTileMat; // can apply for ColorTileMat
const columnRand = Math.floor( Math.random() * targetMat.matrixColumns);
const rowRand = Math.floor( Math.random() * targetMat.matrixRows);
// Move to random tile.
cube?.moveTo(targetMat.getTileCenter(rowRand, columnRand), 80);
}
}
function mouseClicked() {
P5tCube.connectNewP5tCube().then(cube => {
connectedCubeArray.push(cube);
cube?.turnLightOn( 'white' );
});
}