我發現了一個繪製螺旋的代碼,我需要旋轉360度(類似於催眠效果)。我嘗試對它進行動畫製作,但我不知道如何正確實施它。我沒時間了。如果代碼儘可能簡單,那將是非常好的。製作旋轉螺旋
這裏的螺旋代碼:
<canvas id="myCanvas" width="300" height="300"></canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
var centerX = 150;
var centerY = 150;
cxt.moveTo(centerX, centerY);
var STEPS_PER_ROTATION = 60;
var increment = 2*Math.PI/STEPS_PER_ROTATION;
var theta = increment;
while(theta < 40*Math.PI) {
var newX = centerX + theta * Math.cos(theta);
var newY = centerY + theta * Math.sin(theta);
cxt.lineTo(newX, newY);
theta = theta + increment;
}
cxt.stroke();
</script>
上也許這頁將幫助您https://開頭開發商.mozilla.org/zh-CN/docs/HTML/Canvas/Tutorial/Transformations – Xotic750 2013-04-29 19:52:35