fill method

The fill method fills a shape drawn via the lineTo, rect, arc methods and so on.

Syntax

javascriptcontext.fill();

Example

We draw a square and fill it with fill:

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

ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(150, 50);
ctx.lineTo(150, 150);
ctx.lineTo(50, 150);
ctx.fill();

Результат:

See also

  • the fillStyle property
    that sets a fill color
  • the stroke method
    that creates a stroke