File: draw-image-flip.html

package info (click to toggle)
explorercanvas 0.r4~git20200903.44ac99f-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: javascript: 1,776; makefile: 6
file content (59 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
<title>Scale and translate image test</title>
<style>

body {
  text-align: center
}

</style>
<!--[if IE]><script src="../excanvas.js"></script><![endif]-->
<script>

function draw() {
  var ctx = document.getElementById('c').getContext('2d');
  var s = .25;
  var w = 608 / 2;
  var h = 380 / 2;

  ctx.save();
  ctx.translate(w, 0);
  ctx.scale(s, s);
  ctx.drawImage(img, 0, 0, w / s, h / s);
  ctx.restore();

  ctx.save();
  ctx.translate(w, 0);
  ctx.scale(-s, s);
  ctx.drawImage(img, 0, 0, w / s, h / s);
  ctx.restore();

  ctx.save();
  ctx.translate(w, 2 * h);
  ctx.scale(s, -s);
  ctx.drawImage(img, 0, 0, w / s, h / s);
  ctx.restore();

  ctx.save();
  ctx.translate(w, 2 * h);
  ctx.scale(-s, -s);
  ctx.drawImage(img, 0, 0, w / s, h / s);
  ctx.restore();
};

var img = new Image;
img.onload = draw;
window.onload = function() {
  img.src = '../examples/ff.jpg';
};

</script>
</head>
<body>

<canvas id=c width=608 height=380></canvas>

</body>
</html>