加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

html5+canvas+js实现图形翻转和文字翻转与竖排

(2012-06-01 18:31:55)
标签:

html5

canvas

js

图片翻转

文字竖排

it

分类: HTTP/HTML/JS技术
代码如下:

<!DOCTYPE HTML>

<html> 

    <head> 

        <script language="javascript"> 

            function drawBowtie(ctx, fillStyle) { 

                ctx.fillStyle = "rgba(200,200,200,0.3)"

                ctx.fillRect(-30, -30, 60, 60); 

                ctx.fillStyle = fillStyle; 

                ctx.globalAlpha = 1.0

                ctx.beginPath(); 

                ctx.moveTo(25, 25); 

                ctx.lineTo(-25, -25); 

                ctx.lineTo(25, -25); 

                ctx.lineTo(-25, 25); 

                ctx.closePath(); 

                ctx.strokeText("2012",-15,5);

                ctx.fill(); 

                

            }

            function dot(ctx) { 

                ctx.save(); 

                ctx.fillStyle = "black"

                ctx.fillRect(-2, -2, 4, 4); 

                ctx.restore(); 

           

            

            function draw() { 

                var ctx = document.getElementByIdx_x('myCanvas').getContext("2d"); 

                // note that all other translates are relative to this 

                // one 

                ctx.translate(100, 100); 

                

                ctx.save(); 

                ctx.translate(0, 0); // unnecessary 

                drawBowtie(ctx, "red"); 

                dot(ctx); 

                ctx.restore(); 

                

                ctx.save(); 

                ctx.translate(100, 0); 

                ctx.rotate(90 * Math.PI / 180); 

                drawBowtie(ctx, "green"); 

                dot(ctx); 

                ctx.restore();

                

                ctx.save(); 

                ctx.translate(0, 100); 

                ctx.rotate(135 * Math.PI / 180); 

                drawBowtie(ctx, "blue"); 

                dot(ctx); 

                ctx.restore(); 

                

                ctx.save(); 

                ctx.translate(100, 100); 

                ctx.rotate(90 * Math.PI / 180); 

                drawBowtie(ctx, "yellow"); 

                dot(ctx); 

                ctx.restore(); 

           

            window.onload=function(){

                draw();

            }

            </script> 

    </head>

    <body> 

        <div id="pw_body" style="width:100%;height:100%">

            <canvas id="myCanvas" width="300" height="300"></canvas> 

            <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>

        </div>

    </body> 

</html> 

效果图如下:

http://s10/middle/71261a2dgc166bc64ba59&690

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有