forked from hehos/javascriptAdvanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2DSaveRestoreExample01.htm
More file actions
executable file
·39 lines (29 loc) · 1.28 KB
/
Copy path2DSaveRestoreExample01.htm
File metadata and controls
executable file
·39 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html>
<head>
<title>Canvas Save-Restore Example</title>
</head>
<body>
<canvas id="drawing" width="200" height="200">Your browser doesn't support the canvas tag.</canvas>
<script type="text/javascript">
window.onload = function(){
var drawing = document.getElementById("drawing");
//make sure <canvas> is completely supported
if (drawing.getContext){
var context = drawing.getContext("2d");
context.fillStyle = "#ff0000";
context.save();
context.fillStyle = "#00ff00";
context.translate(100, 100);
context.save();
context.fillStyle = "#0000ff";
context.fillRect(0, 0, 100, 200); //draws blue rectangle at (100, 100)
context.restore();
context.fillRect(10, 10, 100, 200); //draws green rectangle at (110, 110)
context.restore();
context.fillRect(0, 0, 100, 200); //draws red rectangle at (0,0)
}
};
</script>
</body>
</html>