rough-stuff / rough

Create graphics with a hand-drawn, sketchy, appearance
http://roughjs.com
MIT License
19.83k stars 613 forks source link

How to clear the canvas? #175

Closed ghost closed 3 years ago

ghost commented 3 years ago

image image

I want to clear the rectangle drawn before, but it says ‘rc.clearRect is not a function’

ghost commented 3 years ago

image Probably to use 'rc.ctx'?

pshihn commented 3 years ago

rc.ctx is not a documented property so you should not rely on that.

you have the reference to the canvasElement and can get the context yourself. In your code, you have the canvasEle

const canvasEle = document.getElementById('canvas');
const ctx = canvasEle.getContext('2d');
ctx.clearRect(.....)