Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 旋转图像,使其看起来像在旋转_Javascript_Html_Html5 Canvas - Fatal编程技术网

Javascript 旋转图像,使其看起来像在旋转

Javascript 旋转图像,使其看起来像在旋转,javascript,html,html5-canvas,Javascript,Html,Html5 Canvas,我试图连续旋转雪花的图像,使其产生在图像中心旋转的幻觉,我正在努力解决这个问题,这里有一些代码 我有一个循环,其中函数snowball被调用,但这并不重要,因为它不会连续旋转一次。 斯诺,是我在代码前面引入的图像 function drawSnowBall() { context.beginPath(); for (var i = 0; i < mp; i++) { var p = particles[i];

我试图连续旋转雪花的图像,使其产生在图像中心旋转的幻觉,我正在努力解决这个问题,这里有一些代码

我有一个循环,其中函数snowball被调用,但这并不重要,因为它不会连续旋转一次。 斯诺,是我在代码前面引入的图像

 function drawSnowBall() {
        context.beginPath();

        for (var i = 0; i < mp; i++) {
            var p = particles[i];
            context.drawImage(Snow,p.x, p.y);
        }
        if (pause == false)
        {

        updateSnow();

}
    }
    var angle = 0;

    function updateSnow() {

        angle;

        for (var i = 0; i < mp; i++) {
            var p = particles[i];
            //Updating X and Y coordinates
            //We will add 1 to the cos function to prevent negative values which will lead flakes to move upwards
            //Every particle has its own density which can be used to make the downward movement different for each flake
            //Lets make it more random by adding in the radius
            p.y += Math.cos(angle + p.d) + SnowSpeed + p.r / 2;
            p.x += Math.sin(angle) * 2;

            //Sending flakes back from the top when it exits
            if (p.x > 800 + 5 || p.x < -5 || p.y > 700) {
                if (i % 3 > 0) //66.67% of the flakes
                {
                    particles[i] = {
                        x: Math.random() * 800,
                        y: -10,
                        r: p.r,
                        d: p.d
                    };
                }
            }


        }

    }
函数drawSnowBall(){
context.beginPath();
对于(变量i=0;i800+5 | | p.x<-5 | | p.y>700){
如果(i%3>0)//66.67%的薄片
{
粒子[i]={
x:Math.random()*800,
y:-10,
r:p.r,
d:p.d
};
}
}
}
}

只需使用setInterval和内部的方法,就可以了。

可能应该改用setInterval