代码改变世界

我的前端房子

2018-11-29 17:24  西欧  阅读(249)  评论(0编辑  收藏  举报
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script type="application/javascript">
function draw() {
var canvas = document.getElementById('canvas');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');


ctx.fillStyle = 'rgb(200, 0, 0)';
ctx.fillRect(70, 70, 50, 50);

/*ctx.fillStyle = 'rgba(0, 0, 200, 0.5)';
ctx.fillRect(90, 90, 50, 50);*/

ctx.beginPath();
ctx.moveTo(100, 40);
ctx.lineTo(70, 70);
ctx.lineTo(120, 70);
ctx.fill();

}
}
/* function draw() {
var canvas = document.getElementById('canvas');
if (canvas.getContext) {
var ctx = canvas.getContext('2d');

ctx.beginPath();
ctx.moveTo(75, 50);
ctx.lineTo(100, 75);
ctx.lineTo(100, 25);
ctx.fill();
}
}*/
</script>
</head>
<body onload="draw();">
<canvas id="canvas" width="150" height="150"></canvas>
</body>
</html>