Skip to content
Snippets Groups Projects
Commit fd036995 authored by Will Billingsley's avatar Will Billingsley
Browse files

Solution to the first part of tut2

parent b46420ea
No related branches found
No related tags found
No related merge requests found
......@@ -3,8 +3,7 @@
<title>Conway's Game of Life</title>
<h1>Conway's Game of Life</h1>
<div id="game" style="font-family: monospace; cursor: pointer;">
</div>
<svg xmlns="http://www.w3.org/2000/svg" id="game" width="640" height="400"></svg>
<div>
<button onclick="javascript: { gameOfLife.stepGame(); render(); }">Step</button>
</div>
......@@ -17,4 +16,15 @@
render()
</script>
<style>
.cell {
fill: #ddd;
stroke: #444;
cursor: pointer;
}
.cell.alive {
fill: #88f;
}
</style>
</html>
\ No newline at end of file
......@@ -2,21 +2,29 @@
function render() {
let xmlns = "http://www.w3.org/2000/svg"
let cellSize = 20
let gameDiv = document.getElementById("game")
gameDiv.innerHTML = ""
for (let y = 0; y < gameOfLife.getH(); y++) {
let row = document.createElement("div")
let row = document.createElementNS(xmlns, "g")
row.setAttribute("class", "gamerow")
gameDiv.appendChild(row)
for (let x = 0; x < gameOfLife.getW(); x++) {
let t = document.createElement("span")
let t = document.createElementNS(xmlns, "rect")
t.setAttribute("x", x * cellSize)
t.setAttribute("y", y * cellSize)
t.setAttribute("width", cellSize)
t.setAttribute("height", cellSize)
t.classList.add("cell")
if (gameOfLife.isAlive(x, y)) {
t.innerHTML = "#"
} else {
t.innerHTML = "."
t.classList.add("alive")
}
let handler = function(evt) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment