How can I clear an arc or circle in HTML5 canvas?

后端 未结 6 1976
谎友^
谎友^ 2021-02-04 02:06

I found that there\'s a clearRect() method, but can\'t find any to clear an arc (or a full circle).

Is there any way to clear an arc in canvas?

6条回答
  •  迷失自我
    2021-02-04 02:34

    This is a circular equivalent of clearRect(). The main thing is setting up a composite operation per @moogoo's answer.

    var cutCircle = function(context, x, y, radius){
        context.globalCompositeOperation = 'destination-out'
        context.arc(x, y, radius, 0, Math.PI*2, true);
        context.fill();
    }
    

    See https://developer.mozilla.org/samples/canvas-tutorial/6_1_canvas_composite.html:

提交回复
热议问题