开发者

How to set color to Rectangle drawn with html5?

开发者 https://www.devze.com 2023-01-04 21:50 出处:网络
I\'m learning about Html5. <html> <body> <canvas id=\"canvas1\" width=\"300\" height=\"200\"></canvas>

I'm learning about Html5.

<html>
<body>
<canvas id="canvas1" width="300" height="200"></canvas>
<script>
 var canvas = document.getElementById("canvas1");
 v开发者_Python百科ar cxt = canvas.getContext("2d");

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

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

How to set color for this Rectangle?


ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect(0, 0, 150, 100);

fillStyle must be called before fillRect

And if you're not already using it:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消