HTML 캔버스 히며 closePath () 메소드
예
문자 L의 형태로 경로를 그린 다음 시작 지점으로 돌아 선을 그릴 :
자바 스크립트 :
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
»시도
브라우저 지원
인터넷 익스플로러 9, 파이어 폭스, 오페라, 크롬과 사파리 지원 히며 closePath () 메소드.
참고 : 인터넷 익스플로러 8 이전 버전의 <캔버스> 요소를 지원하지 않습니다.
정의 및 사용
히며 closePath () 메소드는 시작점 현재 지점에서 경로를 만들 수 있습니다.
팁 : 사용 스트로크 () 캔버스에 정확한 경로를 그리는 방법을.
팁 : 사용 채우기 () (기본값은 검은 색) 이미지를 채울 방법을. 사용 fillStyle에서는의 다른 색상 / 그라데이션을 채우는 속성을.
자바 스크립트 구문 : | 컨텍스트 .closePath (); |
---|
더 많은 예제
예
빨간색으로 채우기 색으로 :
자바 스크립트 :
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
ctx.fillStyle="red";
ctx.fill();
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
ctx.fillStyle="red";
ctx.fill();
»시도
HTML 캔버스 참조 설명서