canvas – 線の描画
canvasで線を描画します。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>テストHTML</title>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
// canvasのDOMを取得
const canvas = document.getElementById('canvas');
// getContextメソッドでコンテキストを取得
// ここでは2次元の平面的な図形を扱うので、引数に「2d」を指定
const ctx = canvas.getContext('2d');
// コンテキストのstyleを定義(背景色: グレー、大きさ: 150の正方形)
ctx.beginPath();
ctx.moveTo(100, 100);
ctx.lineTo(10, 10);
ctx.lineTo(20, 80);
ctx.fill();
</script>
</body>
</html>