gibney.org : Technology : Javascript : Experiments : Conway's Game of Life : conway_gui


just a logo :)

search:


See as: raw | code

terms of service | imprint

gibney.org
is powered by m1d1





conway_gui
(Entry Nr. 308, by user 1 | edit)
ConwayGUI = function() { this.step = function() { this.Conway.step(); this.StepCount++; if (this.StepCount>10) { var SecondsGone=(new Date().getTime()-this.StartTime)/1000; FPS=this.StepCount/SecondsGone; var Info=""+Math.round(FPS*10)/10; document.getElementById("Timer").innerHTML="FPS: "+Info; this.StepCount=0; this.StartTime=new Date().getTime(); } if (this.run) window.setTimeout("window.CG.step()",10); } this.start = function() { this.StartTime=new Date().getTime(); this.StepCount=0; this.run=true; this.step(); } this.stop = function() { this.run=false; } this.randomize = function() { this.Conway.randomize(); } this.clear = function() { this.Conway.clear(); } this.on_click = function(e) { var x=Math.floor(this.Conway.Width/2); var y=Math.floor(this.Conway.Height/2);; this.Conway.Cells[0][y][x]=1; this.Conway.Cells[0][y][x+1]=1; this.Conway.Cells[0][y][x+2]=1; this.Conway.Cells[1][y][x]=1; this.Conway.Cells[1][y][x+1]=1; this.Conway.Cells[1][y][x+2]=1; } this.ini = function() { this.Canvas = document.getElementById('conway'); this.Width = Math.floor( (this.Canvas.width - 1) / 4 ); this.Height= Math.floor( (this.Canvas.height - 1) / 4 ); this.ctx = this.Canvas.getContext('2d'); this.CellWidth = Math.floor(this.Canvas.width / this.Width); this.CellHeight = Math.floor(this.Canvas.height / this.Height); // clear the entire Canvas this.ctx.fillStyle = 'white'; this.ctx.fillRect(10, 10, 12,12); this.ctx.fillRect(0, 0, this.Width * this.CellWidth, this.Height * this.CellHeight); // draw grid lines this.ctx.fillStyle = 'rgb(220,220,220)'; for (var i = 0; i <= this.Height; i++) this.ctx.fillRect(0, i * this.CellHeight, this.Width * this.CellWidth, 1); for (var i = 0; i <= this.Width; i++) this.ctx.fillRect(i * this.CellWidth, 0, 1, this.Height * this.CellHeight); var me=this; this.Canvas.onclick=function(e) {me.on_click(e)}; } this.drawCell = function(x,y,alive) { if (alive) this.ctx.fillStyle='black'; else this.ctx.fillStyle='white'; this.ctx.fillRect(x*this.CellWidth+1,y*this.CellHeight+1,this.CellWidth-1,this.CellHeight-1); } this.ini(); this.Conway = new Conway(this.Width, this.Height); }
Create a new entry at this position