簡単な家を描くことになっているこのコードがありますが、実行しても何も表示されず、何かが間違っているという警告も表示されません。誰もが理由を知っていますか?
function onLoad()
{
var canvas;
var context;
function initialise ()
{
canvas = document.getElementById('canvas');
if (!canvas)
{
alert('Error: I cannot find the canvas element!');
return;
}
if (!canvas.getContext)
{
alert('Error: no canvas.getContext!');
return;
}
context = canvas.getContext('2d');
if (!context)
{
alert('Error: failed to getContext!');
return;
}
}
function draw()
{
context.beginPath();
context.moveTo(150,100);
context.lineTo(250,200);
context.lineTo(250,300);
context.lineTo(50,300);
context.lineTo(50,200);
context.lineTo(150,100);
context.closePath();
context.stroke();
}
initialise();
draw();
}