Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>ConWay's Game of Life</title>
- </head>
- <body>
- <canvas id="myCanvas" width="200" height="200" style="border:1px solid #c3c3c3;">
- </canvas>
- <script>
- var canvas = document.getElementById("myCanvas");
- var ctx = canvas.getContext("2d");
- ctx.fillStyle = "#FF0000";
- fieldSize = 20;
- cellSize = 30;
- ctx.fillRect(0,0,fieldSize,fieldSize);
- currentField = new Array(fieldSize);
- for(i=0;i<currentField.length; i++){
- currentField[i] = new Array(fieldSize);
- }
- for(i=0; i<currentField.length; i++){
- for(j=0;j<currentField.length;j++){
- currentField[i][j] = Math.floor(0.5 + Math.random());
- if(currentField[i][j] == 0){
- ctx.fillStyle = '#FFFFFF';
- }
- else{
- ctx.fillStyle = '#FF0000';
- }
- ctx.fillRect(cellSize*i, cellSize*j, cellSize, cellSize);
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement