<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>canvas</title>
<style type="text/css">
#canvas {
width: 100%;
height: 100%;
/* color: ; */
}
</style>
</head>
<body>
<canvas id="canvas" width="1000" height="500">
</canvas>
</body>
<script>
var mycanvas = document.getElementById('canvas');
var ctx = mycanvas.getContext("2d");
// let id = 1
ctx.beginPath();
ctx.arc(250,100,50,0,2*Math.PI)
ctx.moveTo(250,150);
ctx.lineTo(250,300);
ctx.moveTo(250,180);
ctx.lineTo(100,300);
ctx.moveTo(250,180);
ctx.lineTo(400,300);
ctx.moveTo(250,300);
ctx.lineTo(120,600);
ctx.moveTo(250,300);
ctx.lineTo(380,600);
ctx.closePath();
ctx.fill();
ctx.strokeStyle = "#000000";
ctx.stroke();
// 剑
ctx.beginPath();
ctx.moveTo(400,300);
ctx.lineTo(600,100);
ctx.closePath();
ctx.strokeStyle = "#cccccc"
ctx.stroke()
// 剑柄
ctx.beginPath();
ctx.moveTo(400,300);
ctx.lineTo(380,280);
ctx.lineTo(420,320);
ctx.moveTo(400,300);
ctx.lineTo(360,340);
ctx.closePath();
ctx.strokeStyle = "#666666"
ctx.stroke();
</script>
</html>
火柴人,很无聊,只是学习一下canvas的用法
上结果图