【发布时间】:2019-03-03 08:01:08
【问题描述】:
我想使用画布围绕三角形旋转一个圆圈。有之前的代码,但这里是中间的圆圈,和一个旋转的矩形,我希望圆圈旋转并在中间有一个三角形。有人可以帮忙吗?
这是我的 JS 代码:
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var cx = 100;
var cy = 100;
var rectWidth = 15;
var rectHeight = 10;
var rotation = 0;
requestAnimationFrame(animate);
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.arc(cx, cy, 10, 0, Math.PI * 2);
ctx.closePath();
ctx.fill();
ctx.save();
ctx.translate(cx, cy);
ctx.rotate(rotation);
ctx.strokeRect(-rectWidth / 2 + 20, -rectHeight / 2, rectWidth, rectHeight);
ctx.restore();
rotation += Math.PI / 180;
}
<canvas id="canvas"></canvas>
【问题讨论】:
标签: javascript canvas html5-canvas