-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·77 lines (71 loc) · 2.18 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./Star.js"></script>
<script src="https://alist.xkzs.icu/d/Resource/public/public_files/js/Disable.js?sign=8xETgLUpne_JxwMv3ZXJtvoxD2UoncDef_b01TKrfMQ=:0"></script>
<title>星空背景</title>
<style>
* {
margin: 0;
padding: 0;
}
#starBg {
display: block;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
z-index: 2;
}
</style>
</head>
<body>
<div>
<canvas id="starBg"></canvas>
</div>
<script type="text/javascript">
let stars = [];
const maxStars = 1100; // 星星数量
function initCanvas() {
const canvas = document.getElementById("starBg");
const ctx = canvas.getContext("2d");
const w = (canvas.width = window.innerWidth);
const h = (canvas.height = window.innerHeight);
const canvas2 = document.createElement("canvas");
const ctx2 = canvas2.getContext("2d");
canvas2.width = 100;
canvas2.height = 100;
const half = canvas2.width / 2;
const gradient2 = ctx2.createRadialGradient(half, half, 0, half, half, half);
gradient2.addColorStop(0.025, "#CCC");
gradient2.addColorStop(0.1, "hsl(217, 61%, 33%)");
gradient2.addColorStop(0.25, "hsl(217, 64%, 6%)");
gradient2.addColorStop(1, "transparent");
ctx2.fillStyle = gradient2;
ctx2.beginPath();
ctx2.arc(half, half, half, 0, Math.PI * 2);
ctx2.fill();
for (var i = 1; i < maxStars; i++) {
const star = new Star({w, h}, ctx, canvas2);
stars[i] = star;
}
function animation() {
ctx.globalCompositeOperation = "source-over";
ctx.globalAlpha = 0.8; //尾巴
ctx.fillStyle = "hsla(217, 64%, 6%, 2)";
ctx.fillRect(0, 0, w, h);
ctx.globalCompositeOperation = "lighter";
for (let i = 1; i < stars.length; i++) {
stars[i].draw();
}
window.requestAnimationFrame(animation);
}
animation();
}
initCanvas();
</script>
</body>
</html>