-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform-tracker.html
More file actions
39 lines (31 loc) · 1.33 KB
/
transform-tracker.html
File metadata and controls
39 lines (31 loc) · 1.33 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>
<body>
<canvas id="my-canvas" width="800" height="600"></canvas>
<script type="text/javascript" src="transform-tracker.js"></script>
<script type="text/javascript">
var canvas = document.getElementById('my-canvas');
var context = canvas.getContext('2d');
// create transform tracker object
context.transform = new Transform(context);
// apply transformations
context.transform.save();
context.transform.translate(200, 0);
context.transform.save();
context.transform.rotate(Math.PI / 4);
context.transform.save();
context.transform.scale(2, 2);
// retrieve current state of transformations
var matrix = context.transform.getMatrix();
console.log('matrix:', JSON.stringify(matrix));
var stack = context.transform.stack;
console.log('stack:', JSON.stringify(stack));
// render
context.fillStyle = 'red';
context.fillRect(0,0,100,100);
context.transform.restore();
context.transform.restore();
context.transform.restore();
</script>
</body>
</html>