-
Notifications
You must be signed in to change notification settings - Fork 40
/
box.html
188 lines (166 loc) · 8.45 KB
/
box.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
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title> box | Ractive test</title>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<style>
body {
font-family: "Roboto";
background: white;
}
td {
padding: 1em;
text-align: right;
}
.left {
position: fixed;
left: 40px;
width: 480px;
margin: 0 auto;
}
.right {
position: absolute;
left: 560px;
top: 60px;
}
h1 {
font-size: 3em;
}
h2 {
font-size: 2em;
}
.note {
margin-top: -1.5em;
}
#constraints {
width: 100%;
height: 30em;
font-family: monospace;
}
.num {
font-family: monospace;
width: 40px;
float: right;
padding-top: 5px;
text-align: left;
padding-left: 5px;
}
</style>
</head>
<body>
<div id='ractivecontainer'></div>
<script id='ractivetemplate' type='text/ractive'>
<div class="left">
<h1> box </h1><br><br><br>
<svg width="400" height="400" version="1.1">
<g transform="scale(0.67)">
<g transform="translate(-62.984716,-899.77797)">
<path d="m 312.98455,1149.7784 100.00001,0 0,100 -100.00001,0 z" style="fill:#552baa;fill-opacity:0.75294118;stroke:none" transform="matrix({{plan.scalex * plan.scale}}, 0, 0, {{plan.scaley * plan.scale}}, {{plan.x + 362.984555 * (1-plan.scalex * plan.scale)}}, {{plan.y + 1199.7784 * (1-plan.scaley * plan.scale)}})" class="plan"></path>
<path d="m 312.98455,1049.7783 100.00001,0 0,100.0001 -100.00001,0 z" style="fill:#00d455;fill-opacity:0.75294118;stroke:none" transform="matrix({{top.scalex * top.scale}}, 0, 0, {{top.scaley * top.scale}}, {{top.x + 362.984555 * (1-top.scalex * top.scale)}}, {{top.y + 1099.77835 * (1-top.scaley * top.scale)}})" class="top"></path>
<path d="m 212.98472,1149.7784 100.00002,0 0,100 -100.00002,0 z" style="fill:#0080ff;fill-opacity:0.50196078;stroke:none" transform="matrix({{left.scalex * left.scale}}, 0, 0, {{left.scaley * left.scale}}, {{left.x + 262.98473 * (1-left.scalex * left.scale)}}, {{left.y + 1199.7784 * (1-left.scaley * left.scale)}})" class="left"></path>
<path d="m 312.98455,1249.7782 100.00001,0 0,100 -100.00001,0 z" style="fill:#00d455;fill-opacity:0.75294118;stroke:none" transform="matrix({{bottom.scalex * bottom.scale}}, 0, 0, {{bottom.scaley * bottom.scale}}, {{bottom.x + 362.984555 * (1-bottom.scalex * bottom.scale)}}, {{bottom.y + 1299.7782 * (1-bottom.scaley * bottom.scale)}})" class="bottom"></path>
<path d="m 412.9847,1149.7784 100.00002,0 0,100 -100.00002,0 z" style="fill:#0080ff;fill-opacity:0.50196078;stroke:none" transform="matrix({{right.scalex * right.scale}}, 0, 0, {{right.scaley * right.scale}}, {{right.x + 462.98471 * (1-right.scalex * right.scale)}}, {{right.y + 1199.7784 * (1-right.scaley * right.scale)}})" class="right"></path>
</g>
</g>
</svg>
</div><div class="right">
<table id="controls" style="margin: 0 auto;">
<tr><td>
<h2> bottom </h2></td><td>
scale <input value='{{bottom.scale}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*bottom.scale)/100}}</div><br>
scalex <input value='{{bottom.scalex}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*bottom.scalex)/100}}</div><br>
scaley <input value='{{bottom.scaley}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*bottom.scaley)/100}}</div><br>
x <input value='{{bottom.x}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*bottom.x)/100}}</div><br>
y <input value='{{bottom.y}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*bottom.y)/100}}</div><br>
</td></tr>
<tr><td>
<h2> left </h2></td><td>
scale <input value='{{left.scale}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*left.scale)/100}}</div><br>
scalex <input value='{{left.scalex}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*left.scalex)/100}}</div><br>
scaley <input value='{{left.scaley}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*left.scaley)/100}}</div><br>
x <input value='{{left.x}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*left.x)/100}}</div><br>
y <input value='{{left.y}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*left.y)/100}}</div><br>
</td></tr>
<tr><td>
<h2> plan </h2></td><td>
scale <input value='{{plan.scale}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*plan.scale)/100}}</div><br>
scalex <input value='{{plan.scalex}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*plan.scalex)/100}}</div><br>
scaley <input value='{{plan.scaley}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*plan.scaley)/100}}</div><br>
x <input value='{{plan.x}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*plan.x)/100}}</div><br>
y <input value='{{plan.y}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*plan.y)/100}}</div><br>
</td></tr>
<tr><td>
<h2> right </h2></td><td>
scale <input value='{{right.scale}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*right.scale)/100}}</div><br>
scalex <input value='{{right.scalex}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*right.scalex)/100}}</div><br>
scaley <input value='{{right.scaley}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*right.scaley)/100}}</div><br>
x <input value='{{right.x}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*right.x)/100}}</div><br>
y <input value='{{right.y}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*right.y)/100}}</div><br>
</td></tr>
<tr><td>
<h2> top </h2></td><td>
scale <input value='{{top.scale}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*top.scale)/100}}</div><br>
scalex <input value='{{top.scalex}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*top.scalex)/100}}</div><br>
scaley <input value='{{top.scaley}}' type="range" min="0" max="2" step="0.05"><div class="num">{{Math.round(100*top.scaley)/100}}</div><br>
x <input value='{{top.x}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*top.x)/100}}</div><br>
y <input value='{{top.y}}' type="range" min="-150" max="150" step="1"><div class="num">{{Math.round(100*top.y)/100}}</div><br>
</td></tr>
</table>
<h2> constraints </h2>
<div class="note">access variables by <tt>r.id.attribute</tt>, e.g.:<br> <tt>r.wingrect.scaley = 1 - r. wingtaper.scaley</tt></div>
<textarea id="constraints" onchange="updateCbox();">var w = r.plan.scalex,
h = r.left.scalex,
d = r.plan.scaley,
dw = 50*(w-1),
dh = 50*(h-1),
dd = 50*(d-1)
r.top.scalex = w
r.top.scaley = h
r.top.y = -dh -dd
r.bottom.scalex = w
r.bottom.scaley = h
r.bottom.y = dh + dd
r.left.scalex = h
r.left.scaley = d
r.left.x = -dh - dw
r.right.scalex = h
r.right.scaley = d
r.right.x = dh + dw
</textarea>
</div>
</script>
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>
<script>
var r = {
bottom: {scalex: 1, scaley: 1, scale: 1, x:0, y:0},
left: {scalex: 1, scaley: 1, scale: 1, x:0, y:0},
plan: {scalex: 1, scaley: 1, scale: 1, x:0, y:0},
right: {scalex: 1, scaley: 1, scale: 1, x:0, y:0},
top: {scalex: 1, scaley: 1, scale: 1, x:0, y:0},
}
var cbox = null
var updateCbox = function () {
if (!constraining) {
constraining = true;
try {
eval(cbox.value)
cbox.style.backgroundColor = "#fff"
}
catch(e) { cbox.style.backgroundColor = "#fdd" }
constraining = false;
}
}
var constraining = false;
var ractive = new Ractive({
el: 'ractivecontainer',
template: '#ractivetemplate',
magic: true,
data: r,
onchange: updateCbox
});
var cbox = document.getElementById("constraints")
updateCbox()
</script>
</body>
</html>