1
- import { memory } from ' game-of-life/game_of_life_bg' ;
1
+ import { memory } from " game-of-life/game_of_life_bg" ;
2
2
import { Universe , Cell } from "game-of-life" ;
3
3
4
4
// const pre = document.getElementById("game-of-life-canvas");
@@ -7,7 +7,7 @@ import { Universe, Cell } from "game-of-life";
7
7
// const renderLoop = () => {
8
8
// pre.textContent = universe.render();
9
9
// universe.tick();
10
-
10
+
11
11
// requestAnimationFrame(renderLoop);
12
12
// };
13
13
@@ -29,50 +29,56 @@ const canvas = document.getElementById("game-of-life-canvas");
29
29
canvas . height = ( CELL_SIZE + 1 ) * height + 1 ;
30
30
canvas . width = ( CELL_SIZE + 1 ) * width + 1 ;
31
31
32
- const ctx = canvas . getContext ( '2d' ) ;
32
+ const ctx = canvas . getContext ( "2d" ) ;
33
33
34
34
const renderLoop = ( ) => {
35
- universe . tick ( ) ;
36
- drawGrid ( ) ;
37
- drawCells ( ) ;
38
- requestAnimationFrame ( renderLoop ) ;
39
- }
35
+ debugger ;
36
+ universe . tick ( ) ;
37
+ drawGrid ( ) ;
38
+ drawCells ( ) ;
39
+ requestAnimationFrame ( renderLoop ) ;
40
+ } ;
40
41
41
42
const drawGrid = ( ) => {
42
- ctx . beginPath ( ) ;
43
- ctx . strokeStyle = GRID_COLOR ;
43
+ ctx . beginPath ( ) ;
44
+ ctx . strokeStyle = GRID_COLOR ;
44
45
45
- // Vertical lines
46
- for ( let i = 0 ; i <= width ; i ++ ) {
46
+ // Vertical lines
47
+ for ( let i = 0 ; i <= width ; i ++ ) {
47
48
ctx . moveTo ( i * ( CELL_SIZE + 1 ) + 1 , 0 ) ;
48
49
ctx . lineTo ( i * ( CELL_SIZE + 1 ) + 1 , ( CELL_SIZE + 1 ) * height + 1 ) ;
49
- }
50
+ }
50
51
51
- // Horizontal lines
52
- for ( let j = 0 ; j <= height ; j ++ ) {
53
- ctx . moveTo ( 0 , j * ( CELL_SIZE + 1 ) + 1 ) ;
54
- ctx . lineTo ( ( CELL_SIZE + 1 ) * width + 1 , j * ( CELL_SIZE + 1 ) + 1 ) ;
55
- }
56
- }
52
+ // Horizontal lines
53
+ for ( let j = 0 ; j <= height ; j ++ ) {
54
+ ctx . moveTo ( 0 , j * ( CELL_SIZE + 1 ) + 1 ) ;
55
+ ctx . lineTo ( ( CELL_SIZE + 1 ) * width + 1 , j * ( CELL_SIZE + 1 ) + 1 ) ;
56
+ }
57
+ } ;
57
58
58
59
const getIndex = ( row , column ) => {
59
- return row * width + column ;
60
- }
60
+ return row * width + column ;
61
+ } ;
61
62
62
63
const drawCells = ( ) => {
63
- const cellsPtr = universe . cells ( ) ;
64
- const cells = new Uint8Array ( memory . buffer , cellsPtr , width * height ) ;
65
- ctx . beginPath ( ) ;
66
- for ( let row = 0 ; row < height ; row ++ ) {
67
- for ( let col = 0 ; col < width ; col ++ ) {
68
- const idx = getIndex ( row , col ) ;
69
- ctx . fillStyle = cells [ idx ] === Cell . Dead ? DEAD_COLOR : ALIVE_COLOR ;
70
- ctx . fillRect ( col * ( CELL_SIZE + 1 ) + 1 , row * ( CELL_SIZE + 1 ) + 1 , CELL_SIZE , CELL_SIZE ) ;
71
- }
64
+ const cellsPtr = universe . cells ( ) ;
65
+ const cells = new Uint8Array ( memory . buffer , cellsPtr , width * height ) ;
66
+ ctx . beginPath ( ) ;
67
+ for ( let row = 0 ; row < height ; row ++ ) {
68
+ for ( let col = 0 ; col < width ; col ++ ) {
69
+ const idx = getIndex ( row , col ) ;
70
+ ctx . fillStyle = cells [ idx ] === Cell . Dead ? DEAD_COLOR : ALIVE_COLOR ;
71
+ ctx . fillRect (
72
+ col * ( CELL_SIZE + 1 ) + 1 ,
73
+ row * ( CELL_SIZE + 1 ) + 1 ,
74
+ CELL_SIZE ,
75
+ CELL_SIZE
76
+ ) ;
72
77
}
73
- ctx . stroke ( ) ;
74
- }
78
+ }
79
+ ctx . stroke ( ) ;
80
+ } ;
75
81
76
82
drawGrid ( ) ;
77
83
drawCells ( ) ;
78
- requestAnimationFrame ( renderLoop ) ;
84
+ requestAnimationFrame ( renderLoop ) ;
0 commit comments