Commit e4b19addcb569ca8bc20b1e5ca5eed3b3c2e5797

Authored by Georg Hopp
1 parent edd1185c

really remove game of life from javascript

... ... @@ -19,7 +19,6 @@
19 19 </head>
20 20 <body>
21 21 <canvas id="view3d"></canvas>
22   - <canvas id="game-of-life-canvas"></canvas>
23 22 <script src="./bootstrap.js"></script>
24 23 </body>
25 24 </html>
... ...
1   -import { Universe, Cell, View3d, Color } from "wasm-game-of-life";
  1 +import { View3d } from "wasm-game-of-life";
2 2 import { memory } from "wasm-game-of-life/wasm_game_of_life_bg";
3 3
4 4 // 3D canvas stuff
5   -const view3d = View3d.new(151, 151);
  5 +const view3d = View3d.new(300, 300);
6 6
7 7 const view3d_canvas = document.getElementById("view3d");
8 8 view3d_canvas.width = view3d.width();
... ... @@ -28,85 +28,7 @@ const drawView3d = () => {
28 28 view3d_ctx.putImageData(view3d_image, 0, 0);
29 29 }
30 30
31   -// game of life stuff
32   -const CELL_SIZE = 5; // px
33   -const GRID_COLOR = "#CCCCCC";
34   -const DEAD_COLOR = "#FFFFFF";
35   -const ALIVE_COLOR = "#000000";
36   -
37   -const universe = Universe.new();
38   -const width = universe.width();
39   -const height = universe.height();
40   -
41   -const canvas = document.getElementById("game-of-life-canvas");
42   -canvas.height = (CELL_SIZE + 1) * height + 1;
43   -canvas.width = (CELL_SIZE + 1) * width + 1;
44   -
45   -const ctx = canvas.getContext('2d');
46   -
47   -const renderLoop = () => {
48   - universe.tick();
49   -
50   - drawGrid();
51   - drawCells();
52   -
53   - requestAnimationFrame(renderLoop);
54   -};
55   -
56   -const drawGrid = () => {
57   - ctx.beginPath();
58   - ctx.strokeStyle = GRID_COLOR;
59   -
60   - // vertical lines.
61   - for (let i = 0; i <= width; i++) {
62   - ctx.moveTo(i * (CELL_SIZE + 1) + 1, 0);
63   - ctx.lineTo(i * (CELL_SIZE + 1) + 1, (CELL_SIZE + 1) * height + 1);
64   - }
65   -
66   - // horizontal lines.
67   - for (let j = 0; j <= height; j++) {
68   - ctx.moveTo( 0, j * (CELL_SIZE + 1) + 1);
69   - ctx.lineTo((CELL_SIZE + 1) * width + 1, j * (CELL_SIZE + 1) + 1);
70   - }
71   -
72   - ctx.stroke();
73   -};
74   -
75   -const getIndex = (row, col) => {
76   - return row * width + col;
77   -};
78   -
79   -const drawCells = () => {
80   - const cellsPtr = universe.cells()
81   - const cells = new Uint8Array(memory.buffer, cellsPtr, width * height);
82   -
83   - ctx.beginPath();
84   -
85   - for (let row = 0; row < height; row++) {
86   - for (let col = 0; col < height; col++) {
87   - const idx = getIndex(row, col);
88   -
89   - ctx.fillStyle = cells[idx] === Cell.Dead
90   - ? DEAD_COLOR
91   - : ALIVE_COLOR;
92   -
93   - ctx.fillRect(
94   - col * (CELL_SIZE + 1) + 1,
95   - row * (CELL_SIZE + 1) + 1,
96   - CELL_SIZE,
97   - CELL_SIZE
98   - );
99   - }
100   - }
101   -
102   - ctx.stroke();
103   -};
104   -
105 31 // start everything ...
106   -//drawGrid();
107   -//drawCells();
108   -//requestAnimationFrame(renderLoop);
109   -
110 32 view3d.update();
111 33 drawView3d();
112 34 requestAnimationFrame(view3d_renderLoop);
... ...
Please register or login to post a comment