thomas
This commit is contained in:
40
TP1/EX1/app.js
Normal file
40
TP1/EX1/app.js
Normal file
@@ -0,0 +1,40 @@
|
||||
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;
|
Reference in New Issue
Block a user