xxxxxxxxxx
33
let wordGrid;
let gridSize = 12;
let cellSize = 35;
function setup() {
// Canvas size based on grid
createCanvas(gridSize * cellSize, gridSize * cellSize + 60);
// Instantiate WordGrid object
wordGrid = new WordGrid(gridSize, cellSize);
// Text size for letters in grid
textSize(20);
textFont('Times New Roman');
}
function draw() {
background(255);
fill(0);
textAlign(CENTER, CENTER);
text("Word Search", width / 2, 30); // Title position
// Move everything down to make room for title
translate(0, 60);
wordGrid.draw(); // Draw word grid
}
function mousePressed() {
// Adjust to find correct cell based on mouse position
if (mouseY > 60 && mouseY < height && mouseX > 0 && mouseX < width) {
let col = Math.floor(mouseX / cellSize);
let row = Math.floor((mouseY - 60) / cellSize);
// Toggle color state for clicked cell
wordGrid.toggleCell(row, col);
}
}