document.addEventListener('DOMContentLoaded', () => {
const numberContainer = document.getElementById('number-container');
const totalNumbers = 660; // 14 rows of 100 numbers each
const columns = 30; // Number of columns in the grid
// Create and append numbers from 1 to 100
for (let i = 1; i <= totalNumbers; i++) {
const numberElement = document.createElement('div');
numberElement.classList.add('number');
numberElement.textContent = i;
numberContainer.appendChild(numberElement);
}
// Predefined creature patterns (e.g., 4x4 grid patterns using numbers)
const creatures = [
[
[true, false, true, false],
[false, true, false, true],
[true, false, true, false],
[false, true, false, true],
],
[
[true, true, false, false],
[true, false, false, true],
[false, true, true, false],
[false, false, true, true],
],
[
[false, false, false, true],
[false, true, true, false],
[false, true, false, false],
[true, false, false, false],
],
];
// Function to clear all active classes from numbers
function clearNumbers() {
for (let i = 0; i < totalNumbers; i++) {
numberContainer.children[i].classList.remove('active');
}
}
// Function to place a creature pattern at a random position
function placeCreature() {
clearNumbers(); // Clear previous creature
const randomCreature = creatures[Math.floor(Math.random() * creatures.length)];
const creatureRows = randomCreature.length;
const creatureCols = randomCreature[0].length;
// Calculate a random position to place the creature in the grid
const randomRow = Math.floor(Math.random() * (totalNumbers / columns - creatureRows));
const randomCol = Math.floor(Math.random() * (columns - creatureCols));
// Place the creature in the grid by adding the 'active' class
for (let row = 0; row < creatureRows; row++) {
for (let col = 0; col < creatureCols;...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.