2013-04-01 56 views
3

我有下面的代码:帆布像素错误

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

红线是我想要的角度,但黑线是我得到的角(黑角和更高时,所有我能得到,在黑线下我不能做任何旋转来获得想要的角度)。

,因为我使用的是JavaScript代码回路

+1

你能捣鼓它吗?我不太了解这个问题。 – jeremy

+0

包含您用于实际执行轮换的代码,否则很难弄清楚问题所在。我现在看到的代码是画线的代码 – Flambino

+0

jsfiddle.net/2Yf7F - 在这里你去了,我已经将它添加到bin网站,你只是没有看到它因为我们在聊天室 – ExCluSiv3

回答

1

从我想出这个代码中的参考文献可以发现here,并here请不要给我的CSS代码。如果你把这条线分成两条,一条接一条地分成两条,那就容易多了。 例如...

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是你会不会有一个突破的相同位置在两行。希望这可以帮助!