Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
17mie32
GitHub Repository: 17mie32/17mie32.github.io
Path: blob/main/libs/background/canvas-nest.js
1318 views
1
! function () {
2
var userAgentInfo = navigator.userAgent;
3
var Agents = ["iPad", "iPhone", "Android",
4
"SymbianOS", "Windows Phone",
5
"iPod", "webOS", "BlackBerry", "IEMobile"
6
];
7
for (var v = 0; v < Agents.length; v++) {
8
if (userAgentInfo.indexOf(Agents[v]) > 0) {
9
return;
10
}
11
}
12
13
function o(w, v, i) {
14
return w.getAttribute(v) || i
15
}
16
17
function j(i) {
18
return document.getElementsByTagName(i)
19
}
20
21
function l() {
22
var i = j("script"),
23
w = i.length,
24
v = i[w - 1];
25
return {
26
l: w,
27
z: o(v, "zIndex", -1),
28
o: o(v, "opacity", 0.5),
29
c: o(v, "color", "0,0,0"),
30
n: o(v, "count", 99)
31
}
32
}
33
34
function k() {
35
r = u.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth, n = u.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
36
}
37
38
function b() {
39
e.clearRect(0, 0, r, n);
40
var w = [f].concat(t);
41
var x, v, A, B, z, y;
42
t.forEach(function (i) {
43
i.x += i.xa, i.y += i.ya, i.xa *= i.x > r || i.x < 0 ? -1 : 1, i.ya *= i.y > n || i.y < 0 ? -1 : 1, e.fillRect(i.x - 0.5, i.y - 0.5, 1, 1);
44
for (v = 0; v < w.length; v++) {
45
x = w[v];
46
if (i !== x && null !== x.x && null !== x.y) {
47
B = i.x - x.x, z = i.y - x.y, y = B * B + z * z;
48
y < x.max && (x === f && y >= x.max / 2 && (i.x -= 0.03 * B, i.y -= 0.03 * z), A = (x.max - y) / x.max, e.beginPath(), e.lineWidth = A / 2, e.strokeStyle = "rgba(" + s.c + "," + (A + 0.2) + ")", e.moveTo(i.x, i.y), e.lineTo(x.x, x.y), e.stroke())
49
}
50
}
51
w.splice(w.indexOf(i), 1)
52
}), m(b)
53
}
54
var u = document.createElement("canvas"),
55
s = l(),
56
c = "c_n" + s.l,
57
e = u.getContext("2d"),
58
r, n, m = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (i) {
59
window.setTimeout(i, 1000 / 45)
60
},
61
a = Math.random,
62
f = {
63
x: null,
64
y: null,
65
max: 20000
66
};
67
u.id = c;
68
u.style.cssText = "position:fixed;top:0;left:0;z-index:" + s.z + ";opacity:" + s.o;
69
j("body")[0].appendChild(u);
70
k(), window.onresize = k;
71
window.onmousemove = function (i) {
72
i = i || window.event, f.x = i.clientX, f.y = i.clientY
73
}, window.onmouseout = function () {
74
f.x = null, f.y = null
75
};
76
for (var t = [], p = 0; s.n > p; p++) {
77
var h = a() * r,
78
g = a() * n,
79
q = 2 * a() - 1,
80
d = 2 * a() - 1;
81
t.push({
82
x: h,
83
y: g,
84
xa: q,
85
ya: d,
86
max: 6000
87
})
88
}
89
setTimeout(function () {
90
b()
91
}, 100)
92
}();
93
94