-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex3.html
222 lines (181 loc) · 6.62 KB
/
index3.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Roller Derby Track</title>
<script type="text/javascript" src="js/jquery-1.6.2.min.js" ></script>
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script src="lib/jquery.svg.min.js"></script>
<style type="text/css" media="screen">
body { margin:0; background:#fc0;}
#track1 {
background:#fff;
width:640px;
height:480px;
margin:0 auto;
}
</style>
</head>
<body>
<svg id="track1" viewBox="0 0 90 56" preserveAspectRatio="xMidYMid meet" version="1.1" xmlns="http://www.w3.org/2000/svg">
<style type="text/css">
.skater { stroke-width:0.1px; stroke:#fff; }
.a-team { fill:#c00 }
.b-team { fill:#00c }
.track, .jammer-line, .pivot-line { fill:#ccc; stroke:#666; stroke-width:0.5px; }
text { font-family:sans-serif; font-size:1px; fill:#999 }
.reset { font-size:3px; }
a { fill:#77c; }
a:hover { fill:#009; }
</style>
<g transform="translate(45,28)">
<path class="track"
d="
M17.5,26.5
A26.5,26.5 0 0 0 17.5,-26.5
L-17.5,-26.5
A26.5,26.5 0 0 0 -17.5,26.5
L17.5,26.5
M-17.5,11.5
A1,1 0 0 1 -17.5,-12.5
L17.5,-11.5
A1,1 0 0 1 17.5,12.5
L-17.5,11.5
z
" />
<!-- Center points for outer boundary -->
<!--
<circle cx="17.5" cy="0" r="0.5" />
<circle cx="-17.5" cy="0" r="0.5"/>
-->
<!-- These start lines are perpendicular to the outside boundary, which isn't WFTDA standard -->
<!--
<line x1="17.5" y1="26.5" x2="17.5" y2="12.5" class="pivot-line" />
<line x1="-12.5" y1="26.5" x2="-12.5" y2="11.5" class="jammer-line" />
-->
<!-- Center points for inner boundary -->
<!--
<circle cx="17.5" cy="1" r="0.5" />
<circle cx="-17.5" cy="-1" r="0.5"/>
-->
<!-- Center line inner boundary -->
<!--
<line x1="17.5" y1="1" x2="-17.5" y2="-1" stroke="#ccc" stroke-width="1" />
-->
<!--
These lines are perpendicular to the inside boundary
-->
<g transform="rotate(3.27)">
<line x1="17.5" y1="25.5" x2="17.5" y2="11.5" class="pivot-line" />
<line x1="-12.5" y1="27.3" x2="-12.5" y2="12.5" class="jammer-line" />
</g>
</g>
<g class="skater a-team jammer">
<circle cx="0" cy="0" r="1.5" />
<path transform="translate(-1.5,-1.5) scale(0.0023)" fill="#fff" d="M0,449h1235l-999,726 382-1175 382,1175z"/>
</g>
<g class="skater a-team pivot">
<circle cx="0" cy="0" r="1.5" />
<rect x="-1.5" y="-0.2" width="3" height="0.4" fill="#fff" />
</g>
<g class="skater a-team blocker"><circle cx="0" cy="0" r="1.5" /></g>
<g class="skater a-team blocker"><circle cx="0" cy="0" r="1.5" /></g>
<g class="skater a-team blocker"><circle cx="0" cy="0" r="1.5" /></g>
<g class="skater b-team jammer">
<circle cx="0" cy="0" r="1.5" />
<path transform="translate(-1.5,-1.5) scale(0.0023)" fill="#fff" d="M0,449h1235l-999,726 382-1175 382,1175z"/>
</g>
<g class="skater b-team pivot">
<circle cx="0" cy="0" r="1.5" />
<rect x="-1.5" y="-0.2" width="3" height="0.4" fill="#fff" />
</g>
<g class="skater b-team blocker"><circle cx="0" cy="0" r="1.5" /></g>
<g class="skater b-team blocker"><circle cx="0" cy="0" r="1.5" /></g>
<g class="skater b-team blocker"><circle cx="0" cy="0" r="1.5" /></g>
<text x="80" y="4" class="reset">
<a xlink:href="#">reset</a>
</text>
<text x="2" y="59" class="copyright">
<a xlink:href="http://github.com/aubergene/roller-derby-track">© 2011 Julian Burgess</a>.
Injustice Code at <a xlink:href="http://gothamgirlsrollerderby.com">Gotham Girls Roller Derby</a>
</text>
</svg>
</body>
<script type="text/javascript" charset="utf-8">
var teamsize = 10;
var defaultPositions = ["29.90:43.40", "59.40:51.43", "54.45:48.81", "56.85:42.70", "57.60:48.77", "29.50:50.26", "60.10:43.03", "55.75:52.03", "58.45:45.64", "53.80:45.83"];
var skaters;
var track1 = $('#track1').svg({onLoad: init}).get(0);
function init () {
skaters = $('.skater');
setPositionsFromHash();
makeDraggable();
// console.log(track1);
$('.reset').click(function(e) {
e.preventDefault();
resetPositions();
});
}
function setPositionsFromHash() {
var coord, positions
positions = window.location.hash.substring(1).split(',')
if (positions.length != 10) {
resetPositions();
} else {
setPositions(positions);
}
}
function resetPositions() {
setPositions(defaultPositions);
}
function setPositions(positions) {
$.each(positions, function(i, position) {
coord = position.split(':');
// console.log(coord)
skaters[i].setAttribute('transform','translate(' + coord[0] + ',' + coord[1] + ')');
});
updateFragment();
}
function makeDraggable() {
$('.skater')
.draggable()
.bind('mousedown', function(event, ui){
// bring target to front
// $(event.target.parentElement).append( event.target );
$(event.target.parentElement.parentElement).append( event.target.parentElement );
})
.bind('drag', function(event, ui){
// update coordinates manually, since top/left style props don't work on SVG
var left, top, x_scale, y_scale, viewBoxWidth, viewBoxHeight, svgWidth, svgHeight;
viewBoxWidth = track1.viewBox.baseVal.width
viewBoxHeight = track1.viewBox.baseVal.height
svgWidth = track1.width.baseVal.value;
svgHeight = track1.height.baseVal.value;
x_scale = viewBoxWidth / svgWidth;
y_scale = viewBoxHeight / svgHeight;
left = ui.position.left * x_scale;
top = ui.position.top * y_scale;
$('#positionLeft').text(left);
$('#positionTop').text(top);
// console.log("");
// console.log([viewBoxWidth, viewBoxHeight]);
// console.log([svgWidth, svgHeight]);
// console.log([x_scale, y_scale]);
// console.log([left, top]);
event.target.setAttribute('transform', "translate(" + left + "," + top + ")");
// console.log("left=" + ui.position.left + ", top=" + ui.position.top);
updateFragment();
});
};
function updateFragment() {
var decimal_places = 2;
var positions = [], transform;
$.each(skaters, function(i, skater) {
position = skater.getAttribute('transform').replace('translate(','').replace(')','').split(',');
position = $.map(position, function(val, i) { return parseFloat(val).toFixed(decimal_places) } ).join(':')
positions.push(position);
});
window.location.hash = positions.join(',');
}
</script>
</html>