日期:2014-05-16 浏览次数:20924 次
var canvas = document.getElementById("canvas"); var context = canvas.getContext('2d'); var Width=canvas.width; var Height=canvas.height; var s = "HTML 5 旋转"; context.font="lighter 1.5em palatino"; var colors = ["orange","blue","red"]; function drawText(s,x,y){ context.save(); // 旋转文本 for (var i = 0; i < 12; i++) { context.rotate(30 * Math.PI / 180); context.strokeStyle=colors[i % 3]; context.strokeText(s, 0, 0); } context.restore(); } var angle=0; var loop = setInterval(function () { context.clearRect(0, 0, canvas.width, canvas.height); context.save(); // 平移原点到图形环境的中心 context.translate(Width/2,Height/2); context.rotate(angle * Math.PI / 180); drawText(s,Width/2,Height/2,angle); context.restore(); angle = (angle + 10) % 360; }, 500);