Branchwell

Watch Encyclopedia / website · watchencyclopedia.org / exp / watch-styles.js

1WE.mount('watch-styles', function (S) {
2 var C = S.C, ctx = S.ctx, bez = 0, drag = null;
3 var ST = {
4 dive: ['Dive', '#0d2238', '#1a1d22', 'A turning bezel times your air. Big glowing markers and a screw-down crown. Drag the bezel to line its triangle up with the minute hand.'],
5 pilot: ['Pilot', '#15171b', '#3a3d44', 'Huge numbers and a triangle at 12 so you can read it in a glance. A big crown you can turn with gloves on.'],
6 field: ['Field', '#2a3025', '#59605a', 'A soldier’s watch: plain, tough and easy to read, with an inner ring that shows 13 to 24 hours.'],
7 dress: ['Dress', '#f1ece2', '#c9a45c', 'Thin, quiet and simple. Slim hands, small markers and nothing extra, made to slide under a cuff.'],
8 racing: ['Racing', '#f1ece2', '#2a2d33', 'A stopwatch on the wrist. Small dials count minutes and hours, and the outer scale turns a timed distance into speed.'],
9 travel: ['Travel', '#101826', '#1c3a6b', 'An extra hand circles once a day and points to a second time zone on the 24 hour bezel.'],
10 digital: ['Digital', '#b9c2a8', '#22252b', 'Numbers on a screen instead of hands. Light, tough and exact, with alarms and a stopwatch built in.']
11 };
12 var sty = S.select('Style', Object.keys(ST).map(function (k) { return [k, ST[k][0]]; }), 'dive');
13 S.pointer({ scroll: true, down: function (x, y) { var a = Math.atan2(x - S.W / 2, -(y - S.H / 2)); drag = a - bez; }, move: function (x, y, d) { if (d && drag !== null && sty.v === 'dive') bez = Math.atan2(x - S.W / 2, -(y - S.H / 2)) - drag; }, up: function () { drag = null; bez = Math.round(bez / (S.TAU / 120)) * (S.TAU / 120); } });
14 function hand(x, y, a, len, w, col, shape) {
15 ctx.save(); ctx.translate(x, y); ctx.rotate(a); ctx.fillStyle = col; ctx.beginPath();
16 if (shape === 'dauphine') { ctx.moveTo(0, len * .1); ctx.lineTo(w, 0); ctx.lineTo(0, -len); ctx.lineTo(-w, 0); }
17 else if (shape === 'sword') { ctx.moveTo(-w * .5, len * .12); ctx.lineTo(-w, -len * .7); ctx.lineTo(0, -len); ctx.lineTo(w, -len * .7); ctx.lineTo(w * .5, len * .12); }
18 else { ctx.rect(-w / 2, -len, w, len * 1.12); }
19 ctx.fill(); ctx.restore();
20 }
21 S.loop(function () {
22 var k = sty.v, s = ST[k], w = S.W, h = S.H, x = w / 2, y = h / 2, R = Math.min(w, h) * .44, d = new Date(), sec = d.getSeconds() + d.getMilliseconds() / 1000, min = d.getMinutes() + sec / 60, hr = d.getHours() % 12 + min / 60;
23 S.clear();
24 if (k === 'digital') {
25 S.rr(x - R * .95, y - R * .8, R * 1.9, R * 1.6, R * .25, s[2]); S.rr(x - R * .72, y - R * .42, R * 1.44, R * .84, 8, s[1]);
26 var p = function (n) { return ('0' + n).slice(-2); }; ctx.fillStyle = '#14161a'; ctx.font = '700 ' + R * .42 + 'px ui-monospace,Menlo,monospace'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(p(d.getHours()) + ':' + p(d.getMinutes()), x - R * .12, y + R * .04);
27 ctx.font = '700 ' + R * .2 + 'px ui-monospace,Menlo,monospace'; ctx.fillText(p(d.getSeconds()), x + R * .56, y + R * .12); ctx.font = '600 ' + R * .1 + 'px ui-monospace,Menlo,monospace'; ctx.fillText(d.toLocaleDateString(undefined, { weekday: 'short' }).toUpperCase() + ' ' + d.getDate(), x, y - R * .3);
28 [[-1, -1, 'LIGHT'], [1, -1, 'START'], [-1, 1, 'MODE'], [1, 1, 'RESET']].forEach(function (b) { S.txt(b[2], x + b[0] * R * .62, y + b[1] * R * .62, C.mut, R * .07, 'center', 650); });
29 S.say('<b>' + s[0] + '</b> &nbsp;' + s[3]); return;
30 }
31 var hasBez = k === 'dive' || k === 'travel' || k === 'racing', r = hasBez ? R * .8 : R * .93;
32 S.dot(x, y, R, s[2]); if (k === 'dress') S.ring(x, y, R, '#e3c583', 2);
33 if (k === 'dive') { for (var i = 0; i < 60; i++) { var a = bez + i * S.TAU / 60, b = i % 5 === 0; if (i === 0) { ctx.save(); ctx.translate(x, y); ctx.rotate(a); ctx.fillStyle = '#f0d264'; ctx.beginPath(); ctx.moveTo(0, -R * .97); ctx.lineTo(R * .05, -R * .86); ctx.lineTo(-R * .05, -R * .86); ctx.fill(); ctx.restore(); } else if (i % 10 === 0) { S.txt(String(i), x + R * .9 * Math.sin(a), y - R * .9 * Math.cos(a), '#f1ece2', R * .08, 'center', 700); } else if (b || i < 15) S.ln(x + R * .86 * Math.sin(a), y - R * .86 * Math.cos(a), x + R * (b ? .95 : .91) * Math.sin(a), y - R * (b ? .95 : .91) * Math.cos(a), '#f1ece2', b ? 2.5 : 1); } }
34 if (k === 'travel') { for (var g = 0; g < 24; g++) { var ga = g * S.TAU / 24; if (g % 2 === 0) S.txt(String(g || 24), x + R * .9 * Math.sin(ga), y - R * .9 * Math.cos(ga), '#f1ece2', R * .08, 'center', 700); else S.dot(x + R * .9 * Math.sin(ga), y - R * .9 * Math.cos(ga), 2, '#f1ece2'); } }
35 if (k === 'racing') { [60, 70, 80, 100, 120, 150, 200, 300, 400].forEach(function (v) { var ta = (3600 / v) / 60 * S.TAU; S.txt(String(v), x + R * .9 * Math.sin(ta), y - R * .9 * Math.cos(ta), '#f1ece2', R * .065, 'center', 650); }); }
36 S.dot(x, y, r, s[1]); var ink = (k === 'dress' || k === 'racing') ? '#1d1a16' : '#f1ece2', lume = k === 'dive' || k === 'field' || k === 'pilot' ? '#d9f2c4' : ink;
37 for (var m = 0; m < 60; m++) { var ma = m * S.TAU / 60, big = m % 5 === 0; if (k === 'dress' && !big) continue; S.ln(x + r * (big ? .84 : .9) * Math.sin(ma), y - r * (big ? .84 : .9) * Math.cos(ma), x + r * .95 * Math.sin(ma), y - r * .95 * Math.cos(ma), ink, big ? (k === 'dress' ? 1.5 : 3) : 1); }
38 for (var n = 1; n <= 12; n++) { var na = n * S.TAU / 12, nx = x + r * .7 * Math.sin(na), ny = y - r * .7 * Math.cos(na);
39 if (k === 'pilot' || k === 'field') { if (n === 12 && k === 'pilot') { ctx.fillStyle = lume; ctx.beginPath(); ctx.moveTo(nx, ny + r * .09); ctx.lineTo(nx - r * .09, ny - r * .07); ctx.lineTo(nx + r * .09, ny - r * .07); ctx.fill(); } else S.txt(String(n), nx, ny, lume, r * (k === 'pilot' ? .17 : .15), 'center', 700); if (k === 'field') S.txt(String(n + 12), x + r * .46 * Math.sin(na), y - r * .46 * Math.cos(na), 'rgba(241,236,226,.6)', r * .075, 'center', 600); }
40 else if (k === 'dive') { if (n % 3 === 0) S.rr(nx - r * .035, ny - r * .08, r * .07, r * .16, 2, lume); else S.dot(nx, ny, r * .055, lume); }
41 else if (k === 'travel') S.rr(nx - r * .02, ny - r * .06, r * .04, r * .12, 1, lume); }
42 if (k === 'racing') { [[-.42, 0, sec / 60], [.42, 0, min / 30 % 1], [0, .42, hr / 12]].forEach(function (q) { var sx = x + q[0] * r, sy = y + q[1] * r, sr = r * .2; S.dot(sx, sy, sr, '#2a2d33'); S.ring(sx, sy, sr, '#888', 1); S.ln(sx, sy, sx + sr * .8 * Math.sin(q[2] * S.TAU), sy - sr * .8 * Math.cos(q[2] * S.TAU), '#f1ece2', 1.5); }); }
43 if (k === 'travel') { var ua = (d.getUTCHours() + d.getUTCMinutes() / 60) * S.TAU / 24; hand(x, y, ua, r * .9, 3, C.red); }
44 var shape = k === 'dress' ? 'dauphine' : k === 'dive' || k === 'field' ? 'sword' : 'baton', hw = r * (k === 'dress' ? .035 : .05);
45 hand(x, y, hr * S.TAU / 12, r * .5, hw * 1.2, lume === ink ? ink : lume, shape); hand(x, y, min * S.TAU / 60, r * .8, hw, lume === ink ? ink : lume, shape);
46 hand(x, y, (k === 'racing' ? 0 : sec * S.TAU / 60), r * .86, 1.6, k === 'dress' ? ink : C.red); S.dot(x, y, r * .035, ink);
47 S.say('<b>' + s[0] + '</b> &nbsp;' + s[3]);
48 });
49});