我得到了以下代码:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.moveTo(130, 0);
ctx.lineTo(130, 150);
ctx.stroke();我有点弄乱了像素和旋转绘图/线条。让我解释一下,我有正常的画布代码,但旋转不能正常工作。我已经尝试了一些数字,但我仍然不能得到我想要的角度,因为我只能做180度旋转,而不是270度(或多或少)。
下面是一张图片来解释我想要什么:
http://img689.imageshack.us/img689/1996/13648488297821.jpg
红线是我想要的角度,黑线是我得到的角度(黑色及以上的角度是我能得到的,黑线下我不能做任何旋转来得到想要的角度)。
请不要给我CSS代码,因为我正在使用JavaScript代码循环
发布于 2013-06-08 09:45:22
我编写这段代码的参考资料可以在here和here中找到。如果你把这一行拆成两行,一个接一个,那就容易多了。例如..。
ctx.beginPath();
//edit the x or y to change starting point.
ctx.moveTo(50, 100);
//edit the x to change the length, and y for the angle.
//if you want a horizontal line this y must be the same as the moveto y.
ctx.lineTo(150, 100);
//This x & y must be the same as the previous lineto.
ctx.moveTo(150, 100);
//edit the x to change the length, and y for the angle.
ctx.lineTo(200, 130);
ctx.stroke();请记住,这些方法采用(x,y),只要您的第一个lineTo和下一个moveTo的位置相同,您的两行代码就不会中断。希望这能有所帮助!
https://stackoverflow.com/questions/15751818
复制相似问题