Wol*_*lfr 3 javascript html5 canvas
我无法使用Canvas在图像周围旋转图像.
由于无法旋转图像,因此必须旋转画布:如果我将画布旋转一定程度,我想要旋转的原点会发生变化.我不知道如何跟踪这一变化.
这是我目前的代码:http://pastie.org/669023
一个演示在http://preview.netlashproject.be/cog/
如果你想给出一些东西,拉链代码和图像在http://preview.netlashproject.be/cog/cog.zip
DaM*_*acc 11
我修改了你的代码:
var rotation = 0;
function draw(){
var ctx = document.getElementById('myCanvas').getContext('2d');
ctx.globalCompositeOperation = 'destination-over';
ctx.save();
ctx.clearRect(0,0,200,200);
ctx.translate(100,100); // to get it in the origin
rotation +=1;
ctx.rotate(rotation*Math.PI/64); //rotate in origin
ctx.translate(-100,-100); //put it back
ctx.drawImage(cog,0,0);
ctx.restore();
}
Run Code Online (Sandbox Code Playgroud)
这里重要的是你必须在旋转之前先将图像转换为原点,然后将其翻译回来!
| 归档时间: |
|
| 查看次数: |
5714 次 |
| 最近记录: |