How to use fillStyle() and set color with RGB(red, green, blue) to draw a rectangle on canvas in JavaScript

1 Answer

0 votes
<canvas id="canvas" width="1024" height="600"></canvas>
<script type="text/JavaScript">   

var ctx = document.getElementById('canvas').getContext('2d');
 
// red color 
ctx.fillStyle = 'rgb(' + 255 + ',' + 0 + ',' + 0 + ')';
ctx.fillRect(10, 10, 90, 120);
 

</script>

 



answered May 26, 2016 by avibootz
edited May 26, 2016 by avibootz
...