-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMDN_05. Scale().html
48 lines (41 loc) · 1.15 KB
/
MDN_05. Scale().html
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
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<title>Scale() example</title>
</head>
<body>
<canvas id="canvas" width="800" height="500" style="border: 2px solid blue">Canvas not supported</canvas>
<script type="text/javascript">
var ctx = document.getElementById('canvas').getContext('2d');
let catImg = new Image();
catImg.src = "theCat.png";
function draw() {
// draw a simple rectangle, but scale it.
ctx.save();
ctx.translate(0,0);
ctx.scale(1, 10);
ctx.fillRect(0,22,10,10);
ctx.restore();
// mirror horizontally
ctx.save();
ctx.scale(-1, 1);
ctx.font = "48px serif";
ctx.fillText("MDN", -135, 220);
ctx.restore();
//cat 1 original right side
ctx.save();
ctx.translate(0,0);
ctx.scale(1,1);
ctx.drawImage(catImg,0,0,800,729,200,0,160,144);
ctx.restore();
//cat 2 transform to left side
ctx.save();
ctx.translate(370,0);
ctx.scale(-1,1);
ctx.drawImage(catImg,0,0,800,729,0,150,160,144);
ctx.restore();
}
draw();
</script>
</body>
</html>