HTML5 Game - Canvas Text Reflection

Description

Text Reflection

Demo

ResultView the demo in separate window

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Canvas Demo</title> 
        <style> 
canvas { //w ww .  ja v  a 2 s  . c om
  border: 1px solid #000; 
} 
        </style> 
    </head> 
    <body> 
      <canvas id="myCanvas" width="200" height="200">Did You Know: Every time 
        you use a browser that doesn't support HTML5
      </canvas> 
      <script> 
// Get the context we will be using for drawing. 
let myCanvas = document.getElementById('myCanvas'); 
let myContext = myCanvas.getContext('2d'); 
  
// Draw some text! 
myContext.font = '35px sans-serif'; 
myContext.fillStyle = '#000'; 
myContext.fillText('Hello java2s.com', 10, 100); 

// Set a reflection transform. 
myContext.setTransform(1, 0, 0, -1, 0, 0); 
  
// Set a slight scale transform.  
myContext.scale(1, 1.2); 
  
// Draw the text again with the transforms in place and a light gray fill style. 
myContext.fillStyle = 'rgba(100, 100, 100, 0.4)'; 
myContext.fillText('Hello World', 10, -85); 
      </script> 
    </body> 
</html>

Related Topic