W3Schools.com

HTML5 canvas setTransform Method

HTML5 track Tag Reference HTML5 canvas reference

Example

Draw a rectangle, rotate the canvas by using the setTransform method, and draw a rectangle again:

Yor browser does not support the canvas tag.

JavaScript:

...
ctx.font="30px Arial";
ctx.fillText("Transform",10,30);
ctx.setTransform(0.93,0.3,-0.3,0.93,0,0);
ctx.fillStyle="lightblue";
ctx.fillRect(0,0,250,100)
...

Try it yourself »

Definition and Usage

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.

Differences between setTransform and transform

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);


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The setTransform method is supported in all major browsers.


Parameter Values

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 »

HTML5 track Tag Reference HTML5 canvas reference


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