분류 javascript

직각 삼각형을 그리는 JavaScript 프로그램을 작성하십시오.

컨텐츠 정보

  • 조회 886 (작성일 )

본문

HTML :

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Draw a right-angled triangle</title>
</head>
<body onload="draw();">
<canvas id="canvas" width="150" height="150"></canvas>
</body>
</html>


JS :

function draw() 
{
  var canvas = document.getElementById('canvas');
  if (canvas.getContext)
  {
    var context = canvas.getContext('2d');

    context.beginPath();
    context.moveTo(75,75);
    context.lineTo(10,75);
    context.lineTo(10,25);
    context.fill();
  }
}