Javascript examples for Canvas Reference:strokeRect
The strokeRect() method draws a rectangle. The default color is black.
context.strokeRect(x, y, width, height);
Parameter | Description |
---|---|
x | The x-coordinate of the upper-left corner |
y | The y-coordinate of the upper-left corner |
width | The width of the rectangle, in pixels |
height | The height of the rectangle, in pixels |
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="250" 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);//from www . ja v a 2s. c o m </script> </body> </html>