Properti fillStyle

Properti fillStyle mengatur warna isian bentuk saat menggambar pada canvas. Nilai dari properti ini adalah satuan CSS untuk warna apa pun.

Sintaks

javascriptkonteks.fillStyle = warna;

Contoh

Mari gambar sebuah persegi menggunakan rect dan isi dengan warna merah:

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();

Результат:

Lihat juga