40 lines
927 B
JavaScript
40 lines
927 B
JavaScript
import Ant from './Ant.js';
|
|
// Supposons que vous avez une fonction render pour l'affichage
|
|
// Par exemple : function render(grid) { ... }
|
|
|
|
let ant;
|
|
let grid;
|
|
const gridSize = 50;
|
|
const intervalId;
|
|
|
|
function setup() {
|
|
grid = createGrid(gridSize);
|
|
ant = new Ant(grid, Math.floor(gridSize / 2), Math.floor(gridSize / 2));
|
|
document.getElementById('resetBtn').addEventListener('click', resetSimulation);
|
|
startSimulation();
|
|
}
|
|
|
|
function createGrid(size) {
|
|
const newGrid = [];
|
|
for (let i = 0; i < size; i++) {
|
|
newGrid[i] = new Array(size).fill(0);
|
|
}
|
|
return newGrid;
|
|
}
|
|
|
|
function startSimulation() {
|
|
intervalId = setInterval(() => {
|
|
ant.step();
|
|
render(grid); // Appelez votre fonction de rendu ici
|
|
}, 100);
|
|
}
|
|
|
|
function resetSimulation() {
|
|
clearInterval(intervalId);
|
|
ant.reset();
|
|
render(grid);
|
|
startSimulation();
|
|
}
|
|
|
|
// Assurez-vous d'appeler setup() au chargement de la page
|
|
window.onload = setup; |