forked from lizzz0523/limni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.js
36 lines (33 loc) · 768 Bytes
/
shared.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
export async function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
export function filter (params, init = '') {
return Object.keys(params).reduce((value, key) => {
value += ` ${key}(${params[key]})`
return value
}, init)
}
export function blur (data, x, y, w, h) {
let v = { r: 0, g: 0, b: 0, a: 0 }
let n = 0
for (let dy = -5; dy <= 5; dy++) {
for (let dx = -5; dx <= 5; dx++) {
const ry = y + dy
const rx = x + dx
if (rx < 0 || rx >= w || ry < 0 || ry >= h) {
continue
}
const t = (ry * w + rx) * 4
v.r += data[t + 0]
v.g += data[t + 1]
v.b += data[t + 2]
v.a += data[t + 3]
n++
}
}
v.r /= n
v.g /= n
v.b /= n
v.a /= n
return v
}