-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgliderfinder.js
More file actions
85 lines (77 loc) · 1.34 KB
/
Copy pathgliderfinder.js
File metadata and controls
85 lines (77 loc) · 1.34 KB
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
var r=8;
var period=4;
var oldTempCells=[];
function shift(){
var sx=-1;
var sy=-1;
var tempCells=[];
for(var x=0;x<r;x++){
tempCells[x]=[];
for(var y=0;y<r;y++){
tempCells[x][y]=getCell(cells,x-sx,y-sy);
}
}
var tempCellsBig=[];
for(var x=0;x<r+period*2;x++){
tempCellsBig[x]=[];
for(var y=0;y<r+period*2;y++){
tempCellsBig[x][y]=getCell(cells,x-sx-period,y-sy-period);
}
}
clearCells();
for(var x=0;x<r+period*2;x++){
for(var y=0;y<r+period*2;y++){
//if(cells[x][y]>0){
addCell(x-period,y-period,tempCellsBig[x][y]);
//}
}
}
oldTempCells=tempCells;
}
for(var x=0;x<r;x++){
oldTempCells[x]=[];
for(var y=0;y<r;y++){
oldTempCells[x][y]=getCell(cells,x,y);
}
}
function iterate(){
var tempCells=[];
for(var x=0;x<r;x++){
tempCells[x]=[];
for(var y=0;y<r;y++){
tempCells[x][y]=getCell(cells,x,y);
}
}
var isEmpty=true;
var diff=0;
var canChange=[];
for(var x=0;x<r;x++){
for(var y=0;y<r;y++){
if(tempCells[x][y]>0){
isEmpty=false;
}
diff+=tempCells[x][y]===oldTempCells[x][y]?0:1;
}
}
for(var x=0;x<r;x++){
for(var y=0;y<r;y++){
if((tempCells[x][y]!=oldTempCells[x][y])||isEmpty){
if(Math.random()>0.75){
tempCells[x][y]=1-tempCells[x][y];//Math.floor(Math.random()*2);
}
}
}
}
for(var x=0;x<r;x++){
for(var y=0;y<r;y++){
//if(cells[x][y]>0){
addCell(x,y,tempCells[x][y]);
//}
}
}
for(var i=0;i<period;i++){
calc();
}
shift();
}
window.setInterval(iterate,0);