xxxxxxxxxx
94
var shell = []; // shell radom
var shellImg = []; // shell back imgs
let shellSize = 80; // size of shell
let printPos; // print position
// let shellFront[];
// let shellBack[];
function preload() {
for (var i = 0; i < 8; i++) {
shellImg[i] = loadImage("assets/shell-" + i + ".jpg"); // load shell imgs
}
font = loadFont('assets/canela-thin.ttf');
}
function setup() {
createCanvas(600, 600);
// get random shell img number
for (var i = 0; i < 9; i++) {
shell[i] = int(random(0, 8));
}
}
function draw() {
background(0);
textSize(64);
fill(0, 102, 153);
textFont(font);
textAlign(CENTER);
// DRAW LEFT SHELLS
for (let i = 0; i < 4; i++) {
// left column
image(shellImg[shell[i]],
width / 4,
i * (height / 6) + 100,
shellSize,
shellSize);
// determine whether shell is up or down
if (shell[i] % 2) {
printpos = "I"; // I = face up
} else {
printpos = "II"; // II = face down
}
// print shell text
text(printpos,
shellSize,
i * (height / 6) + 165);
}
// DRAW RIGHT SHELLS
for (let i = 4; i < 8; i++) {
// right column
image(shellImg[shell[i]],
width / 4 * 3 - shellSize,
(i-4) * (height / 6) + 100,
shellSize,
shellSize);
// determine whether shell is up or down
if (shell[i] % 2) {
printpos = "I"; // I = face up
} else {
printpos = "II"; // II = face down
}
// print shell text
text(printpos,
width - shellSize ,
(i-4) * (height / 6) + 165);
}
}
function mousePressed() {
// get new shells onPress
for (var i = 0; i < 9; i++) {
shell[i] = int(random(0, 8));
}
}