Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (38 sloc) 1016 Bytes
<!doctype html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>画三角形</title>
<style type="text/css">
body{background: black}
#c1{background:white;}
span{color:white;}
</style>
</head>
<body>
<canvas id="c1" width="400" height="400">
<span>不支持canvas的浏览器就会显示</span>
</canvas>
<script type="text/javascript">
window.onload = function(){
var oc = document.getElementById('c1');
var content = oc.getContext('2d');
content.save();//局部作用效果
content.fillStyle = 'red';
content.beginPath();//beginPath()不写的时候可能会出错,所以确保beginPath和closePath都相对应
content.moveTo(100,100);
content.lineTo(200,200);
content.lineTo(300,200);
content.closePath();
content.fill();
content.restore();
content.beginPath();
content.moveTo(100,200);
content.lineTo(200,300);
content.lineTo(300,300);
content.closePath();
content.fill();
}
</script>
</body>
</html>
You can’t perform that action at this time.