简体   繁体   English

画布形状动画

[英]Canvas shape animation

I want to animate shapes in canvas in 3 phase appearance of the shape, moving and disappear and these should execute one after other and stop at specified time so please help me.... I m trying with this code 我想在画布上以形状的三个阶段外观为形状进行动画处理,然后移动并消失,它们应该一个接一个地执行,并在指定的时间停止,因此请帮助我。...我正在尝试使用此代码

function dummy_animate(){
  //execute it one after other....

   shadow(); 

   setTimeout("fadein_rect()" , 3000);

   move_timer =  setInterval(drawIt1,100);

  timerId_out = setInterval("fadeout()", 300);
}

canvas works like a tv screen, you should redraw every frame, so your code won't work canvas就像电视屏幕一样,您应该重新绘制每一帧,因此您的代码将无法工作

<canvas></canvas>
<style type="text/css">
    body{height:100%;width:100%;margin:0;padding:0;border:0;}
</style>

<script type="text/javascript">
(function () {
    var canvas = document.body.children[0],
    docElem = document.documentElement,

    h = canvas.height = docElem.clientHeight,
    w = canvas.width = docElem.clientWidth,
    ctx = canvas.getContext("2d"),
    timeout = 33,
    hc = h/2,
    wc = w/2,
    spd = 5;

    //console.log( ctx );
    function clear (  ) {
        ctx.fillRect ( 0, 0, w, h );
    }

    function update (  ) {
        clear();
        moveLeft();
    }

    function moveLeft (  ) {
        ctx.beginPath();
        ctx.moveTo ( wc, hc );
        ctx.lineTo ( wc = wc - spd, hc );
        ctx.closePath();
        ctx.stroke();
    }

    function init (  ) {

        ctx.lineWidth = 5;
        ctx.strokeStyle = "rgb(255,255,255)";

        // fade mask style
        // this is a very simply demo so i use this
        ctx.fillStyle = "rgba(0,0,0,0.3)"; 

        setInterval ( update , timeout );
    }

    init();
})()    

</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM