0
我對HTML5 Canvas很新。然而,我一直致力於構建造型,但我無法獲得我創造的明星,以「流行明星時尚」的方式移動。如果你能幫助我讓明星移動,至少在整個屏幕上,這將是非常有用的。HTML5 Canvas-在畫布上移動一顆星
下面是代碼:
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
function drawStar(cx, cy, spikes, outerRadius, innerRadius) {
var rot = Math.PI/2 * 3;
var x = cx;
var y = cy;
var step = Math.PI/spikes;
ctx.strokeSyle = "#000";
ctx.beginPath();
ctx.moveTo(cx, cy - outerRadius)
for (i = 0; i < spikes; i++) {
x = cx + Math.cos(rot) * outerRadius;
y = cy + Math.sin(rot) * outerRadius;
ctx.lineTo(x, y)
rot += step
x = cx + Math.cos(rot) * innerRadius;
y = cy + Math.sin(rot) * innerRadius;
ctx.lineTo(x, y)
rot += step
}
ctx.lineTo(cx, cy - outerRadius)
ctx.closePath();
ctx.lineWidth=1;
ctx.strokeStyle='#0797c4';
ctx.stroke();
ctx.fillStyle='#0797c4';
ctx.fill();
}
drawStar(75, 100, 5, 30, 15);
這裏是Codepen: http://codepen.io/codingexperiments/pen/QbVyqE