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を定義
// パスの開始
ctx.beginPath();
// 図形1の描画
ctx.moveTo(10, 10);
ctx.lineTo(60, 60);
// パスを線で描画する
ctx.stroke();
</script>
</body>
</html>
画面にアクセスすると、座標(10, 10)から(60, 60)へ直線が描画されます。