Metod stroke

Metod stroke xetti cizdirmeyi tamamlamaq ucun lineTo ile birlikde istifade edilir, hemcinin rect kimi metodlarla cizilen formaları konturla cizmek ucun istifade olunur.

Sintaksis

javascriptkontekst.stroke()

Nümunə

Gelin bir xett cizek:

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

Результат:

Nümunə

Gelin bir kvadrat cizek:

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.closePath();
ctx.stroke();

Результат:

Həmçinin bax

  • metod fill,
    forma arxaplan rəngi ile doldurmaq ucun istifade olunur
  • xüsusiyyət strokeStyle,
    xettin rəngini təyin edir