读HTML5应用与开发实践【三】【canvas圆、贝赛尔曲线、样式与颜色】

<!Doctype html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html";charset="utf-8">
        <title>canvas</title>
        <script language=javascript>
            function draw()
            {
                var canvas=document.getElementById('1');
                var context=canvas.getContext('2d');
                context.globalAlpha=0.7;
                context.beginPath();
                context.moveTo(60,100);
                context.lineTo(700,450);
                context.lineTo(400,145);
                context.lineTo(60,200);
                context.fillStyle="green";
                context.strokeStyle="black";
                context.closePath();
                context.fill(); 
                context.stroke();
                context.fillStyle="yellow";
                context.fillRect(100,100,50,135);
                context.beginPath();
                context.arc(200,400,50,0,2*Math.PI,true);
                context.closePath();
                context.fillStyle="rgba(255,0,0,0.25)";
                context.fill();
                context.beginPath();
                context.arc(180,390,10,0,2*Math.PI,true);
                context.fillStyle="rgba(255,0,0,0.8)";
                context.fill();
                context.closePath();
                //右眼
                context.beginPath();
                context.arc(220,390,10,0,2*Math.PI,true);
                context.fillStyle="rgba(255,0,0,0.8)";
                context.fill();
                context.closePath();
                //嘴
                context.beginPath();
                context.lineWidth=3;
                context.lineCap="round";
                context.arc(200,413,20,Math.PI,0,true);
                context.strokeStyle="rgba(255,0,0,0.8)";
                context.stroke();
                
                //贝赛尔曲线0.0 爱心
                context.beginPath();
                context.strokeStyle="rgba(255,0,0,1)";
                context.moveTo(375,40);
                context.bezierCurveTo(375,37,370,25,350,25);
                context.bezierCurveTo(320,25,320,62.5,320,62.5);
                context.bezierCurveTo(320,80,340,102,375,120);
                context.bezierCurveTo(410,102,430,80,430,62.5);
                context.bezierCurveTo(430,62.5,430,25,400,25);
                context.bezierCurveTo(385,25,375,37,375,40);
                context.stroke();
                //框框渐变
                for(var i=0;i<6;i++)
                {
                    for(var j=0;j<6;j++)
                    {
                        context.fillStyle='rgb('+Math.floor(255-42.5*i)+','+Math.floor(255-42.5*j)+',0)';
                        context.fillRect(j*25+400,i*25+400,25,25);
                    }
                }
                //圈圈渐变
                for(i=0;i<6;i++)
                {
                    for(j=0;j<6;j++)
                    {
                        context.strokeStyle='rgb('+Math.floor(255-42.5*i)+','+Math.floor(255-42.5*j)+',0)';
                        context.beginPath();
                        context.arc(500+i*25,12.5+j*25,10,0,Math.PI*2,true);
                        context.stroke();
                    }
                }
                
                window.addEventListener("load",drawDiagonal,ture);
            }
        </script>
    </head>
    <body>
        <canvas id="1" style="border: 1px solid skyblue" width="800" height="600">恩?
            <script>
                draw();
            </script>
        </canvas>
    </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值