분류 javascript

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

컨텐츠 정보

  • 조회 940 (작성일 )

본문

HTML :

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Draw a rectangular shape</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.fillRect(20,20,100,100);
    context.clearRect(40,40,60,60);
    context.strokeRect(45,45,50,50);
  }
}