Last active
March 1, 2017 01:32
-
-
Save vsaravanan/106fa3786c6091c01170caf4ce37aef1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<canvas id="canvas" width="150" height="150"></canvas> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function draw() { | |
var ctx = document.getElementById('canvas').getContext('2d'); | |
ctx.fillRect(0, 0, 150, 150); // Draw a rectangle with default settings | |
ctx.save(); // Save the default state | |
ctx.fillStyle = '#09F'; | |
ctx.fillRect(15, 15, 120, 120); | |
ctx.save(); // Save the current state | |
ctx.fillStyle = '#FFF'; // Make changes to the settings | |
ctx.globalAlpha = 0.5; | |
ctx.fillRect(30, 30, 90, 90); | |
ctx.restore(); // Restore previous state | |
ctx.fillRect(45, 45, 60, 60); | |
ctx.restore(); // Restore original state | |
ctx.fillRect(60, 60, 30, 30); | |
}draw(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment