Draw a 150*100 pixels rectangle:
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="180" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.strokeRect(20, 20, 150, 100);// ww w.j a va2 s . co m </script> </body> </html>
The strokeRect()
method draws a rectangle (no fill).
The default color of the stroke is black.
Use the strokeStyle property to set a color, gradient, or pattern to style the stroke.
context.strokeRect(x, y, width, height);
Parameter Values
Parameter | Description |
---|---|
x | The x-coordinate of the upper-left corner of the rectangle |
y | The y-coordinate of the upper-left corner of the rectangle |
width | The width of the rectangle, in pixels |
height | The height of the rectangle, in pixels |