圆图不清除在90度
Circular drawing is not cleared at 90 degrees
我想在360度轨道上移动一个红色圆圈。
但在90度处,圆圈未清除。
这里是代码: https://jsfiddle.net/Laqd0L36/3/
var i=0;
function Rotate(ctx){
i++;
if(i==360){
i=0;
}
ctx.clearRect(0,0,ctx.canvas.width,ctx.canvas.height);
//Radius of orbit * i(degree) * convert to radian
x = 140*Math.cos(i*Math.PI/180);
y = 140*Math.sin(i*Math.PI/180);
Circle(ctx,x,y);
}
function Circle(ctx,x,y){
ctx.fillStyle = 'rgb(255,35,55)';
ctx.beginPath();
ctx.arc(x,y,12,0,Math.PI*2,true);
ctx.fill();
ctx.closePath();
}
function CtxInterval(){
var can = document.getElementById("can");
var ctx = can.getContext("2d");
ctx.translate(150,150);
setInterval(function(){Rotate(ctx);},10);
}
CtxInterval();
当您通过150, 150
翻译上下文时,您需要在-150, -150
开始您的clearRect
矩形。(这是你更新的小提琴)
@Teemu的评论是更优雅的解决方案,即
去掉
ctx.translate(150, 150)
,arc()
中的x和y加150
var i=0;
function Rotate(ctx){
i++;
if(i==360){
i=0;
}
console.log("width: "+ctx.canvas.width+ "height: "+ctx.canvas.height);
ctx.clearRect(-150,-150,ctx.canvas.width,ctx.canvas.height);
//Radius of orbit * i(degree) * convert to radian
x = 140*Math.cos(i*Math.PI/180);
y = 140*Math.sin(i*Math.PI/180);
Circle(ctx,x,y);
}
function Circle(ctx,x,y){
ctx.fillStyle = 'rgb(255,35,55)';
ctx.beginPath();
ctx.arc(x,y,12,0,Math.PI*2,true);
ctx.fill();
ctx.closePath();
}
function CtxInterval(){
var can = document.getElementById("can");
var ctx = can.getContext("2d");
ctx.translate(150,150);
setInterval(function(){Rotate(ctx);},10);
}
CtxInterval();
相关文章:
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 图像在旋转 90 度时脱离父 td
- 如何设置对象沿世界x轴旋转90度
- 如何将每个图形旋转90度
- 三.js设置旋转矩阵超过90度时的奇怪行为
- 将 d3.parset 可视化效果旋转 90 度(使可视化效果变为水平而不是垂直)
- 通过手机加载时,画布图像会将图像旋转 90 度
- 自拍时图像旋转了90度
- d3:计算两个节点之间的线的中点,画一条从它到一个新节点成90度角的线
- html将整个画布旋转90度
- 未使用Chrome 37中的.transform应用旋转(90度)
- Three.js -当相机以90度角旋转时,为什么在x轴和z轴上旋转会产生相同的效果?
- 顺时针旋转画布90度,更新宽度和高度
- 旋转背景图像的Div 90度使用JQuery
- 根据其他图像的位置旋转图像90度
- 如何将包含图像的画布旋转90、180、270度
- 使用three.js和tween.js以90度增量旋转对象以创建360度循环
- 将桌子旋转90度
- 如何在HTML5中转换-90度后使网页适合
- 圆图不清除在90度