图片
<
let ctx = canvas.getContext('2d');
let painting = false
ctx.fillStyle = 'green';
canvas.onmousedown = () => {
painting = true
}
canvas.onmousemove = (e) => {
if (painting === true) {
ctx.fillRect(e.clientX - 5, e.clientY - 25, 10, 10);
} else {
console.log(什么都不做)
}
}
canvas.onmouseup = () => {
painting = false
}
</script>
</body>