Advertisement
KatyasGameOfDeath

Untitled

Oct 15th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Katya's Game Of Death</title>
  5. <meta charset="UTF-8">
  6. <meta name ="author" content="TheWonderKat">
  7. </head>
  8.  
  9. <script="text/javascript">
  10.  
  11. <!--someone show me how to draw a grid!!!!!!!!!!!!!!-->
  12.  
  13.  
  14.  
  15.  
  16.  
  17. function create2DArray (colms,rows) {
  18.  
  19. let arr = new Array(colms);
  20. for (let i=0;i<arr.length>;i++); {
  21. arr[i]=new Array(rows);
  22.  
  23. }
  24.  
  25. return create2DArray;
  26. }
  27.  
  28. let grid;
  29. let colms =;
  30. let rows =;
  31. let resolution =;
  32.  
  33. function setup() {
  34. createCanvas(400,400);
  35. grid = create2DArray (10,10);
  36. for(let i=0; i< coms; i++) {
  37. for(let j= 0;j<rows; j++) {
  38. grid[i][j] = math.random(2);
  39. }
  40. }
  41. }
  42. }
  43.  
  44.  
  45. <!--looking through all columns and rows for drawing-->
  46.  
  47. function draw() {
  48. //background(0);
  49.  
  50. //not counting the outer edges
  51. if(i== 0|| i==colms -1|| j==0\\j==)
  52. next[i][j] = grid[i][j];
  53.  
  54. let state grid=grid[i][j];
  55. //stae and grid are the same color so something is not working
  56. //rule time
  57. if(state ==0 && neighbors ==3) {
  58. next[i][j] = 1;
  59. } else if(state ==0 && neighbors <23) {
  60. next[i][j] = 0;
  61. }else {
  62.  
  63. for(let i=0; i< coms; i++) {
  64. for(let j= 0;j<rows; j++) {
  65. let x =i *resolution;
  66. let y =j *resolution;
  67. if(grid[i][j] ==1) {
  68. fill(300);
  69. stroke(0);
  70. rect(x,y, resolution -1,
  71.  
  72. }
  73.  
  74. //let nexGeneration = create2DArray (colms,rows);
  75. //count live neighbors
  76. //how to make internal loop
  77.  
  78. let sum = 0;
  79. sum += grid[i-1][j]
  80. sum += grid[i-1][j]
  81. sum += grid[i-1][j]
  82. sum += grid[i-1][j]
  83. sum += grid[i-1][j]
  84. sum += grid[i-1][j]
  85. sum += grid[i-1][j]
  86. sum += grid[i-1][j]
  87. //change the rules for neighbors
  88.  
  89. }
  90.  
  91. function countNeighbors(grid,x,y) {
  92. for(let i= -1;1<2;i++) {
  93. for(let j=-1; j<2; i++) {
  94. sum += grid[i][j];
  95. }
  96. }
  97. if(i=x,j=x);
  98. return(sum);
  99. else//idk what to do here
  100.  
  101. return sum;
  102.  
  103. grid = next;
  104. </script>
  105.  
  106. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement