码迷,mamicode.com
首页 > Web开发 > 详细

html5 canvas 旋转扩大

时间:2015-02-11 18:09:55      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
window.onload = function ()
{
    var oC = document.getElementById(‘c1‘);
    var oGC = oC.getContext(‘2d‘);
    
    var num = 0;
    var inum2 = 0;
    var value = 1;
    
    setInterval(function ()
    {
        num++;
        oGC.save();
        if(inum2 == 100)
        {
            value = -1;
        }
        else if(inum2 == 0)
        {
            value = 1;
        }
        
        inum2 += value;
        oGC.clearRect(0,0,oC.width,oC.height);
        oGC.translate(100,100);
        oGC.rotate(num*Math.PI/180);
        
        oGC.scale(inum2*1/50,inum2*1/50);
        oGC.translate(-50,-50);
        oGC.fillRect(0,0,100,100);
        oGC.restore();
    },30)
    
    
    
    
}
</script>
<style>
body{
    background:pink;
    }
#c1{
    background:white;
    }    
</style>
</head>

<body>
    <canvas id="c1" width="400" height="400"></canvas>
</body>
</html>

 

html5 canvas 旋转扩大

标签:

原文地址:http://www.cnblogs.com/mayufo/p/4286520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!