Advertisement
Lusien_Lashans

Life

May 24th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>ConWay's Game of Life</title>
  5. </head>
  6. <body>
  7.  
  8. <canvas id="myCanvas" width="200" height="200" style="border:1px solid #c3c3c3;">
  9.  
  10. </canvas>
  11.  
  12. <script>
  13. var canvas = document.getElementById("myCanvas");
  14. var ctx = canvas.getContext("2d");
  15. ctx.fillStyle = "#FF0000";
  16. fieldSize = 20;
  17. cellSize = 30;
  18. ctx.fillRect(0,0,fieldSize,fieldSize);
  19. currentField = new Array(fieldSize);
  20. for(i=0;i<currentField.length; i++){
  21.     currentField[i] = new Array(fieldSize);
  22. }
  23. for(i=0; i<currentField.length; i++){
  24.     for(j=0;j<currentField.length;j++){
  25.         currentField[i][j] = Math.floor(0.5 + Math.random());
  26.         if(currentField[i][j] == 0){
  27.             ctx.fillStyle = '#FFFFFF';
  28.         }
  29.         else{
  30.             ctx.fillStyle = '#FF0000';
  31.         }
  32.         ctx.fillRect(cellSize*i, cellSize*j, cellSize, cellSize);
  33.     }
  34. }
  35. </script>
  36.  
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement