# HG changeset patch # User Eugen Sawin # Date 1325802567 -3600 # Node ID cb8897d7f508521531aa20be1401dc3dfe2ce099 # Parent a76b2fb0f21fb96285c311200cd35738dd34c0a5 Fixed minor bug. diff -r a76b2fb0f21f -r cb8897d7f508 dark.css --- a/dark.css Thu Jan 05 23:04:57 2012 +0100 +++ b/dark.css Thu Jan 05 23:29:27 2012 +0100 @@ -208,9 +208,13 @@ left: 25px; height: 100px; width: 670px; +} + +#gameoflife { + background: black; } -#sim { +#sim { border-style: none; position: relative; margin: 0; diff -r a76b2fb0f21f -r cb8897d7f508 factory/v2012/dark.css --- a/factory/v2012/dark.css Thu Jan 05 23:04:57 2012 +0100 +++ b/factory/v2012/dark.css Thu Jan 05 23:29:27 2012 +0100 @@ -208,9 +208,13 @@ left: 25px; height: 100px; width: 670px; +} + +#gameoflife { + background: black; } -#sim { +#sim { border-style: none; position: relative; margin: 0; diff -r a76b2fb0f21f -r cb8897d7f508 factory/v2012/script.js --- a/factory/v2012/script.js Thu Jan 05 23:04:57 2012 +0100 +++ b/factory/v2012/script.js Thu Jan 05 23:29:27 2012 +0100 @@ -4,7 +4,8 @@ var gameoflife; $(document).ready(function() { - simulation = new Simulation(document.getElementById("sim"), 670, 50, 4); + simulation = new Simulation(document.getElementById("sim"), + 670, 50, 4, green, background); var image = new Image(); image.onload = init_logo; image.src = "images/logobase.png"; @@ -248,7 +249,13 @@ context.closePath(); context.strokeStyle = colour1a.str(); context.stroke(); - + var colour1e = new Colour(0, 0, 0, 0.05); + context.beginPath(); + context.moveTo(70, h - 1); + context.lineTo(w - 71, h - 1); + context.closePath(); + context.strokeStyle = colour1e.str(); + context.stroke(); var colour1b = new Colour(0, 0, 0, 0.05); context.beginPath(); context.moveTo(50, h - 1); @@ -256,7 +263,13 @@ context.closePath(); context.strokeStyle = colour1b.str(); context.stroke(); - + var colour1c = new Colour(0, 0, 0, 0.05); + context.beginPath(); + context.moveTo(25, h - 1); + context.lineTo(w - 26, h - 1); + context.closePath(); + context.strokeStyle = colour1c.str(); + context.stroke(); var colour1d = new Colour(0, 0, 0, 0.05); context.beginPath(); context.moveTo(10, h - 1); @@ -286,7 +299,8 @@ function init_gameoflife() { var canvas = document.getElementById("gameoflife"); if (canvas) { - gameoflife = new Simulation(canvas, 670, 670, 8); + gameoflife = new Simulation(canvas, 670, 670, 8, + green, black); $("#gameoflife").mousemove(function(event) { gameoflife.mouse_moved(mouse_pos(event, "#gameoflife")); }); @@ -549,8 +563,8 @@ } function Grid(width, height, cell_size) { - this.width = parseInt(width / cell_size); - this.height = parseInt(height / cell_size); + this.width = parseInt(width / cell_size + 0.5); + this.height = parseInt(height / cell_size + 0.5); this.canvas_width = width; this.canvas_height = height; this.cell_size = cell_size; @@ -601,7 +615,7 @@ if (this.y + 1 < this.grid.height) { this._neighbours.push(this.grid.cell(this.x-1, this.y+1)); } - } + } if (this.x + 1 < this.grid.width) { this._neighbours.push(this.grid.cell(this.x+1, this.y)); if (this.y + 1 < this.grid.height) { @@ -623,7 +637,7 @@ return d; } -function Simulation(canvas, w, h, cell_size) { +function Simulation(canvas, w, h, cell_size, life_colour, dead_colour) { this.last_update = 0; this.last_draw = 0; this.last_mouse_moved = 0; @@ -635,6 +649,8 @@ this.pos_queue = new Array(); this.cell_queue = new Array(); this.cell_size = cell_size; + this.life_colour = life_colour; + this.dead_colour = dead_colour; this.grid = new Grid(this.canvas.width, this.canvas.height, cell_size); draw_sim_lines(); } @@ -642,7 +658,8 @@ var now = $.now(); if (this.redraw.length) { var cell = this.redraw.pop(); - this.context.fillStyle = cell.value == 1 ? green.str() : background.str(); + this.context.fillStyle = cell.value == 1 ? + this.life_colour.str() : this.dead_colour.str(); this.context.fillRect(cell.canvas_x, cell.canvas_y, this.grid.cell_size, this.grid.cell_size); this.last_draw = $.now(); diff -r a76b2fb0f21f -r cb8897d7f508 script.js --- a/script.js Thu Jan 05 23:04:57 2012 +0100 +++ b/script.js Thu Jan 05 23:29:27 2012 +0100 @@ -4,7 +4,8 @@ var gameoflife; $(document).ready(function() { - simulation = new Simulation(document.getElementById("sim"), 670, 50, 4); + simulation = new Simulation(document.getElementById("sim"), + 670, 50, 4, green, background); var image = new Image(); image.onload = init_logo; image.src = "images/logobase.png"; @@ -248,7 +249,13 @@ context.closePath(); context.strokeStyle = colour1a.str(); context.stroke(); - + var colour1e = new Colour(0, 0, 0, 0.05); + context.beginPath(); + context.moveTo(70, h - 1); + context.lineTo(w - 71, h - 1); + context.closePath(); + context.strokeStyle = colour1e.str(); + context.stroke(); var colour1b = new Colour(0, 0, 0, 0.05); context.beginPath(); context.moveTo(50, h - 1); @@ -256,7 +263,13 @@ context.closePath(); context.strokeStyle = colour1b.str(); context.stroke(); - + var colour1c = new Colour(0, 0, 0, 0.05); + context.beginPath(); + context.moveTo(25, h - 1); + context.lineTo(w - 26, h - 1); + context.closePath(); + context.strokeStyle = colour1c.str(); + context.stroke(); var colour1d = new Colour(0, 0, 0, 0.05); context.beginPath(); context.moveTo(10, h - 1); @@ -286,7 +299,8 @@ function init_gameoflife() { var canvas = document.getElementById("gameoflife"); if (canvas) { - gameoflife = new Simulation(canvas, 670, 670, 8); + gameoflife = new Simulation(canvas, 670, 670, 8, + green, black); $("#gameoflife").mousemove(function(event) { gameoflife.mouse_moved(mouse_pos(event, "#gameoflife")); }); @@ -549,8 +563,8 @@ } function Grid(width, height, cell_size) { - this.width = parseInt(width / cell_size); - this.height = parseInt(height / cell_size); + this.width = parseInt(width / cell_size + 0.5); + this.height = parseInt(height / cell_size + 0.5); this.canvas_width = width; this.canvas_height = height; this.cell_size = cell_size; @@ -601,6 +615,8 @@ if (this.y + 1 < this.grid.height) { this._neighbours.push(this.grid.cell(this.x-1, this.y+1)); } + } else { + this._neighbours.push(this.grid.cell(this.grid.width-1, this.y)); } if (this.x + 1 < this.grid.width) { this._neighbours.push(this.grid.cell(this.x+1, this.y)); @@ -611,6 +627,8 @@ if (this.y > 0) { this._neighbours.push(this.grid.cell(this.x+1, this.y-1)); } + } else { + this._neighbours.push(this.grid.cell(0, this.y)); } return this._neighbours; } @@ -623,7 +641,7 @@ return d; } -function Simulation(canvas, w, h, cell_size) { +function Simulation(canvas, w, h, cell_size, life_colour, dead_colour) { this.last_update = 0; this.last_draw = 0; this.last_mouse_moved = 0; @@ -635,6 +653,8 @@ this.pos_queue = new Array(); this.cell_queue = new Array(); this.cell_size = cell_size; + this.life_colour = life_colour; + this.dead_colour = dead_colour; this.grid = new Grid(this.canvas.width, this.canvas.height, cell_size); draw_sim_lines(); } @@ -642,7 +662,8 @@ var now = $.now(); if (this.redraw.length) { var cell = this.redraw.pop(); - this.context.fillStyle = cell.value == 1 ? green.str() : background.str(); + this.context.fillStyle = cell.value == 1 ? + this.life_colour.str() : this.dead_colour.str(); this.context.fillRect(cell.canvas_x, cell.canvas_y, this.grid.cell_size, this.grid.cell_size); this.last_draw = $.now();