帮我用js 写一个爱心代码
时间: 2023-11-23 20:47:34 浏览: 79
基于JavaScript实现的程序员表白爱心代码(2套)
好的,以下是使用 JavaScript 编写的一个简单的爱心代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>爱心</title>
</head>
<body>
<canvas id="myCanvas"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var centerX = canvas.width / 2;
var centerY = canvas.height / 2 - 50;
var radius = 100;
context.beginPath();
context.moveTo(centerX, centerY);
context.bezierCurveTo(centerX + 100, centerY - 75, centerX + 75, centerY - 100, centerX, centerY - 50);
context.bezierCurveTo(centerX - 75, centerY - 100, centerX - 100, centerY - 75, centerX, centerY);
context.fillStyle = "#ff69b4";
context.fill();
context.beginPath();
context.moveTo(centerX, centerY);
context.bezierCurveTo(centerX + 100, centerY + 75, centerX + 75, centerY + 100, centerX, centerY + 50);
context.bezierCurveTo(centerX - 75, centerY + 100, centerX - 100, centerY + 75, centerX, centerY);
context.fillStyle = "#ff69b4";
context.fill();
</script>
</body>
</html>
```
你可以将这段代码保存为一个 HTML 文件,然后在浏览器中打开,就可以看到一个粉色的爱心了。
阅读全文