fillStyle 속성
fillStyle 속성은 canvas에 도형을 그릴 때
채우기 색상을 설정합니다. 속성 값은
CSS 색상 단위를
사용할 수 있습니다.
문법
컨텍스트.fillStyle = 색상;
예제
rect를 사용하여
사각형을 그리고 빨간색으로 채워 보겠습니다:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
ctx.rect(50, 50, 100, 100);
ctx.fillStyle = 'red';
ctx.fill();
:
함께 보기
-
선 색상을 설정하는 메서드
strokeStyle