-
Notifications
You must be signed in to change notification settings - Fork 0
/
patterns.js
89 lines (81 loc) · 1.7 KB
/
patterns.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var gosper_gun = {
"x": [1, 1, 2, 2, 11, 11, 11, 12, 12, 13, 13, 14, 14, 15, 16, 16, 17, 17, 17, 18, 21, 21, 21, 22, 22, 22, 23, 23, 25, 25, 25, 25, 35, 35, 36, 36],
"y": [5, 6, 5, 6, 5, 6, 7, 4, 8, 3, 9, 3, 9, 6, 4, 8, 5, 6, 7, 6, 3, 4, 5, 3, 4, 5, 2, 6, 1, 2, 6, 7, 3, 4, 3, 4],
"universe": "cylinder",
"name": "Gosper's Gun"
};
var glider = {
"x": [2, 3, 1, 2, 3],
"y": [1, 2, 3, 3, 3],
"universe": "klein",
"name": "Glider"
}
var glider_army = {
"blueprint": [
[0,0,0,0,0],
[0,0,1,0,0],
[0,0,0,1,0],
[0,1,1,1,0],
[0,0,0,0,0]
],
"call": function(i,j,v){
if(i>=5*Math.floor(rows/5)||j>=5*Math.floor(cols/5))
return false;
return this.blueprint[i%5][j%5];
},
"grid": function(res, h, w){
r = Math.floor(h/res);
c = Math.floor(w/res);
r = 5*Math.floor(r/5);
c = 5*Math.floor(c/5);
newg = [];
for(i=0; i<r; i++){
var temp = [];
for(j=0; j<c; j++){
temp.push(this.blueprint[i%5][j%5]);
}
newg.push(temp);
}
return newg;
},
"speed": 1,
"universe": "torus",
"name": "Glide Army"
}
var empty_pattern = {
"name": "Empty"
};
var random_pattern = {
"scale": true,
"call": function(i,j,v){ return Math.random()<v; },
"universe": "mobius",
"name": "Random"
};
var full_pattern = {
"call": function(i,j,v){ return true; },
"name": "Full"
};
var patterns = {
"empty": empty_pattern,
"random": random_pattern,
"full": full_pattern,
"glider": glider,
"gosper": gosper_gun,
"glider_army": glider_army
};
// TODO: add tutorial
function capturePattern(){
arr = {
"x": [],
"y": []
};
for(i=0; i<grid.length; i++){
for(j=0; j<grid[i].length; j++){
if(grid[i][j]){
arr.x.push(j);
arr.y.push(i);
}
}
}
return arr;
}