-
Notifications
You must be signed in to change notification settings - Fork 2
/
snaptut-grouptransform.html
73 lines (51 loc) · 2.2 KB
/
snaptut-grouptransform.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<title>Snap.svg Tutorial</title>
<script src="analytics.js"></script>
</head>
<body>
<link href="/snapstyle.css" rel="stylesheet">
<div id="container"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="snap.svg.js"></script>
<a href="http://snapsvg.io/docs/">Snap Docs</a> <a href="/">More SVG Dabbles</a>
<article>
<h1 class="heading">Snap transforms</h1>
<div class="intro">Time to get used to transforms...transforms are combined and affect a 'matrix. If you look at the markup at the bottom when run, you will see some transform 'matrix'. These are the combined transforms in one lump.</div>
<pre class="codestuff"><code contenteditable="true">
var s = Snap("#svgout");
var c = s.circle( 200,200,10 );
//var r = s.rect(200,100,100,100,20,20).attr({ stroke: '#123456', 'strokeWidth': 20, fill: 'red', 'opacity': 0.3 });
var r = s.polyline(20,20,200,200).attr({ stroke: '#123456', 'strokeWidth': 20, fill: 'blue', 'opacity': 0.3 });
var p = s.polyline(10,10,100,100).attr({ stroke: '#123456', 'strokeWidth': 20, fill: 'blue', 'opacity': 0.3 });
var g = s.group( r, p);
gclone = g.clone();
gclone2 = g.clone();
gclone3 = g.clone();
gclone4 = g.clone();
gclone5 = g.clone();
//t=relative transform, T=absolute transform, s=relative scale, S=absolute Scale
//r=relative rotate, R=relative rotate
//relative means it takes into account previous transforms to accumulate
//here it doesn't make much difference, until we combine later
gclone.transform( 't100,100');
gclone2.transform( 'r20,200,200' );
gclone3.transform( 'r40,200,200' );
s.text(350,150,"rotate around 200,200");
gclone2.transform( 't100,100r20,200,200' );
g.transform( 't100,100r40,200,200' );
s.text(450,250,"combined translate of 100,100 and rotate around 200,200");
</code>
<button class="run">Edit/Run</button>
</pre>
</article>
<div class="intro">SVGout area...</div>
<div class="output">
<svg id="svgout" width="400" height="400"></svg>
</div>
<div class="intro">The actual svg markup looks like this (when you've clicked on run)....</div>
<div id="htmlraw"></div>
<script src="snaptut.js"></script></script>
<script src="hijs.js"></script>
</body>