x-coordinate:
y-coodinate:
width:
height:
y-coodinate:
width:
height:
Recently, I discovered how powerful the HTML canvas element is.
You can conviniently draw all kinds of shapes,
make animations or even create games with it.
In the example above, create any kind of rectangle by typing in some values inside the input field. Create the canvas element with canvas. Optionally, define the width and height of it.
A canvas without drawing abilities is not very usefuel. In the JavaScript code we specify what we want to do with it. getContext("2d") allows you to draw lines, rectangles, circles and much more! Get the data of the canvas element with document.getElementById("id of the canvas"), return the object of it with the getContext("2d") method and start drawing.
This time, we want to draw a rectangle so we use the fillRect() method. The syntax is as follows:
fillRect(x-coordinate, y-coordinate, width, height)
The values, typed in by the user, is stored in document.getElementById ("name of id").value. All this is fired with an onclick event. The rectangle is erased with the clerRect() method.
In the example above, create any kind of rectangle by typing in some values inside the input field. Create the canvas element with canvas. Optionally, define the width and height of it.
A canvas without drawing abilities is not very usefuel. In the JavaScript code we specify what we want to do with it. getContext("2d") allows you to draw lines, rectangles, circles and much more! Get the data of the canvas element with document.getElementById("id of the canvas"), return the object of it with the getContext("2d") method and start drawing.
This time, we want to draw a rectangle so we use the fillRect() method. The syntax is as follows:
fillRect(x-coordinate, y-coordinate, width, height)
The values, typed in by the user, is stored in document.getElementById ("name of id").value. All this is fired with an onclick event. The rectangle is erased with the clerRect() method.
No comments:
Post a Comment