canvas基础练习

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>canvas</title>
<style>
body{
	background:#808080;
}

#canvas{
	background:#ffffff;
}
</style>
<script>
window.onload = function(){
    //获取canvas元素
    var canvas = document.getElementById('canvas');     
    //获取2d绘图环境
    var cxt = canvas.getContext('2d');      

    cxt.fillRect(1,1,50,50);
    cxt.strokeRect(51,51,50,50);
    cxt.fillRect(101,101,50,50);
    cxt.strokeRect(150,150,50,50);
    cxt.fillRect(200,200,50,50);
    cxt.fillRect(250,250,50,50);
    cxt.strokeRect(300,300,50,50);
    cxt.fillRect(350,350,50,50);
    cxt.fillRect(448,448,50,50);
    cxt.strokeRect(399,399,50,50);

    cxt.strokeRect(448,2,50,50);
    cxt.fillRect(399,51,50,50);
    cxt.strokeRect(349,101,50,50);
    cxt.fillRect(299,151,50,50);
    cxt.strokeRect(250,201,49,49);
    cxt.strokeRect(201,250,49,49);
    cxt.fillRect(151,299,50,50);
    cxt.strokeRect(101,349,50,50);
    cxt.fillRect(51,399,50,50);
    cxt.strokeRect(2,448,50,50);
}
</script>
</head>
<body>
<canvas id="canvas" width="500" height="500">您的浏览器不支持canvas元素</canvas>
</body>
</html>


效果图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值