-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemaphore-decoder.html
More file actions
311 lines (289 loc) · 9.67 KB
/
semaphore-decoder.html
File metadata and controls
311 lines (289 loc) · 9.67 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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<title>Semaphore Decoder</title>
<meta name="author" content="Bobbie Chen" />
<meta name="description" content="A point-and-click visual semaphore decoder for solving puzzles" />
<link rel="icon" href="semaphore-favicon.png" />
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js"></script>
<link href="normalize.css" rel="stylesheet" />
<link href="skeleton.css" rel="stylesheet" />
<style>
.flag {
height: 30px;
width: calc(min(200px, min(25vh, 50vw)) - 2em);
padding-top: 5px;
padding-left: 5px;
border: 4px ridge black;
border-right: 0px;
position: absolute;
display: inline-block;
cursor: pointer;
transform-origin: right;
}
.flag.hover {
background-color: rgba(255, 255, 128, 0.5);
z-index: 1;
}
.flag.selected {
background-color: rgba(255, 255, 128, 1);
z-index: 1;
}
.flag.hover.selected {
background-color: rgba(255, 255, 128, 0.8);
z-index: 1;
}
.flag-container {
position: relative;
padding: calc(min(200px, min(25vh, 50vw))) 0;
}
.info-container {
padding-top: 1em;
}
</style>
</head>
<body>
<div id="app" class="container">
<semaphore-decoder></semaphore-decoder>
<hr />
<h3>What's this?</h3>
<div class="row">
<div class="one-half column">
<p>
<a href="https://en.wikipedia.org/wiki/Flag_semaphore">Flag semaphore</a>
is a technique used for visual communication, where the positions of two flags represent a single letter.
</p>
<p>
I often see these at puzzle hunts disguised as clock hands, tree branches, dance moves, etc., and I'm very
slow at reading the lookup chart (see image at right). I thought the ideal way to decode semaphore would be
to draw out the actual angles. So I wrote my own visual semaphore decoder, implemented using Vue.
</p>
<p>
It's very rare to solve just one semaphore - usually you need to solve many to form a word or a phrase. So I
added the ability to push each letter to a text box, using . (period) for quick entry. It's a regular text
input, so you can type normally if you want to change anything.
</p>
<p>
There is also a quick link to anagram the resulting letters on
<a href="https://nutrimatic.org">Nutrimatic</a>, which is a very powerful pattern-matching tool. If you're
familiar with Nutrimatic syntax, you can use it here as well - for example, if you're not quite sure what a
semaphore position is, you can enter capital A for "any letter", and hope that Nutrimatic will be able to
fill it in for you.
</p>
<p>
Note that this decoder does not decode numerals, which are typically represented with the (0, 45) signal
followed by another signal.
</p>
<p>
More writing on how this project was made: <br />
<a href="https://bobbiechen.com/blog/2020/5/28/the-making-of-semaphore-decoder?ref=bobbiec.github.io"
>The Making of Semaphore Decoder</a
>.
</p>
</div>
<img src="semaphore-chart.png" class="one-half column" />
</div>
</div>
<footer style="padding-bottom: 1rem; text-align: center">
A project by <a href="https://bobbiechen.com?ref=bobbiec.github.io">Bobbie Chen</a>. See all
<a href="/">web demos</a>.
</footer>
<script>
Vue.component("flag", {
props: ["position", "selected"],
template: `
<div
v-bind:class="['flag', {'hover': hover, 'selected': selected}]"
v-bind:style="style"
v-on:click="$emit('flagClicked', position)"
v-on:mouseover="hover = true"
v-on:mouseleave="hover = false"
>
{{ position }}
</div>`,
data: function () {
return {
hover: false,
}
},
computed: {
style() {
return {
transform: `rotate(${90 + this.position}deg`,
}
},
},
})
Vue.component("semaphore-decoder", {
template: `
<div style="max-width:450px">
<div class="row flag-container">
<flag
v-for="number in numbers"
v-bind:position="number"
v-bind:selected="(number === firstFlag || number === secondFlag)"
v-bind:key="number"
v-on:flagClicked="flagClicked"
></flag>
</div>
<div class="info-container">
<h1>Decoded: <strong> {{ match }} </strong></h1>
<div class="u-full-width">
{{ match === "?" ? "Select two flags!" :
match === "(none)" ? "These two flags mean nothing."
: "Click Add or hit . to add to the textbox." }}
</div>
<div class="row" style="display: flex">
<input
v-model="text"
class="nine columns"
type="text"
placeholder="Your word here, eventually"
/>
<button v-on:click="addLetter" class="three columns">
Add
</button>
</div>
<button v-on:click="text = ''" class="u-full-width">
Clear textbox
</button>
<a
v-bind:href="'https://nutrimatic.org/?q=%3C' + text + '%3E&go=Go'"
target="_blank"
class="button button-primary u-full-width"
style="color:#555"
>
Anagram on Nutrimatic
</a>
<small class="u-full-width">
Currently selected angles: {{ firstFlag }}, {{ secondFlag }}
</small>
</div>
</div>
`,
data: function () {
return {
numbers: [0, 45, 90, 135, 180, 225, 270, 315],
firstFlag: 180,
secondFlag: 225,
text: "",
}
},
computed: {
match() {
switch (`${this.firstFlag}-${this.secondFlag}`) {
case "0-90":
return "J"
case "0-135":
return "V"
case "0-180":
return "D"
case "0-225":
return "K"
case "0-270":
return "P"
case "0-315":
return "T"
case "45-90":
return "W"
case "45-135":
return "X"
case "45-180":
return "E"
case "45-225":
return "L"
case "45-270":
return "Q"
case "45-315":
return "U"
case "90-135":
return "Z"
case "90-180":
return "F"
case "90-225":
return "M"
case "90-270":
return "R"
case "90-315":
return "Y"
case "135-180":
return "G"
case "135-225":
return "N"
case "135-270":
return "S"
case "180-225":
return "A"
case "180-270":
return "B"
case "180-315":
return "C"
case "225-270":
return "H"
case "225-315":
return "I"
case "270-315":
return "O"
case "0-45":
case "135-315":
return "(none)"
default:
return "?"
}
},
},
methods: {
flagClicked(position) {
if (this.secondFlag || this.firstFlag === null) {
if (position === this.firstFlag) {
this.firstFlag = this.secondFlag
this.secondFlag = null
} else if (position === this.secondFlag) {
this.secondFlag = null
} else {
this.firstFlag = position
this.secondFlag = null
}
} else {
if (position === this.firstFlag) {
this.firstFlag = null
} else if (position < this.firstFlag) {
this.secondFlag = this.firstFlag
this.firstFlag = position
} else {
this.secondFlag = position
}
}
},
keyPressed(event) {
if (event.key !== ".") {
return
}
if (!(this.firstFlag && this.secondFlag)) {
return
}
this.addLetter()
return
},
addLetter() {
let match = this.match
if (match.length === 1) {
this.text += match.toLowerCase()
}
},
},
created: function () {
document.addEventListener("keydown", this.keyPressed)
},
destroyed: function () {
document.removeEventListener("keydown", this.keyPressed)
},
})
var app = new Vue({
el: "#app",
})
</script>
</body>
</html>