-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdonut.js
132 lines (119 loc) · 3.44 KB
/
donut.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
(function () {
var _onload = function () {
var pretag = document.getElementById("d");
var canvastag = document.getElementById("canvasdonut");
var tmr1 = undefined,
tmr2 = undefined;
var A = 1,
B = 1;
var asciiframe = function () {
var b = [];
var z = [];
A += 0.07;
B += 0.03;
var cA = Math.cos(A),
sA = Math.sin(A),
cB = Math.cos(B),
sB = Math.sin(B);
for (var k = 0; k < 1760; k++) {
b[k] = k % 80 == 79 ? "\n" : " ";
z[k] = 0;
}
for (var j = 0; j < 6.28; j += 0.07) {
var ct = Math.cos(j),
st = Math.sin(j);
for (i = 0; i < 6.28; i += 0.02) {
var sp = Math.sin(i),
cp = Math.cos(i),
h = ct + 2,
D = 1 / (sp * h * sA + st * cA + 5),
t = sp * h * cA - st * sA;
var x = 0 | (40 + 30 * D * (cp * h * cB - t * sB)),
y = 0 | (12 + 15 * D * (cp * h * sB + t * cB)),
o = x + 80 * y,
N =
0 |
(8 *
((st * sA - sp * ct * cA) * cB -
sp * ct * sA -
st * cA -
cp * ct * sB));
if (y < 22 && y >= 0 && x >= 0 && x < 79 && D > z[o]) {
z[o] = D;
b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0];
}
}
}
pretag.innerHTML = b.join("");
};
window.anim1 = function () {
if (tmr1 === undefined) {
tmr1 = setInterval(asciiframe, 50);
} else {
clearInterval(tmr1);
tmr1 = undefined;
}
};
var R1 = 1;
var R2 = 2;
var K1 = 150;
var K2 = 5;
var canvasframe = function () {
var ctx = canvastag.getContext("2d");
ctx.fillStyle = "#000";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
if (tmr1 === undefined) {
A += 0.07;
B += 0.03;
}
var cA = Math.cos(A),
sA = Math.sin(A),
cB = Math.cos(B),
sB = Math.sin(B);
for (var j = 0; j < 6.28; j += 0.3) {
var ct = Math.cos(j),
st = Math.sin(j);
for (i = 0; i < 6.28; i += 0.1) {
// i <=> phi
var sp = Math.sin(i),
cp = Math.cos(i);
var ox = R2 + R1 * ct,
oy = R1 * st;
var x = ox * (cB * cp + sA * sB * sp) - oy * cA * sB;
var y = ox * (sB * cp - sA * cB * sp) + oy * cA * cB;
var ooz = 1 / (K2 + cA * ox * sp + sA * oy);
var xp = 150 + K1 * ooz * x;
var yp = 120 - K1 * ooz * y;
var L =
0.7 *
(cp * ct * sB -
cA * ct * sp -
sA * st +
cB * (cA * st - ct * sA * sp));
if (L > 0) {
ctx.fillStyle = "rgba(255,255,255," + L + ")";
ctx.fillRect(xp, yp, 1.5, 1.5);
}
}
}
};
window.anim2 = function () {
if (tmr2 === undefined) {
tmr2 = setInterval(canvasframe, 50);
} else {
clearInterval(tmr2);
tmr2 = undefined;
}
};
asciiframe();
canvasframe();
};
if (document.all) window.attachEvent("onload", _onload);
else window.addEventListener("load", _onload, false);
})();
playmusic(){
var audioElement = document.createElement("audio");
audioElement.setAttribute("src", "spin.mp3");
audioElement.setAttribute("autoplay", "autoplay");
audioElement.loop = true;
};