html
html
1
2
3
4
5
6
7
8
9
<!DOCTYPE html>
<html>
<head>
<title>Valentine's Day Code</title>
</head>
<body>
<canvas id="cnv"></canvas>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
body {
position:absolute;
width:100%;
height:100%;
margin:0;
background-color: black;
overflow:hidden;
}
canvas{
position:absolute;
}
Enter to Rename, Shift+Enter to Preview
js
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
let W, H, c, ctx, arr = []
const heart = (x, c, d) => -d*Math.pow(x, 2/3) - c*Math.sqrt(1- x*x)
class Dot {
constructor(x, y, d) {
this.x = x;
this.y = y;
this.d = d;
this.r = 1
this.rad = 3
}
getColor() {
let red = Math.min(255, Math.max(0, 255 - this.rad));
let blue = Math.min(255, Math.max(0, this.rad * 100));
return `rgba(${red}, 0, ${blue}, 1)`;
}
draw(){
ctx.beginPath()
ctx.fillStyle = this.getColor()
ctx.arc(this.x0, this.y0, this.rad,0,2*Math.PI)
ctx.fill()
}
update() {
this.x0 = W / 2 + this.d*this.x*this.r
this.y0 = H / 2 + this.d*this.y*this.r
this.r+=2
this.rad = this.rad>0.1?this.rad-=0.02 : this.rad
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Uruchom