HTML5 Game - Simple rotation transformation

Description

Simple rotation transformation

Demo

ResultView the demo in separate window

<!DOCTYPE html>  
<html> 
<head> 
<style> 
#canvas { /*w  w w . j a v  a  2s  . c  o  m*/
  border:1px solid #03F; 
  background:#CFC; 
} 
</style> 
</head> 
<body> 
<canvas id="canvas" width="640" height="480"></canvas> 
<script> 
  let context = document.getElementById('canvas').getContext('2d'); 
    
      //now draw a red square 
      context.setTransform(1,0,0,1,0,0); 
      let angleInRadians = 45 * Math.PI / 180; 
      context.rotate(angleInRadians); 
      context.fillStyle = "red"; 
      context.fillRect(100,100,50,50); 



</script> 



</body> 
</html>

Related Topic