xxxxxxxxxx
48
const blocks = {
INVERTED_DAYLIGHT_SENSOR: null,
REDSTONE_LAMP: null
};
const s = 60;
let w, h;
let g;
function preload() {
blocks.INVERTED_DAYLIGHT_SENSOR = loadImage("inverted daylight sensor.JPG");
blocks.REDSTONE_LAMP = loadImage("redstone lamp.JPG");
}
function setup() {
createCanvas(960, 540);
w = width / s;
h = height / s;
g = create3DArray(w, h);
g[2][2][0] = blocks.INVERTED_DAYLIGHT_SENSOR;
g[3][2][0] = blocks.REDSTONE_LAMP;
}
function draw() {
background(255);
for (let i = 0; i < w; i++) {
for (let j = 0; j < h; j++) {
const x = i * s;
const y = j * s;
stroke(0, 10);
noFill();
rect(x, y, s, s);
if (g[i][j][0]) {
image(g[i][j][0], x, y, s, s);
}
}
}
}
function create3DArray(w, h) {
const arr = new Array(w);
for (let i = 0; i < w; i++) {
arr[i] = new Array(h);
for (let j = 0; j < h; j++) {
arr[i][j] = [];
}
}
return arr;
}