fillStyle ගුණය

fillStyle ගුණය මගින් canvas හි අඳින රූපයක් පිරවීමේ වර්ණය සකසයි. මෙම ගුණයේ අගය වන්නේ ඕනෑම CSS වර්ණ ඒකක වේ.

වාක්‍ය රීතිය

javascriptcontext.fillStyle = color;

උදාහරණය

අපි දැන් rect ක්‍රමය භාවිතා කර චතුරස්‍රයක් අඳිමු සහ එය රතු වර්ණයෙන් පුරවමු:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');

ctx.rect(50, 50, 100, 100);
ctx.fillStyle = 'red';
ctx.fill();

Результат:

මෙයද බලන්න

  • strokeStyle ක්‍රමය,
    යම් රේඛාවක වර්ණය සකසයි