script.js
window.addEventListener('load', function(){
const cs = document.getElementById('myCanvas'),
ctx = cs.getContext('2d'),
csWidth = cs.width,
csHeight = cs.height,
center = {
x: csWidth / 2,
y: csHeight / 2
};
// 横線の定義
const horizontal_line = function() {
ctx.beginPath();
ctx.lineWidth = 1; // 線の太さ
ctx.strokeStyle = 'blue'; // 線の色
ctx.moveTo(0, center.y);
ctx.lineTo(csWidth, center.y);
ctx.closePath();
ctx.stroke();
};
horizontal_line();
// 縦線の定義
var vertical_line = function() {
ctx.beginPath();
ctx.lineWidth = 10; // 線の太さ
ctx.strokeStyle = 'red'; // 線の色
ctx.moveTo(center.x, 0);
ctx.lineTo(center.x, csHeight);
ctx.closePath();
ctx.stroke();
};
vertical_line();
})