-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.js
127 lines (100 loc) · 2.63 KB
/
canvas.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
/*var canvas = document.querySelector(".canvas")
const c = canvas.getContext('2d')
canvas.width = innerWidth
canvas.height = innerHeight
addEventListener('resize', () => {
canvas.width = innerWidth
canvas.height = innerHeight
init()
})
class Particle {
constructor(x, y, radius) {
this.x = x
this.y = y
this.radius = radius
}
draw() {
c.beginPath()
c.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false)
c.shadowColor = '#fff'
c.shadowBlur = 15
c.fillStyle = '#fff'
c.fill()
c.closePath()
}
update() {
this.draw()
}
}
let particles
function init() {
particles = []
for (let i = 0; i < 1500; i++) {
const canvasWidth = canvas.width + 1000
const canvasHeight = canvas.height + 2000
const x = Math.random() * canvasWidth - canvasWidth / 2
const y = Math.random() * canvasHeight - canvasHeight / 2
const radius = 2 * Math.random()
particles.push(new Particle(x, y, radius))
}
}
// Animation Loop
let radians = 0
let alpha = 1
function animate() {
requestAnimationFrame(animate)
c.fillStyle = `rgba(10, 10, 10, ${alpha})`
c.fillRect(0, 0, canvas.width, canvas.height)
c.save()
c.translate(canvas.width / 2, canvas.height / 2)
c.rotate(radians)
particles.forEach((particle) => {
particle.update()
})
c.restore()
radians += 0.003
}
init()
animate()*/
// Initialising the canvas
var canvas = document.querySelector('canvas'),
ctx = canvas.getContext('2d');
// Setting the width and height of the canvas
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
addEventListener('resize', () => {
canvas.width = innerWidth;
canvas.height = innerHeight;
init();
});
// Setting up the letters
var letters = 'ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ';
letters = letters.split('');
// Setting up the columns
function init() {
var fontSize = 10,
columns = canvas.width / fontSize;
var counter = columns;
// Setting up the drops
var drops = [];
for (var i = 0; i < columns; i++) {
drops[i] = 1;
}
var initInterval;
// Setting up the draw function
function draw() {
ctx.fillStyle = 'rgba(0, 0, 0, .1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < drops.length; i++) {
var text = letters[Math.floor(Math.random() * letters.length)];
ctx.fillStyle = '#444';
ctx.fillText(text, i * fontSize, drops[i] * fontSize);
drops[i]++;
if (drops[i] * fontSize > canvas.height && Math.random() > .95) {
drops[i] = 0;
}
}
}
initInterval = setInterval(draw, 33);
}
init();