Mirror an element on the HTML5 canvas

Example of how you can mirror an element on the HTML5 canvas.
<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
    </style>
  </head>
  <body>
    <canvas id="myCanvas" width="600" height="300"></canvas>
    <script>
        
    var txt = 'Hello Tizen!';

    var canvas = document.getElementById('myCanvas'); 
    var ctx = canvas.getContext('2d'); 
    
        ctx.translate(canvas.width / 2, canvas.height / 2);

        ctx.scale(-1,-1); // negative values mirror in both X and Y axis
        
        ctx.font = '35pt Arial Bold';
        ctx.textAlign = 'center';
        ctx.fillStyle = 'red';
        ctx.fillText(txt, 0, 0);
       
   </script>
  </body>
</html>     

Responses

0 Replies