Javascript examples for Canvas:image
image rotation with dynamic values and images
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> $(window).load(function(){/*from w w w .ja v a2 s . c om*/ var can = document.getElementById('canvas1'); var context = can.getContext('2d'); for(var i = 0; i < 9; i++){ tmpTreeX = 1+Math.random()*(can.width-95); tmpTreeY = 1+Math.random()*(can.height-90); var imgTreeFile = new Image(); context.save(); context.translate(tmpTreeX,tmpTreeY); context.rotate(47 * Math.PI / 180); context.translate(-tmpTreeX,-tmpTreeY); context.fillRect(tmpTreeX, tmpTreeY, 95, 90); context.restore(); } }); </script> </head> <body> <canvas id="canvas1" width="500" height="500"></canvas> </body> </html>