-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
66 lines (48 loc) · 1.15 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
let width = 1000
let height = 800
let s = 10
let w = width /s
let h = height / s
let life = []
function setup() {
let c = createCanvas(width, height);
frameRate(10);
for(let i = 0 ; i < w ; i++){
let f = []
for(let j = 0 ; j < h ; j++){
n = random(0 , 100)
if(n < 8){
f.push(new cell(i , j , s , w , h , true));
}
else{
f.push(new cell(i , j , s , w , h , false));
}
}
life.push(f);
}
}
function draw() {
background(0);
for(let i = 0 ; i < w ; i++){
for(let j = 0 ; j < h ; j++){
life[i][j].make();
life[i][j].add_neibour(life);
}
}
for(let i = 0 ; i < w ; i++){
for(let j = 0 ; j < h ; j++){
if(life[i][j].Alive){
life[i][j].stay = true;
}
else{
life[i][j].stay = false;
}
}
}
}
function keyPressed() {
if (key === 's') {
saveGif('GameofLife2.gif', 10);
// saveGif('GameofLife.gif', 5);
}
}