-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
181 lines (154 loc) · 5.55 KB
/
index.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
<!DOCTYPE HTML>
<html>
<head>
<title>lego-gears: helping you find gear trains the easy way</title>
<script src="web/jquery-2.1.0.min.js"></script>
<script src="web/fraction.js"></script>
<script src="web/underscore.js"></script>
<script type="text/javascript" src="object-pool.js"></script>
<script src="web/raphael-min.js"></script>
<script src="web/LegoCanvas.js"></script>
<script src="web/worker.js"></script>
<style>
body {
color: white;
background-color: black;
font-family: monospace;
}
h1 {
text-align: center;
}
input {
margin: 10px
}
</style>
</head>
<body>
<h1>lego-gears: helping you find gear trains the easy way</h1>
<hr />
<p>
Plates up:
<input type="text" id="plates_up" />Half pins across:
<input type="text" id="half_pins_across" />Gear ratio:
<input type="text" id="gear_ratio" />
<br />
<input type="submit" id="submit" value="find gear trains" />
<span id="status_message">Ready.</span>
</p>
<p id="advanced">
ADVANCED (takes way longer to calculate!!!)
<br />
<input type="checkbox" id="allow_two_gears_on_same_axle" />Allow Two Gears On Same Axle
<br />
<input type="checkbox" id="negative_movements_allowed" />Negative Movements Allowed
</p>
<hr />
<p id="filters">
Gears to use:
<input type="checkbox" class="gears" value="8" />8
<input type="checkbox" class="gears" value="12" checked />12
<input type="checkbox" class="gears" value="16" checked />16
<input type="checkbox" class="gears" value="20" checked />20
<input type="checkbox" class="gears" value="24" checked />24
<input type="checkbox" class="gears" value="36" />36
<input type="checkbox" class="gears" value="40" />40
</p>
<hr />
<div id="canvas_container" style="float:left"></div>
<div id="solutions" style="float:left; padding:10px; height:500px; width: 500px; overflow:auto"></div>
<script>
var lego_canvas = LegoCanvas(document.getElementById("canvas_container"));
var list_of_solutions;
var gears = [];
$(".gears").click(update_list_of_solutions);
function update_list_of_solutions() {
var html_solutions = "";
$(".gears").each(function() {
gears[$(this).val()] = $(this).prop('checked');
});
// filter the solutions to only include the preferred gears
var solutions_with_preferred_gears = _.filter(list_of_solutions,
function(solution) {
return _.every(solution,
function(combo) {
return gears[combo[0]] && gears[combo[1]];
});
});
if (solutions_with_preferred_gears.length !== 0) {
_.each(solutions_with_preferred_gears,
function(solution) {
html_solutions += "<input class=\"solution\" type=\"radio\" name=\"gear_train\" " +
"value=\"" + JSON.stringify(solution) + "\">" +
JSON.stringify(solution) + "</input><br />";
});
} else if (list_of_solutions.length !== 0) {
html_solutions = "Gear trains are being filtered out by \"gears to use\". " +
"Check off more boxes!";
} else {
html_solutions = "No gear trains found :-(";
}
$("#solutions").html(html_solutions);
$(".solution").click(function() {
lego_canvas("create_gear_train")(JSON.parse($(".solution:checked").val()));
});
}
var worker = new Worker('web/worker.js');
worker.onerror = function(event) {
throw event.message + " (" + event.filename + ":" + event.lineno + ")";
};
worker.onmessage = function(event) {
// if the worker returns a string, you know there's a problem
if (typeof event.data === "string") {
$("#status_message").text(event.data);
} else {
$("#status_message").text("Ready.");
list_of_solutions = event.data;
update_list_of_solutions();
}
};
$("#submit").click(function() {
try {
$("#status_message").text("computing...");
var message = {
up: $("#plates_up").val(),
across: $("#half_pins_across").val(),
ratio: $("#gear_ratio").val(),
allow_two_gears_on_same_axle: $("#allow_two_gears_on_same_axle").prop('checked'),
negative_movements_allowed: $("#negative_movements_allowed").prop('checked')
}
worker.postMessage(message);
} catch (err) {
$("#status_message").text("Error: " + err.message);
}
});
lego_canvas("create_gear_train")([
[24, 20, 7, 0],
[24, 8, 0, 4],
[16, 8, 1, 3],
[16, 12, 2, 3]
]);
</script>
<a href="https://github.com/2sb18/lego-gears">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://github-camo.global.ssl.fastly.net/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67"
alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png">
</a>
<script>
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return (false);
}
$("input").each(function() {
if (getQueryVariable($(this).attr("id"))) {
$(this).val(getQueryVariable($(this).attr("id")));
}
});
</script>
</body>
</html>