<...">

How to set color to rectangle drawn using html5?

I am learning HTML5.

<html>
<body>
<canvas id="canvas1" width="300" height="200"></canvas>
<script>
 var canvas = document.getElementById("canvas1");
 var cxt = canvas.getContext("2d");

 context.fillRect(0, 0, 150, 100);

</script>
</body>
</html>

How to set color for this rectangle?

+3
source share
1 answer
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect(0, 0, 150, 100);

fillStyle must be called before fillRect

And if you are not using it yet:

https://developer.mozilla.org/en/canvas_tutorial

+4
source

Source: https://habr.com/ru/post/1751717/


All Articles