K
K
kirillDu2021-02-04 09:27:17
Canvas
kirillDu, 2021-02-04 09:27:17

canvas js. How to clear the canvas?

When the button is clicked, a curved line is drawn in the canvas.
How to make it so that when the button is pressed again, the canvas is cleared and the line is drawn again

HTML


JS

let canvas = document.getElementById("cnvs")
let ctx = canvas.getContext('2d');
let LengthLinii = (rand * 100) * 1.5;
let linRelomlenia = LengthLinii / 2;
let visotaGrafika = 300 - ((rand * 100) * 1.5);

ctx.moveTo(0, 280);
ctx.strokeStyle = "#bc9109";
ctx.linewidth = 5;
ctx.shadowColor = "#bc9109";
ctx.shadowOffsetX = 30;
ctx.shadowOffsetY = 60;
ctx.shadowblur = 80;
ctx.quadraticCurveTo(linRelomlenia, 270, DlinaLinii, visotaGrafika)
ctx.stroke();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question