Prev Demo
HTML Canvas
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title> Canvas translate </title> </head> <body> <canvas id="myCanvas" width="200" height="150" style="border:5px dotted green;"> </canvas> <script> var a = document.getElementById("myCanvas"); var b = a.getContext("2d"); b.fillStyle = "yellow"; b.fillRect(10, 10, 100, 100); b.translate(40, 30); b.fillStyle = "blue"; b.fillRect(10, 10, 100, 100); </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output