Draw a rectangle, rotate the canvas by using the setTransform method, and draw a rectangle again:
JavaScript:
The transform method uses a matrix to change the form of the canvas.
The transform method lets you scale, rotate, move, and skew the canvas.
The transformation will only affect drawings made after the transform method is called.
The transform method takes six parameters, representing the matrix.
The transform method behaves relatively to other transformations made by the rotate, scale, or translate methods. I.e. if you have allready set your drawing to scale by two, and the transform method scales your drawings by two, your drawings will now scale by four.
The setTransform method does not behave relatively to other transformations.
| JavaScript syntax: | context.setTransform(a,b,c,d,e,f); |
|---|
![]()
The setTransform method is supported in all major browsers.
| Parameter | Values | Description | Play it |
|---|---|---|---|
| a | scale-x | Scales the drawings horizontally | Play it » |
| b | skew-x | Skew the the drawings horizontally | Play it » |
| c | skew-y | Skew the the drawings vertically | Play it » |
| d | scale-y | Scales the drawings vertically | Play it » |
| e | translate-x | Moves the the drawings horizontally | Play it » |
| f | translate-y | Moves the the drawings vertically | Play it » |
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $3.98 Unlimited Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| Download XML Editor |
| FREE Website BUILDER |
| Best Website Templates Top CSS Templates |
| CREATE HTML Websites |
| EASY WEBSITE BUILDER |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|