Watch Encyclopedia / website / exp / materials.js
| 1 | WE.mount('materials', function (S) { |
| 2 | var C = S.C, ctx = S.ctx; |
| 3 | var M = [['Gold (18 karat)', 2.8, 'case'], ['Acrylic crystal', 3, 'crystal'], ['Bronze', 3, 'case'], ['Stainless steel', 5, 'case'], ['Mineral glass crystal', 5.5, 'crystal'], ['Titanium (grade 5)', 6, 'case'], ['Ceramic', 8.5, 'case'], ['Sapphire crystal', 9, 'crystal']]; |
| 4 | var T = [['2.5', 'Fingernail'], ['3.5', 'Copper coin'], ['5.5', 'Knife blade'], ['7', 'Sand and grit'], ['10', 'Diamond']]; |
| 5 | var tool = S.select('Scratch it with', T, '7'); |
| 6 | S.loop(function (dt, t) { |
| 7 | S.clear(); var w = S.W, h = S.H, sm = S.small(), x0 = sm ? 14 : w * .26, x1 = w - 20, top = h * .12, rowh = (h * .8) / M.length, hv = +tool.v, X = function (v) { return x0 + (v - 1) / 9 * (x1 - x0); }; |
| 8 | for (var g = 1; g <= 10; g++) { S.ln(X(g), top - 6, X(g), top + rowh * M.length, C.grid, 1); S.txt(String(g), X(g), top - 16, C.mut, 11, 'center'); } |
| 9 | S.txt('Softer', x0, top - 34, C.mut, 12); S.txt('Harder', x1 - 44, top - 34, C.mut, 12, 'right'); |
| 10 | var hit = 0; |
| 11 | M.forEach(function (m, i) { |
| 12 | var y = top + i * rowh + rowh / 2, scr = hv > m[1]; if (scr) hit++; |
| 13 | if (sm) S.txt(m[0], x0, y - rowh * .3, C.ink, 11.5, 'left', 600); else S.txt(m[0], x0 - 14, y, C.ink, 13.5, 'right', 600); |
| 14 | var by = sm ? y + 4 : y, bh = Math.min(22, rowh * (sm ? .36 : .5)); S.rr(x0, by - bh / 2, X(m[1]) - x0, bh, 5, scr ? 'rgba(232,115,92,.3)' : m[2] === 'crystal' ? 'rgba(111,177,230,.45)' : 'rgba(213,163,90,.5)'); |
| 15 | S.dot(X(m[1]), by, 5, scr ? C.red : C.ink); |
| 16 | if (scr) { ctx.strokeStyle = 'rgba(241,236,226,.8)'; ctx.lineWidth = 1; for (var k = 0; k < 4; k++) { var sx = x0 + 12 + ((i * 37 + k * 53) % Math.max(20, X(m[1]) - x0 - 40)); ctx.beginPath(); ctx.moveTo(sx, by - bh * .3); ctx.lineTo(sx + 16, by + bh * .3); ctx.stroke(); } } |
| 17 | S.txt(scr ? 'scratched' : 'no mark', X(m[1]) + 12, by, scr ? C.red : C.green, 11.5, 'left', 650); |
| 18 | }); |
| 19 | var tx = X(hv); S.ln(tx, top - 6, tx, top + rowh * M.length, C.yellow, 2); ctx.fillStyle = C.yellow; ctx.beginPath(); ctx.moveTo(tx, top - 2); ctx.lineTo(tx - 7, top - 14); ctx.lineTo(tx + 7, top - 14); ctx.fill(); |
| 20 | var name = T.filter(function (q) { return q[0] === tool.v; })[0][1]; |
| 21 | S.say('<b>' + name + '</b> (hardness about ' + tool.v + ') scratches <b>' + hit + ' of ' + M.length + '</b> materials. A thing can only scratch what is softer than itself.' + (tool.v === '7' ? ' Everyday dust holds tiny grains of quartz, which is why sapphire stays clear and softer crystals pick up marks.' : '')); |
| 22 | }); |
| 23 | }); |