The difference between cavas fill () and fillrect ()


            var odiv1=document.getElementById("csn")
            var ctx=odiv1.getContext("2d")
            ctx.rect(20,20,150,100);
            ctx.fill();
            ctx.fillRect(40,40,100,100);
            
        </script>
    </body>

ask the gods the difference between fill () and fillrect () except for calling the display on the canvas. What"s the difference? You"d better give an example.

Jan.08,2022

fillRect (x, y, width, height)
draw a filled rectangle
fill ()
to generate a solid graph by filling the content area of the path.

reference:
https://developer.mozilla.org.


fillRect can be decomposed into
rect (x br y, width, height)
fill ();

).

fill () is a lower-level method. FillRect is only used to draw filled rectangles, and fill is used to fill any closed path. For example, arc () circles can also be drawn

.
Menu