-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackerEffectBG.html
More file actions
149 lines (124 loc) · 4.58 KB
/
hackerEffectBG.html
File metadata and controls
149 lines (124 loc) · 4.58 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
overflow: hidden;
background: #000;
}
canvas {
background: #000;
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<canvas id="canvas1"></canvas>
<script>
const canvas = document.getElementById('canvas1')
const ctx = canvas.getContext('2d')
canvas.width = window.innerWidth
canvas.height = window.innerHeight
let gradient = ctx.createRadialGradient(
canvas.width / 2,
canvas.height / 2,
100,
canvas.width / 2,
canvas.height / 2, canvas.width / 2)
gradient.addColorStop(0, 'magenta')
gradient.addColorStop(0.5, 'cyan')
gradient.addColorStop(1, 'red')
class Symbol {
constructor(x, y, fontSize, canvasHeight) {
this.characters = `アァカサタナハマヤャラワガザダバパイィキシチニヒミリヰギジヂビピウゥクスツヌフムユュルグズブヅプエェケセテネヘメレヱゲゼデベペオォコソトノホモヨョロヲゴゾドボポヴッン0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`
this.x = x
this.y = y
this.text = ''
this.fontSize = fontSize
this.canvasHeight = canvasHeight
}
draw(context) {
this.text = this.characters.charAt(Math.floor(Math.random() * this.characters.length))
context.fillText(this.text, this.x * this.fontSize, this.y * this.fontSize)
if (this.y * this.fontSize > this.canvasHeight &&
Math.random() > 0.98) {
this.y = 0
}
else {
this.y += 1
}
}
}
class Effect {
constructor(canvasWidth, canvasHeight) {
this.canvasWidth = canvasWidth
this.canvasHeight = canvasHeight
this.fontSize = 15
this.columns = this.canvasWidth / this.fontSize
this.symbols = []
this.#initialize()
console.log(this.symbols)
}
#initialize() {
for (let i = 0; i < this.columns; i++) {
this.symbols[i] = new Symbol(i, 0, this.fontSize, this.canvasHeight)
}
} reSize(width, height) {
this.canvasWidth = width
this.canvasHeight = height
this.columns = this.canvasWidth / this.fontSize
this.symbols = []
this.#initialize()
}
}
const effect = new Effect(canvas.width, canvas.height)
let lastTime = 0
const fps = 30
const nextFrame = 1000 / fps
let timer = 0
function animate(timeStamp) {
const deltaTime = timeStamp - lastTime
lastTime = timeStamp
if (timer > nextFrame) {
ctx.fillStyle = `rgb(0,0,0,0.08)`
ctx.textAlign = 'center'
ctx.fillRect(0, 0, canvas.width, canvas.height)
// ctx.fillStyle = '#0aff0a '
ctx.fillStyle = gradient
ctx.font = effect.fontSize + `px monospace`
effect.symbols.forEach(symbol => symbol.draw(ctx))
timer = 0
}
else {
timer += deltaTime
}
requestAnimationFrame(animate)
}
animate(0)
window.addEventListener('resize', function () {
canvas.width = window.innerWidth
canvas.height = window.innerHeight
effect.reSize(canvas.width, canvas.height)
gradient = ctx.createRadialGradient(
canvas.width / 2,
canvas.height / 2,
100,
canvas.width / 2,
canvas.height / 2, canvas.width / 2)
gradient.addColorStop(0, 'magenta')
gradient.addColorStop(0.5, 'cyan')
gradient.addColorStop(1, 'red')
})
</script>
</body>
</html>