代码改变世界

八卦图

2017-02-15 09:11  蛋黄月饼  阅读(152)  评论(0编辑  收藏  举报

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>八卦图</title>
</head>
<body>
<canvas id = "canvas" width = "500px" height = "500px"></canvas>
</body>
<script>
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");

context.beginPath();
context.arc(250,250,200,0,Math.PI*2);
context.stroke();

context.beginPath();
context.arc(250,250,200,Math.PI/2,Math.PI*3/2);
context.fill();

context.fillStyle = "white";
context.beginPath();
context.arc(250,150,100,0,Math.PI*2);
context.fill();

context.fillStyle = "black";
context.beginPath();
context.arc(250,350,100,0,Math.PI*2);
context.fill();

context.beginPath();
context.arc(250,150,30,0,Math.PI*2);
context.fill();

context.fillStyle = "white";
context.beginPath();
context.arc(250,350,30,0,Math.PI*2);
context.fill();
</script>
</html>