-
Notifications
You must be signed in to change notification settings - Fork 0
/
frac1.js
95 lines (81 loc) · 2.08 KB
/
frac1.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
90
91
92
93
var matelight = require('matelight');
var m = matelight.connect();
var pic = new Array(1920);
for (var i = 0; i < 1920; i++) pic[i] = 0.5;
var blur1 = 0.5, blur2 = 0.5;
m.startLoop(function () {
var arr = new Array(1920);
var arr2 = new Array(1920);
for (var i = 0; i < 1920; i++) {
pic[i] = Math.max(0, Math.min(1, pic[i]+0.003*(2*Math.random()-1)));
}
var i = 0;
for (var y = 0; y < 16; y++) {
for (var x = 0; x < 40; x++) {
var sum = [0,0,0], count = 0;
count += add(sum, pic, x-1, y, blur1);
count += add(sum, pic, x , y, 1);
count += add(sum, pic, x+1, y, blur1);
arr[i+0] = sum[0]/count;
arr[i+1] = sum[1]/count;
arr[i+2] = sum[2]/count;
i+=3;
}
}
var i = 0;
for (var y = 0; y < 16; y++) {
for (var x = 0; x < 40; x++) {
var sum = [0,0,0], count = 0;
count += add(sum, arr, x, y-1, blur1);
count += add(sum, arr, x, y , 1);
count += add(sum, arr, x, y+1, blur1);
pic[i+0] = sum[0]/count;
pic[i+1] = sum[1]/count;
pic[i+2] = sum[2]/count;
i+=3;
}
}
var i = 0;
for (var y = 0; y < 16; y++) {
for (var x = 0; x < 40; x++) {
var sum = [0,0,0], count = 0;
count += add(sum, pic, x-1, y, blur2);
count += add(sum, pic, x , y, 1);
count += add(sum, pic, x+1, y, blur2);
arr[i+0] = sum[0]/count;
arr[i+1] = sum[1]/count;
arr[i+2] = sum[2]/count;
i+=3;
}
}
var i = 0;
for (var y = 0; y < 16; y++) {
for (var x = 0; x < 40; x++) {
var sum = [0,0,0], count = 0;
count += add(sum, arr, x, y-1, blur2);
count += add(sum, arr, x, y , 1);
count += add(sum, arr, x, y+1, blur2);
arr2[i+0] = sum[0]/count;
arr2[i+1] = sum[1]/count;
arr2[i+2] = sum[2]/count;
i+=3;
}
}
var i = 0;
for (var i = 0; i < 1920; i++) {
arr[i] = Math.max(0, Math.min(255, Math.round(((arr2[i]-0.5)*50+0.5)*255)));
}
//console.log(arr);
m.setArray(arr);
}, 40)
function add(sum, pic, x, y, value) {
if (x < 0) return 0;
if (y < 0) return 0;
if (x >= 40) return 0;
if (y >= 16) return 0;
var i = (x + y*40)*3;
sum[0] += pic[i+0]*value;
sum[1] += pic[i+1]*value;
sum[2] += pic[i+2]*value;
return value;
}