.png)
paintJS์ ๊ธฐ๋ฅ ์ค ์ค์ํ ๊ธฐ๋ฅ์ผ๋ก, canvas ์ ์ฒด๋ฅผ ์ํ๋ ์์์ผ๋ก ์ฑ์๋ฃ๋ fill ๊ธฐ๋ฅ์ ์ถ๊ฐํ์๋ค.
canvas์ ๊ณต์๋ฌธ์๋ฅผ ํตํด ํ์ธํ๋ฉด, CanvasRenderingContext2D๋ถ๋ถ์ fill and stroke styles ํญ๋ชฉ์์ fillStyle์ ์ง์ ํ ์ ์๋ค๋ ์ ์ ํ์ธํ ์ ์๋ค. ๋ฐ๋ผ์, strokeStyle๊ณผ ๊ฐ์ ์์์ ํ๋๋ก ์ง์ ํด์ฃผ์ด์ผํ๊ณ , fillRect() ํจ์๋ฅผ ํตํด์ canvas๋ฅผ ์ฑ์ธ ๊ฒ์ด๊ธฐ ๋๋ฌธ์, ๊ธฐ๋ณธ strokeStyle๊ฐ๊ณผ canvas.width,canvas.heigth์ ๊ฐ์ธ INITIAL_COLOR์ CANVAS_SIZE์ ๊ฐ์ ๊ฐ๊ฐ "#2c2c2c"์ 500์ผ๋ก ์ ์ธํด์ฃผ์๋ค. ๋ํ ์ด๊ธฐ์ ctx.fillStyle = INITIAL_COLOR; ๊ฐ์ผ๋ก ์ ์ํด์ฃผ์๋ค.
๊ธฐ์กด์ handleColorClickํจ์๋ ์ฌ์ฉ์๊ฐ ์์ div๋ฅผ ํด๋ฆญํ๋ ๊ฒฝ์ฐ ctx.strokeStyle์ ํด๋น ์์ ๊ฐ์ผ๋ก ํต์ผ์์ผ์ฃผ๋ ๋ด์ฉ์ ํจ์์์ผ๋, fill ๋ชจ๋์ ์ถ๊ฐ๋ฅผ ์ํด์ ctx.fillStyle์ ๊ฐ ๋ํ ํด๋น ์์ ๊ฐ์ผ๋ก ํต์ผ์์ผ์ฃผ๋๋ก ํ์๋ค.
๊ธฐ์กด์ handleModeClick์ filling์ ๊ฐ์ true ํน์ false๋ก ๋ฐ๊พธ์ด์ฃผ๊ณ , ํด๋น button์ innerText๋ฅผ ๋ณ๊ฒฝํด์ฃผ๋ ๊ฒ์ ๊ทธ์ณค์ผ๋, filling์ด true๊ฐ ๋๋ ๊ฒฝ์ฐ, ctx.fillStyle์ ๊ฐ์ ํ์ฌ ctx.strokeStyle์ ๊ฐ๊ณผ ๊ฐ๊ฒ ํ๋๋ก ํ์๋ค.
canvas.addEventListener("click", handleCanvasClick);
๋ฅผ ํตํด ์ถ๊ฐ๋ handleCanvasClickํจ์๋ canvas์ "click" ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ ๊ฒฝ์ฐ if(filling)์ ํตํด filling์ true์ฌ๋ถ๋ฅผ ํ์ธํ๊ณ ๋ง์ฝ true์ธ ๊ฒฝ์ฐ,
ctx.fillRect(0,0,CANVAS_SIZE,CANVAS_SIZE);
๋ฅผ ํตํด canvas๋ฅผ fillStyle์ ์์์ผ๋ก ์น ํด์ฃผ์๋ค. 0,0์ ํด๋น canvas์์์ ์์น๋ฅผ ์๋ฏธํ๊ณ , CANVAS_SIZE,CANVAS_SIZE๋ ์์น ๋๋ Rect์ ๊ฐ๋ก์ ์ธ๋ก์ ๊ธธ์ด (width & height) ๋ฅผ ์๋ฏธํ๋ค. ๋ฐ๋ผ์, 0,0์์์ CANVAS_SIZE๋งํผ์ ๊ธธ์ด๋ฅผ ๊ฐ๋ Rect๋ ์ ์ฒด canvas๋ฅผ ์๋ฏธํ๊ฒ ๋๋ค.
