Meta Description" name="description" />
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Love Heart</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #000;
overflow: hidden;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
const canvas = document.getElementById("c");
const ctx = canvas.getContext("2d");
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resize();
window.addEventListener("resize", resize);
const TEXT = "I Love You";
let angle = 0;
function heartX(t) {
return 16 * Math.pow(Math.sin(t), 3);
}
function heartY(t) {
return 13 * Math.cos(t)
- 5 * Math.cos(2 * t)
- 2 * Math.cos(3 * t)
- Math.cos(4 * t);
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "red";
ctx.font = "bold 12px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
const cx = canvas.width / 2;
const cy = canvas.height / 2;
for (let t = 0; t < Math.PI * 2; t += 0.1) {
const x = heartX(t + angle) * 15;
const y = -heartY(t + angle) * 15;
ctx.fillText(TEXT, cx + x, cy + y);
}
angle += 0.01;
requestAnimationFrame(draw);
}
draw();
</script>
</body>
</html>1
1
2KB
2KB
99.0ms
124.0ms
100.0ms