-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
101 lines (92 loc) · 2.54 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>ASCII Donut Animation</title>
<style>
html,
body {
margin: 0;
padding: 0;
background-color: black;
}
pre {
font-family: monospace;
white-space: pre;
color: chartreuse;
}
</style>
</head>
<body>
<pre id="donut"></pre>
<script>
function drawDonut() {
const canvasWidth = 90;
const canvasHeight = 36;
let A = 0;
let B = 0;
const preElement = document.getElementById("donut");
const z = new Array(canvasWidth * canvasHeight).fill(0);
const b = new Array(canvasWidth * canvasHeight).fill(" ");
function render() {
// Clear the canvas
b.fill(" ");
z.fill(0);
for (let j = 0; j < 6.28; j += 0.07) {
for (let i = 0; i < 6.28; i += 0.02) {
const c = Math.sin(i);
const d = Math.cos(j);
const e = Math.sin(A);
const f = Math.sin(j);
const g = Math.cos(A);
const h = d + 2;
const D = 1 / (c * h * e + f * g + 5);
const l = Math.cos(i);
const m = Math.cos(B);
const n = Math.sin(B);
const t = c * h * g - f * e;
const x = Math.floor(40 + 30 * D * (l * h * m - t * n));
const y = Math.floor(18 + 15 * D * (l * h * n + t * m));
const o = x + canvasWidth * y;
const N = Math.floor(
8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n)
);
if (
y >= 0 &&
y < canvasHeight &&
x >= 0 &&
x < canvasWidth &&
D > z[o]
) {
z[o] = D;
b[o] = [
",",
".",
"-",
"~",
":",
";",
"=",
"!",
"*",
"#",
"$",
"@",
][N > 0 ? N : 0];
}
}
}
let output = "";
for (let i = 0; i < canvasWidth * canvasHeight; i++) {
output += i % canvasWidth ? b[i] : "\n";
}
preElement.textContent = output;
A += 0.04;
B += 0.02;
requestAnimationFrame(render);
}
render();
}
drawDonut();
</script>
</body>
</html>