案例:Claude 2生成的生命游戏代码     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
  <title>Game of Life</title>
5
  <style>
6
    #grid {
7
      display: flex;
8
      flex-wrap: wrap;
9
      width: 200px;
10
      height: 200px;
11
    }
12
    .cell {
13
      width: 10px;
14
      height: 10px;
15
      border: 1px solid black;
16
    }
17
    .alive {
18
      background-color: pink;
19
    }
20
  </style>
21
</head>
22
<body>
23
  <div id="grid"></div>
24
25
  <script>// 初始化网格
26
const GRID_SIZE = 20; 
27
const grid = document.getElementById('grid');
28
for (let i = 0; i < GRID_SIZE * GRID_SIZE; i++) {
29
  const cell = document.createElement('div');
30
  cell.classList.add('cell');
31
  grid.appendChild(cell);
32
}
33
34
// 设置单元格状态
35
function setCellState(x, y, alive) {
36
  const cell = grid.children[y * GRID_SIZE + x];
37
  alive ? cell.classList.add('alive') : cell.classList.remove('alive');
38
}
39
40
// 实现生命游戏规则
41
function update() {
42
  // 遍历每个单元格并应用生命游戏规则
43
  // ...
44
  
45
  // 更新单元格状态
46
  for (let x = 0; x < GRID_SIZE; x++) {
47
    for (let y = 0; y < GRID_SIZE; y++) {
48
      setCellState(x, y, newState[y][x]);