Watch Encyclopedia / website · watchencyclopedia.org / commits / 8b38e375
Website: current files new
written by Branchwell · 8b38e375b3e16f98454b93adca8e1fbd4fc534c5
214 files changed
404.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>Page not found | Watch Encyclopedia</title><meta name="description" content="That page could not be found."><link rel="canonical" href="https://watchencyclopedia.org/404"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="Page not found | Watch Encyclopedia"><meta property="og:description" content="That page could not be found."><meta property="og:url" content="https://watchencyclopedia.org/404"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <section class="hero"><div><p class="k">404</p><h1>This page has stopped.</h1><p class="lede">We couldn't find that page. It may have moved, or it hasn't been made yet.</p><div class="btns"><a class="btn" href="/">See every entry</a></div></div><div><svg viewBox="0 0 360 360" xmlns="http://www.w3.org/2000/svg" class="dial"><circle cx="180.0" cy="180.0" r="168.0" fill="var(--dial)" stroke="var(--case)" stroke-width="10"/><circle cx="180.0" cy="180.0" r="152.0" fill="none" stroke="var(--tick)" stroke-opacity=".25"/><line x1="180.0" y1="30.0" x2="180.0" y2="52.0" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="195.7" y1="30.8" x2="194.7" y2="39.8" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="211.2" y1="33.3" x2="209.3" y2="42.1" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="226.4" y1="37.3" x2="223.6" y2="45.9" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="241.0" y1="43.0" x2="237.3" y2="51.2" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="255.0" y1="50.1" x2="244.0" y2="69.1" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="268.2" y1="58.6" x2="262.9" y2="65.9" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="280.4" y1="68.5" x2="274.3" y2="75.2" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="291.5" y1="79.6" x2="284.8" y2="85.7" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="301.4" y1="91.8" x2="294.1" y2="97.1" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="309.9" y1="105.0" x2="290.9" y2="116.0" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="317.0" y1="119.0" x2="308.8" y2="122.7" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="322.7" y1="133.6" x2="314.1" y2="136.4" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="326.7" y1="148.8" x2="317.9" y2="150.7" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="329.2" y1="164.3" x2="320.2" y2="165.3" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="330.0" y1="180.0" x2="308.0" y2="180.0" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="329.2" y1="195.7" x2="320.2" y2="194.7" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="326.7" y1="211.2" x2="317.9" y2="209.3" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="322.7" y1="226.4" x2="314.1" y2="223.6" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="317.0" y1="241.0" x2="308.8" y2="237.3" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="309.9" y1="255.0" x2="290.9" y2="244.0" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="301.4" y1="268.2" x2="294.1" y2="262.9" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="291.5" y1="280.4" x2="284.8" y2="274.3" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="280.4" y1="291.5" x2="274.3" y2="284.8" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="268.2" y1="301.4" x2="262.9" y2="294.1" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="255.0" y1="309.9" x2="244.0" y2="290.9" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="241.0" y1="317.0" x2="237.3" y2="308.8" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="226.4" y1="322.7" x2="223.6" y2="314.1" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="211.2" y1="326.7" x2="209.3" y2="317.9" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="195.7" y1="329.2" x2="194.7" y2="320.2" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="180.0" y1="330.0" x2="180.0" y2="308.0" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="164.3" y1="329.2" x2="165.3" y2="320.2" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="148.8" y1="326.7" x2="150.7" y2="317.9" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="133.6" y1="322.7" x2="136.4" y2="314.1" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="119.0" y1="317.0" x2="122.7" y2="308.8" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="105.0" y1="309.9" x2="116.0" y2="290.9" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="91.8" y1="301.4" x2="97.1" y2="294.1" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="79.6" y1="291.5" x2="85.7" y2="284.8" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="68.5" y1="280.4" x2="75.2" y2="274.3" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="58.6" y1="268.2" x2="65.9" y2="262.9" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="50.1" y1="255.0" x2="69.1" y2="244.0" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="43.0" y1="241.0" x2="51.2" y2="237.3" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="37.3" y1="226.4" x2="45.9" y2="223.6" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="33.3" y1="211.2" x2="42.1" y2="209.3" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="30.8" y1="195.7" x2="39.8" y2="194.7" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="30.0" y1="180.0" x2="52.0" y2="180.0" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="30.8" y1="164.3" x2="39.8" y2="165.3" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="33.3" y1="148.8" x2="42.1" y2="150.7" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="37.3" y1="133.6" x2="45.9" y2="136.4" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="43.0" y1="119.0" x2="51.2" y2="122.7" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="50.1" y1="105.0" x2="69.1" y2="116.0" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="58.6" y1="91.8" x2="65.9" y2="97.1" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="68.5" y1="79.6" x2="75.2" y2="85.7" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="79.6" y1="68.5" x2="85.7" y2="75.2" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="91.8" y1="58.6" x2="97.1" y2="65.9" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="105.0" y1="50.1" x2="116.0" y2="69.1" stroke="var(--tick)" stroke-width="5" stroke-linecap="round"/><line x1="119.0" y1="43.0" x2="122.7" y2="51.2" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="133.6" y1="37.3" x2="136.4" y2="45.9" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="148.8" y1="33.3" x2="150.7" y2="42.1" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="164.3" y1="30.8" x2="165.3" y2="39.8" stroke="var(--tick)" stroke-width="1.6" stroke-linecap="round"/><line x1="171.5" y1="174.7" x2="251.2" y2="224.5" stroke="var(--hand)" stroke-width="9" stroke-linecap="round"/><line x1="173.9" y1="193.6" x2="230.6" y2="66.4" stroke="var(--hand)" stroke-width="6" stroke-linecap="round"/><circle cx="180.0" cy="180.0" r="9" fill="var(--hand)"/><circle cx="180.0" cy="180.0" r="3.5" fill="var(--accent)"/></svg></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script></body></html> |
about/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>About | Watch Encyclopedia</title><meta name="description" content="Watch Encyclopedia is a free interactive encyclopedia you watch and play with."><link rel="canonical" href="https://watchencyclopedia.org/about/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="About | Watch Encyclopedia"><meta property="og:description" content="Watch Encyclopedia is a free interactive encyclopedia you watch and play with."><meta property="og:url" content="https://watchencyclopedia.org/about/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/" aria-current="page">About</a></nav></header> | |
| 7 | + <div class="page-h"><div class="crumbs"><a href="/">Home</a> / About</div><p class="k">About</p><h1>About Watch Encyclopedia</h1><p class="lede">We're building an encyclopedia you watch and play with, not one you only read.</p></div> | |
| 8 | + <article style="padding-bottom:64px"><h2>What it is</h2><p>Every entry opens on a live model: a planet in orbit, an engine turning, a globe of history, a phone coming apart. You can press, drag and slide to change what you see. A short note underneath says what is going on.</p> | |
| 9 | + <h2>How we build entries</h2><p>The models use real figures and real rules wherever we can. When a picture is simplified so it fits on a screen, such as planet sizes or the speed of an animation, we say so in the entry.</p> | |
| 10 | + <h2>Independent</h2><p>Watch Encyclopedia isn't tied to any maker or seller. We don't run ads or take placements. Where an entry builds on other people's published work, we credit them inside that entry.</p> | |
| 11 | + <h2>Free for everyone</h2><p>Every entry is free to use, with no account and nothing to sign up for.</p> | |
| 12 | + <h2>Growing</h2><p>We add new entries all the time, across space, history, machines, science, math and timekeeping.</p></article> | |
| 13 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 14 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script></body></html> |
assets/site.css added
| 1 | + *{box-sizing:border-box}:root{--bg:#f6f2ea;--fg:#1d1a16;--ink:#2a251e;--mut:#625a4e;--card:#fffdf8;--line:#e2d9c9;--soft:#ece4d4;--accent:#9a6b2c;--dial:#fbf8f1;--case:#b9ac95;--tick:#2a251e;--hand:#1d1a16} | |
| 2 | + @media (prefers-color-scheme:dark){:root{--bg:#121110;--fg:#f1ece2;--ink:#e8e0d2;--mut:#ada393;--card:#1a1917;--line:#2e2b27;--soft:#26231f;--accent:#d5a35a;--dial:#1d1b18;--case:#5d564b;--tick:#e8e0d2;--hand:#f1ece2}} | |
| 3 | + html{scroll-behavior:smooth}body{margin:0;background:var(--bg);color:var(--fg);font:18px/1.65 "Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;-webkit-font-smoothing:antialiased} | |
| 4 | + a{color:inherit}img{max-width:100%;height:auto;display:block}.wrap{max-width:1120px;margin:0 auto;padding:0 20px} | |
| 5 | + .sans,header,nav,.k,.btn,footer,.toc,.crumbs,.tag,input,.chip{font-family:system-ui,-apple-system,"Segoe UI",sans-serif} | |
| 6 | + header{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:20px 0;flex-wrap:wrap} | |
| 7 | + .brand{display:flex;align-items:center;gap:10px;font-weight:700;font-size:20px;text-decoration:none;letter-spacing:.01em} | |
| 8 | + .brand svg{width:30px;height:30px} | |
| 9 | + nav{display:flex;gap:6px 16px;flex-wrap:wrap}nav a{color:var(--mut);text-decoration:none;font-size:15px}nav a:hover,nav a[aria-current]{color:var(--fg)} | |
| 10 | + .menu{display:none;font:inherit;font-size:15px;background:none;border:1px solid var(--line);border-radius:999px;padding:6px 14px;color:var(--fg)} | |
| 11 | + h1,h2,h3{font-weight:700;letter-spacing:-.015em;line-height:1.12} | |
| 12 | + h1{font-size:clamp(38px,6vw,68px);margin:0 0 18px}h2{font-size:clamp(28px,3.8vw,40px);margin:0 0 12px}h3{font-size:22px;margin:0 0 6px} | |
| 13 | + .lede{font-size:21px;color:var(--mut);max-width:640px;margin:0 0 28px} | |
| 14 | + .hero{display:grid;grid-template-columns:1.1fr 1fr;gap:40px;align-items:center;padding:48px 0 64px} | |
| 15 | + .btns{display:flex;gap:12px;flex-wrap:wrap}.btn{display:inline-block;padding:12px 22px;border-radius:999px;background:var(--fg);color:var(--bg);text-decoration:none;font-weight:600;font-size:16px;border:1px solid var(--fg)} | |
| 16 | + .btn.ghost{background:transparent;color:var(--fg);border-color:var(--line)} | |
| 17 | + .dial{width:100%;max-width:440px;margin:0 auto;display:block;filter:drop-shadow(0 18px 40px rgba(0,0,0,.18))} | |
| 18 | + .dial .sec{animation:tick 60s steps(60) infinite}@keyframes tick{to{transform:rotate(360deg)}} | |
| 19 | + .diagram{width:100%;height:auto;display:block}.balance{animation:swing 1s ease-in-out infinite alternate}@keyframes swing{from{transform:rotate(-150deg)}to{transform:rotate(150deg)}} | |
| 20 | + @media (prefers-reduced-motion:reduce){.dial .sec,.balance{animation:none}} | |
| 21 | + .pic{margin:0;border-radius:24px;overflow:hidden;background:var(--soft)}.pic img{width:100%;height:100%;object-fit:cover} | |
| 22 | + .pic.art{background:none;border-radius:0;overflow:visible} | |
| 23 | + .sec-b{padding:64px 0;border-top:1px solid var(--line)}p.sub{color:var(--mut);max-width:680px;margin:0 0 32px;font-size:19px} | |
| 24 | + .k{margin:0 0 8px;font-size:12.5px;color:var(--accent);text-transform:uppercase;letter-spacing:.14em;font-weight:700} | |
| 25 | + .cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:16px} | |
| 26 | + .card{background:var(--card);border:1px solid var(--line);border-radius:20px;padding:22px 24px;text-decoration:none;display:block} | |
| 27 | + a.card:hover{border-color:var(--accent)}.card p.k{color:var(--accent);font-size:12.5px}.card p{margin:0;color:var(--mut);font-size:17px}.card .k{margin-bottom:6px} | |
| 28 | + .card .pic{margin:-22px -24px 18px;border-radius:20px 20px 0 0;aspect-ratio:3/2} | |
| 29 | + .split{display:grid;grid-template-columns:1fr 1fr;gap:40px;align-items:center} | |
| 30 | + .panel{background:var(--card);border:1px solid var(--line);border-radius:24px;padding:26px} | |
| 31 | + .page-h{padding:44px 0 26px;max-width:780px}.crumbs{font-size:14px;color:var(--mut);margin-bottom:14px}.crumbs a{color:var(--mut)} | |
| 32 | + .layout{display:grid;grid-template-columns:220px 1fr;gap:48px;padding-bottom:64px} | |
| 33 | + .toc{position:sticky;top:20px;align-self:start;font-size:14.5px;border-left:2px solid var(--line);padding-left:14px} | |
| 34 | + .toc b{display:block;margin-bottom:8px;font-size:12px;letter-spacing:.12em;text-transform:uppercase;color:var(--mut)} | |
| 35 | + .toc a{display:block;color:var(--mut);text-decoration:none;padding:3px 0}.toc a:hover{color:var(--fg)} | |
| 36 | + article{max-width:760px}article h2{font-size:30px;margin:44px 0 10px;scroll-margin-top:20px}article h2:first-child{margin-top:0} | |
| 37 | + article h3{margin:28px 0 6px}article p,article li{color:var(--fg)}article .fig{margin:24px 0 30px} | |
| 38 | + .entry{border-top:1px solid var(--line);padding:26px 0}.entry:first-of-type{border-top:0;padding-top:0} | |
| 39 | + .facts{display:grid;grid-template-columns:auto 1fr;gap:4px 16px;font-size:16px;margin:12px 0 0;padding:14px 18px;background:var(--card);border:1px solid var(--line);border-radius:14px} | |
| 40 | + .facts dt{color:var(--mut);font-family:system-ui,sans-serif;font-size:14px;padding-top:2px}.facts dd{margin:0} | |
| 41 | + .tl{list-style:none;padding:0;margin:0;border-left:2px solid var(--line)} | |
| 42 | + .tl li{position:relative;padding:0 0 26px 26px}.tl li:before{content:"";position:absolute;left:-7px;top:9px;width:12px;height:12px;border-radius:50%;background:var(--accent)} | |
| 43 | + .tl .yr{font-family:system-ui,sans-serif;font-weight:700;font-size:15px;color:var(--accent);display:block} | |
| 44 | + .gl input{width:100%;font-size:17px;padding:13px 18px;border-radius:999px;border:1px solid var(--line);background:var(--card);color:var(--fg);margin:0 0 20px} | |
| 45 | + .gl dl{margin:0}.gl dt{font-weight:700;font-size:20px;margin-top:20px}.gl dd{margin:2px 0 0;color:var(--mut)} | |
| 46 | + .letters{display:flex;flex-wrap:wrap;gap:6px;margin:0 0 10px}.chip{font-size:13px;padding:4px 10px;border:1px solid var(--line);border-radius:999px;text-decoration:none;color:var(--mut)} | |
| 47 | + .callout{border-left:3px solid var(--accent);padding:4px 0 4px 18px;color:var(--mut);margin:24px 0} | |
| 48 | + .note{color:var(--mut);font-size:15px} | |
| 49 | + footer{border-top:1px solid var(--line);padding:24px 0 44px;color:var(--mut);font-size:14px;display:flex;gap:18px;flex-wrap:wrap;justify-content:space-between} | |
| 50 | + footer a{color:var(--mut)} | |
| 51 | + @media (max-width:860px){.hero,.split{grid-template-columns:1fr}.hero{padding-top:20px}.layout{grid-template-columns:1fr;gap:20px}.toc{position:static;border:0;padding:0;display:flex;flex-wrap:wrap;gap:4px 14px}.toc b{width:100%} | |
| 52 | + .menu{display:inline-block}nav{display:none;width:100%;padding-top:6px}nav.open{display:flex}} | |
| 53 | + | |
| 54 | + .stage{background:#0d0f13;color:#f1ece2;border-radius:24px;overflow:hidden;border:1px solid #23272f;margin:0 0 28px;font-family:system-ui,-apple-system,"Segoe UI",sans-serif;position:relative} | |
| 55 | + .stage .scr{position:relative;aspect-ratio:16/9;max-height:76vh;width:100%}.stage.short .scr{aspect-ratio:21/9;max-height:56vh} | |
| 56 | + .stage canvas{position:absolute;inset:0;width:100%;height:100%;display:block} | |
| 57 | + .stage .fs{position:absolute;top:10px;right:10px;width:38px;height:38px;border-radius:999px;border:1px solid #333944;background:rgba(13,15,19,.7);color:#f1ece2;font-size:17px;cursor:pointer} | |
| 58 | + .stage .cap{margin:0;padding:12px 18px 0;font-size:15.5px;color:#cfc8b8;min-height:24px;line-height:1.45}.stage .cap b{color:#d5a35a;font-weight:650} | |
| 59 | + .stage .ctl{display:flex;flex-wrap:wrap;gap:10px 14px;align-items:flex-end;padding:12px 18px 18px} | |
| 60 | + .stage .ctl:empty{padding:0 0 12px} | |
| 61 | + .c-sl{display:flex;flex-direction:column;gap:2px;min-width:150px;flex:1 1 150px;max-width:260px;font-size:13px;color:#9a927f} | |
| 62 | + .c-lab{display:flex;justify-content:space-between;gap:10px;font-size:13px;color:#9a927f}.c-lab b{color:#f1ece2;font-weight:600;font-variant-numeric:tabular-nums} | |
| 63 | + .c-sl input{width:100%;accent-color:#d5a35a;height:26px;margin:0} | |
| 64 | + .c-in input{height:38px;border-radius:999px;border:1px solid #363c47;background:#171b22;color:#f1ece2;padding:0 14px;font:inherit;font-size:15px} | |
| 65 | + .c-tg,.c-bt,.c-row button{font:inherit;font-size:14px;padding:8px 15px;border-radius:999px;border:1px solid #363c47;background:#171b22;color:#f1ece2;cursor:pointer;min-height:38px} | |
| 66 | + .c-bt{background:#d5a35a;border-color:#d5a35a;color:#17130c;font-weight:650} | |
| 67 | + .c-tg[aria-pressed=true],.c-row button[aria-pressed=true]{background:#f1ece2;border-color:#f1ece2;color:#14161a} | |
| 68 | + .c-seg{display:flex;flex-direction:column;gap:4px}.c-row{display:flex;flex-wrap:wrap;gap:6px} | |
| 69 | + .c-note{font-size:13px;color:#9a927f;align-self:center} | |
| 70 | + .stage:fullscreen{border-radius:0;display:flex;flex-direction:column}.stage:fullscreen .scr{flex:1;max-height:none;aspect-ratio:auto} | |
| 71 | + .stage button:focus-visible,.stage input:focus-visible{outline:2px solid #d5a35a;outline-offset:2px} | |
| 72 | + .entry-h{padding:30px 0 20px;max-width:820px}.entry-h h1{font-size:clamp(34px,5vw,56px);margin-bottom:12px}.entry-h .lede{margin-bottom:0} | |
| 73 | + .below{display:grid;grid-template-columns:1.25fr 1fr;gap:20px;margin:0 0 56px} | |
| 74 | + .below .panel h2{font-size:22px;margin-bottom:8px}.below .panel p{margin:0 0 12px}.below ul{margin:0;padding-left:20px}.below li{margin-bottom:8px} | |
| 75 | + .below .facts{margin-top:0;background:none;border:0;padding:0} | |
| 76 | + .grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:18px} | |
| 77 | + .tile{background:var(--card);border:1px solid var(--line);border-radius:20px;overflow:hidden;text-decoration:none;display:flex;flex-direction:column;transition:transform .15s,border-color .15s} | |
| 78 | + .tile:hover{border-color:var(--accent);transform:translateY(-2px)} | |
| 79 | + .tile .th{aspect-ratio:16/9;background:#0d0f13 center/cover no-repeat;display:block} | |
| 80 | + .tile .tb{padding:14px 18px 18px}.tile h3{font-size:20px;margin:0 0 4px}.tile p{margin:0;color:var(--mut);font-size:15.5px;line-height:1.45} | |
| 81 | + .tile .k{font-size:11.5px;margin-bottom:5px} | |
| 82 | + .filters{display:flex;flex-wrap:wrap;gap:8px;margin:0 0 22px} | |
| 83 | + .filters button{font:inherit;font-family:system-ui,sans-serif;font-size:14.5px;padding:8px 16px;border-radius:999px;border:1px solid var(--line);background:var(--card);color:var(--fg);cursor:pointer} | |
| 84 | + .filters button[aria-pressed=true]{background:var(--fg);color:var(--bg);border-color:var(--fg)} | |
| 85 | + .finder{width:100%;max-width:420px;font-size:16px;padding:11px 18px;border-radius:999px;border:1px solid var(--line);background:var(--card);color:var(--fg);margin:0 0 14px;font-family:system-ui,sans-serif} | |
| 86 | + .hero2{padding:26px 0 8px}.hero2 h1{max-width:900px}.hero2 .lede{max-width:700px} | |
| 87 | + .frame{border-radius:24px;overflow:hidden;border:1px solid var(--line);background:#0d0f13;margin:0 0 14px} | |
| 88 | + .frame iframe{display:block;width:100%;height:min(86vh,900px);min-height:560px;border:0} | |
| 89 | + .frame-links{display:flex;gap:12px;flex-wrap:wrap;margin:0 0 28px} | |
| 90 | + @media (prefers-reduced-motion:reduce){.tile{transition:none}} | |
| 91 | + @media (max-width:860px){.below{grid-template-columns:1fr}.stage .scr,.stage.short .scr{aspect-ratio:1/1;max-height:none}.stage{border-radius:18px;margin-left:-8px;margin-right:-8px}.frame{margin-left:-8px;margin-right:-8px;border-radius:18px}.frame iframe{height:82vh}} |
assets/visitor-odometer.v1.css added
| 1 | + /* Self-host with visitor-odometer.v1.js. No fonts, images, or other requests. */ | |
| 2 | + .visitor-odometer { | |
| 3 | + --visitor-accent: #ffad64; | |
| 4 | + display: flex; flex-wrap: wrap; align-items: center; gap: 8px 13px; | |
| 5 | + margin-block: 1rem; font: inherit; | |
| 6 | + } | |
| 7 | + .visitor-odometer-label { | |
| 8 | + font: 600 .72rem/1.25 ui-monospace, monospace; | |
| 9 | + letter-spacing: .16em; text-transform: uppercase; | |
| 10 | + } | |
| 11 | + .visitor-odometer-tiles { | |
| 12 | + display: inline-flex; gap: clamp(2px, 1vw, 4px); max-width: 100%; padding: 5px; | |
| 13 | + border: 1px solid #ffffff20; border-radius: 9px; background: linear-gradient(#18191c, #070708); | |
| 14 | + box-shadow: 0 8px 25px -12px #0009; | |
| 15 | + } | |
| 16 | + .visitor-odometer-tile { | |
| 17 | + position: relative; display: grid; overflow: hidden; place-items: center; | |
| 18 | + min-width: 0; width: clamp(13px, 7vw, 29px); height: clamp(26px, 9vw, 39px); | |
| 19 | + border-radius: 4px; background: linear-gradient(#24252a 0%, #17181b 49%, #0b0c0d 51%, #18191c); | |
| 20 | + box-shadow: inset 0 0 0 1px #ffffff12, inset 0 -6px 10px #0007; | |
| 21 | + } | |
| 22 | + .visitor-odometer-tile::after { | |
| 23 | + position: absolute; inset-inline: 0; top: 50%; height: 1px; content: ""; background: #0009; | |
| 24 | + } | |
| 25 | + .visitor-odometer-face { | |
| 26 | + color: var(--visitor-accent); font: 600 clamp(14px, 5vw, 24px)/1 ui-monospace, monospace; | |
| 27 | + font-variant-numeric: tabular-nums; text-shadow: 0 0 7px #f580256e; | |
| 28 | + animation: visitor-odometer-roll .6s cubic-bezier(.2, .8, .2, 1) both; | |
| 29 | + } | |
| 30 | + .visitor-odometer-note { font-size: .875rem; } | |
| 31 | + .visitor-odometer-number { font-weight: 650; } | |
| 32 | + .visitor-odometer-sr { | |
| 33 | + position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; | |
| 34 | + clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); | |
| 35 | + } | |
| 36 | + @keyframes visitor-odometer-roll { | |
| 37 | + from { transform: translateY(-90%); opacity: 0; } | |
| 38 | + to { transform: none; opacity: 1; } | |
| 39 | + } | |
| 40 | + @media (prefers-reduced-motion: reduce) { .visitor-odometer-face { animation: none; } } |
assets/visitor-odometer.v1.js added
| 1 | + // Aggregate-only visitor odometer: no cookies, referrer, identifiers or beacons. | |
| 2 | + (() => { | |
| 3 | + 'use strict'; | |
| 4 | + const endpoint = 'https://projectatom.ai/api/visits'; | |
| 5 | + const selector = '[data-visitor-odometer][data-visitor-site]'; | |
| 6 | + const siteIDs = new Set(['projectatom', 'protomota', 'airesourcepro', 'skillfarm', 'portfolio', 'opentalon', 'inkspring', 'jotley', | |
| 7 | + 'glimmer', 'pulsecanvas', 'graphley', 'bucksley', 'jobley', 'voxley', 'textley', 'moontrace', 'sunlaid', 'cypress', 'lightwell', 'lumengesso', 'clearwake', 'krahn', 'chewandrinse', 'sidestreetmakers', 'carryspan', 'commonwakemarine', 'rootwardgardens', 'evenharbor', 'clearmeadow', 'fieldofwhy', | |
| 8 | + 'watchencyclopedia', 'paywell', 'makeaclip', 'groundroom', 'brightpatchstories', 'calendarley', 'champagnedamage', | |
| 9 | + 'neverwastv', 'noctvrne', 'otherworldvision', 'quillflow', 'tradenook', 'trendii', 'vexley', 'laceless', 'kindpaw', 'petgrove', | |
| 10 | + 'homegrove', 'cyclical', 'commongrocer', 'brightiris', 'homeandroad', 'clothworks', 'jotkey', 'stridewell', 'branchwell', 'platewell', 'everbuilt']); | |
| 11 | + const pending = new Map(); | |
| 12 | + const minimumDigits = 7; | |
| 13 | + const ordinal = n => Number.isSafeInteger(n) && n > 0; | |
| 14 | + const keyFor = site => site === 'projectatom' ? 'atom-visitor-no' : `visitor-odometer-v1:${site}`; | |
| 15 | + function element(tag, name, text = '') { | |
| 16 | + const node = document.createElement(tag); | |
| 17 | + node.className = name; | |
| 18 | + node.textContent = text; | |
| 19 | + return node; | |
| 20 | + } | |
| 21 | + function paint(node, count, mine, unavailable = false) { | |
| 22 | + const numeral = count == null ? (unavailable ? '–' : '·').repeat(minimumDigits) : String(count).padStart(minimumDigits, '0'); | |
| 23 | + const description = count == null ? (unavailable ? 'Visitor count unavailable' : 'Loading visitor count') : `${count.toLocaleString()} visitors`; | |
| 24 | + const accessibleTotal = element('span', 'visitor-odometer-sr', description); | |
| 25 | + accessibleTotal.setAttribute('role', 'status'); | |
| 26 | + const label = element('span', 'visitor-odometer-label', 'Visitors'); | |
| 27 | + label.setAttribute('aria-hidden', 'true'); | |
| 28 | + const digits = element('span', 'visitor-odometer-tiles'); | |
| 29 | + digits.setAttribute('aria-hidden', 'true'); | |
| 30 | + for (const character of numeral) { | |
| 31 | + const digit = element('span', 'visitor-odometer-tile'); | |
| 32 | + digit.append(element('span', 'visitor-odometer-face', character)); | |
| 33 | + digits.append(digit); | |
| 34 | + } | |
| 35 | + const note = element('span', 'visitor-odometer-note', ordinal(mine) ? 'You’re visitor ' : 'Thank you for being here.'); | |
| 36 | + if (ordinal(mine)) { | |
| 37 | + note.append(element('strong', 'visitor-odometer-number', `No. ${mine.toLocaleString()}`), '. Thank you for being here.'); | |
| 38 | + } | |
| 39 | + node.classList.add('visitor-odometer'); | |
| 40 | + node.setAttribute('role', 'group'); | |
| 41 | + node.setAttribute('aria-label', 'Visitor counter'); | |
| 42 | + node.replaceChildren(label, digits, accessibleTotal, note); | |
| 43 | + } | |
| 44 | + function browserNumber(site) { | |
| 45 | + try { | |
| 46 | + const n = Number(window.localStorage.getItem(keyFor(site))); | |
| 47 | + return ordinal(n) ? n : null; | |
| 48 | + } catch { return null; } | |
| 49 | + } | |
| 50 | + async function request(site, method) { | |
| 51 | + const response = await fetch(site === 'projectatom' ? '/api/visits' : `${endpoint}?site=${encodeURIComponent(site)}`, { | |
| 52 | + method, | |
| 53 | + signal: typeof AbortSignal.timeout === 'function' ? AbortSignal.timeout(4500) : undefined, | |
| 54 | + mode: 'cors', | |
| 55 | + credentials: 'omit', | |
| 56 | + referrerPolicy: 'no-referrer', | |
| 57 | + cache: 'no-store', | |
| 58 | + redirect: 'error', | |
| 59 | + }); | |
| 60 | + if (!response.ok) throw new Error('Counter unavailable'); | |
| 61 | + const result = await response.json(); | |
| 62 | + if (!Number.isSafeInteger(result?.count) || result.count < 0) throw new Error('Counter unavailable'); | |
| 63 | + return result; | |
| 64 | + } | |
| 65 | + async function load(site, mine) { | |
| 66 | + const read = () => request(site, 'GET').catch(async () => { | |
| 67 | + await new Promise(resolve => setTimeout(resolve, 400)); | |
| 68 | + return request(site, 'GET'); | |
| 69 | + }); | |
| 70 | + const run = async () => { | |
| 71 | + mine = browserNumber(site) ?? mine; | |
| 72 | + const data = await (mine ? read() : request(site, 'POST').catch(read)); | |
| 73 | + if (ordinal(data.you) && data.you <= data.count) { | |
| 74 | + try { window.localStorage.setItem(keyFor(site), String(data.you)); } catch { /* storage disabled */ } | |
| 75 | + } | |
| 76 | + return data; | |
| 77 | + }; | |
| 78 | + const locks = site === 'projectatom' ? window.navigator?.locks : null; | |
| 79 | + const result = await (locks ? locks.request(keyFor(site), run) : run()); | |
| 80 | + if (ordinal(result.you) && result.you <= result.count) { | |
| 81 | + mine = result.you; | |
| 82 | + // Keep the number only on this browser, for the current site. It is | |
| 83 | + // never placed in the URL or otherwise sent back to the counter. | |
| 84 | + try { window.localStorage.setItem(keyFor(site), String(mine)); } catch { /* storage disabled */ } | |
| 85 | + } | |
| 86 | + return { count: result.count, mine }; | |
| 87 | + } | |
| 88 | + function mount(widget) { | |
| 89 | + if (!widget.isConnected || widget.firstElementChild) return; | |
| 90 | + const site = widget.getAttribute('data-visitor-site'); | |
| 91 | + if (!siteIDs.has(site)) return; | |
| 92 | + const mine = browserNumber(site); | |
| 93 | + paint(widget, null, mine); | |
| 94 | + if (!pending.has(site)) pending.set(site, load(site, mine)); | |
| 95 | + pending.get(site).then(result => { if (widget.isConnected) paint(widget, result.count, result.mine); }) | |
| 96 | + .catch(() => { if (widget.isConnected) paint(widget, null, mine, true); }); | |
| 97 | + } | |
| 98 | + | |
| 99 | + // Hydrating or navigating an SPA can replace server-rendered placeholders. | |
| 100 | + // Reuse the previous request: remounting must not count a second visit. | |
| 101 | + document.querySelectorAll(selector).forEach(mount); | |
| 102 | + new MutationObserver(records => { | |
| 103 | + for (const record of records) { | |
| 104 | + if (record.target.matches?.(selector)) mount(record.target); | |
| 105 | + for (const node of record.addedNodes) { | |
| 106 | + if (node.matches?.(selector)) mount(node); | |
| 107 | + node.querySelectorAll?.(selector).forEach(mount); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + }).observe(document.body, { childList: true, subtree: true }); | |
| 111 | + })(); |
assets/we.js added
| 1 | + /* Watch Encyclopedia stage runtime. Each entry registers WE.mount(slug, fn) and draws on a canvas. */ | |
| 2 | + (function () { | |
| 3 | + var C = { bg: '#0d0f13', panel: '#161a21', ink: '#f1ece2', mut: '#9a927f', dim: '#4d525d', grid: '#232831', acc: '#d5a35a', blue: '#6fb1e6', red: '#e8735c', green: '#7ecb93', violet: '#b79cf0', yellow: '#f0d264', teal: '#5fd0c5', pink: '#ee8fb5' }; | |
| 4 | + var reg = {}, audio = null; | |
| 5 | + function el(tag, cls, txt) { var e = document.createElement(tag); if (cls) e.className = cls; if (txt != null) e.textContent = txt; return e; } | |
| 6 | + function start(root) { | |
| 7 | + var fn = reg[root.dataset.exp]; if (!fn || root._we) return; root._we = 1; | |
| 8 | + var cv = root.querySelector('canvas'), ctx = cv.getContext('2d'), ui = root.querySelector('.ctl'), cap = root.querySelector('.cap'); | |
| 9 | + var S = { el: root, cv: cv, ctx: ctx, C: C, W: 0, H: 0, t: 0, dirty: true, TAU: Math.PI * 2 }; | |
| 10 | + function size() { | |
| 11 | + var r = cv.getBoundingClientRect(), d = Math.min(2, window.devicePixelRatio || 1); | |
| 12 | + if (!r.width) return; | |
| 13 | + S.W = r.width; S.H = r.height; S.dpr = d; S.u = Math.min(S.W, S.H); | |
| 14 | + cv.width = Math.round(r.width * d); cv.height = Math.round(r.height * d); | |
| 15 | + ctx.setTransform(d, 0, 0, d, 0, 0); S.dirty = true; if (S.onresize) S.onresize(); | |
| 16 | + } | |
| 17 | + S.clear = function (c) { ctx.fillStyle = c || C.bg; ctx.fillRect(0, 0, S.W, S.H); }; | |
| 18 | + S.txt = function (s, x, y, col, px, align, wt) { ctx.fillStyle = col || C.ink; ctx.font = (wt || 500) + ' ' + (px || 13) + 'px system-ui,-apple-system,"Segoe UI",sans-serif'; ctx.textAlign = align || 'left'; ctx.textBaseline = 'middle'; ctx.fillText(s, x, y); }; | |
| 19 | + S.ln = function (x1, y1, x2, y2, col, w) { ctx.strokeStyle = col || C.ink; ctx.lineWidth = w || 1; ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); }; | |
| 20 | + S.dot = function (x, y, r, col) { ctx.fillStyle = col || C.ink; ctx.beginPath(); ctx.arc(x, y, Math.max(0, r), 0, 6.2832); ctx.fill(); }; | |
| 21 | + S.ring = function (x, y, r, col, w) { ctx.strokeStyle = col || C.ink; ctx.lineWidth = w || 1; ctx.beginPath(); ctx.arc(x, y, Math.max(0, r), 0, 6.2832); ctx.stroke(); }; | |
| 22 | + S.arrow = function (x1, y1, x2, y2, col, w) { var a = Math.atan2(y2 - y1, x2 - x1), h = 7 + (w || 1.5) * 1.5; S.ln(x1, y1, x2, y2, col, w || 1.5); ctx.fillStyle = col || C.ink; ctx.beginPath(); ctx.moveTo(x2, y2); ctx.lineTo(x2 - h * Math.cos(a - .45), y2 - h * Math.sin(a - .45)); ctx.lineTo(x2 - h * Math.cos(a + .45), y2 - h * Math.sin(a + .45)); ctx.fill(); }; | |
| 23 | + S.rr = function (x, y, w, h, r, fill, stroke) { ctx.beginPath(); if (ctx.roundRect) ctx.roundRect(x, y, w, h, r); else ctx.rect(x, y, w, h); if (fill) { ctx.fillStyle = fill; ctx.fill(); } if (stroke) { ctx.strokeStyle = stroke; ctx.lineWidth = 1; ctx.stroke(); } }; | |
| 24 | + S.say = function (h) { if (cap && cap._h !== h) { cap._h = h; cap.innerHTML = h; } }; | |
| 25 | + S.small = function () { return S.W < 560; }; | |
| 26 | + // ---- controls | |
| 27 | + S.slider = function (label, min, max, val, step, fmt, cb) { | |
| 28 | + var w = el('label', 'c-sl'), top = el('span', 'c-lab'), nm = el('span', '', label), out = el('b'), inp = el('input'); | |
| 29 | + inp.type = 'range'; inp.min = min; inp.max = max; inp.step = step || 1; inp.value = val; | |
| 30 | + top.appendChild(nm); top.appendChild(out); w.appendChild(top); w.appendChild(inp); ui.appendChild(w); | |
| 31 | + var o = { v: +val, el: w, set: function (v) { o.v = +v; inp.value = v; out.textContent = fmt ? fmt(o.v) : o.v; S.dirty = true; } }; | |
| 32 | + inp.addEventListener('input', function () { o.v = +inp.value; out.textContent = fmt ? fmt(o.v) : o.v; S.dirty = true; if (cb) cb(o.v); }); | |
| 33 | + out.textContent = fmt ? fmt(o.v) : o.v; return o; | |
| 34 | + }; | |
| 35 | + S.toggle = function (label, on, cb) { | |
| 36 | + var b = el('button', 'c-tg', label); b.type = 'button'; b.setAttribute('aria-pressed', !!on); ui.appendChild(b); | |
| 37 | + var o = { v: !!on, el: b, set: function (v) { o.v = !!v; b.setAttribute('aria-pressed', o.v); S.dirty = true; } }; | |
| 38 | + b.addEventListener('click', function () { o.set(!o.v); if (cb) cb(o.v); }); return o; | |
| 39 | + }; | |
| 40 | + S.button = function (label, cb) { var b = el('button', 'c-bt', label); b.type = 'button'; ui.appendChild(b); b.addEventListener('click', function () { cb(); S.dirty = true; }); return b; }; | |
| 41 | + S.select = function (label, opts, val, cb) { | |
| 42 | + var w = el('div', 'c-seg'); w.setAttribute('role', 'group'); w.setAttribute('aria-label', label); | |
| 43 | + if (label) w.appendChild(el('span', 'c-lab', label)); | |
| 44 | + var row = el('div', 'c-row'); w.appendChild(row); ui.appendChild(w); | |
| 45 | + var o = { v: val, el: w, set: function (v) { o.v = v; [].forEach.call(row.children, function (b) { b.setAttribute('aria-pressed', b.dataset.v === String(v)); }); S.dirty = true; } }; | |
| 46 | + opts.forEach(function (op) { var v = op[0], b = el('button', '', op[1]); b.type = 'button'; b.dataset.v = v; row.appendChild(b); b.addEventListener('click', function () { o.set(v); if (cb) cb(v); }); }); | |
| 47 | + o.set(val); return o; | |
| 48 | + }; | |
| 49 | + S.input = function (label, val, cb, max) { | |
| 50 | + var w = el('label', 'c-sl c-in'), top = el('span', 'c-lab', label), inp = el('input'); inp.type = 'text'; inp.value = val; inp.maxLength = max || 60; inp.autocomplete = 'off'; inp.spellcheck = false; | |
| 51 | + w.appendChild(top); w.appendChild(inp); ui.appendChild(w); var o = { v: val, el: inp }; | |
| 52 | + inp.addEventListener('input', function () { o.v = inp.value; S.dirty = true; if (cb) cb(o.v); }); return o; | |
| 53 | + }; | |
| 54 | + S.note = function (txt) { var p = el('span', 'c-note', txt); ui.appendChild(p); return p; }; | |
| 55 | + // ---- pointer (canvas coords in CSS px) | |
| 56 | + S.ptr = { x: -1, y: -1, down: false }; | |
| 57 | + S.pointer = function (h) { | |
| 58 | + cv.style.touchAction = h.scroll ? 'pan-y' : 'none'; cv.style.cursor = h.cursor || 'pointer'; | |
| 59 | + function pos(e) { var r = cv.getBoundingClientRect(); S.ptr.x = e.clientX - r.left; S.ptr.y = e.clientY - r.top; } | |
| 60 | + cv.addEventListener('pointerdown', function (e) { pos(e); S.ptr.down = true; try { cv.setPointerCapture(e.pointerId); } catch (x) { } if (h.down) h.down(S.ptr.x, S.ptr.y, e); S.dirty = true; }); | |
| 61 | + cv.addEventListener('pointermove', function (e) { pos(e); if (h.move) h.move(S.ptr.x, S.ptr.y, S.ptr.down, e); S.dirty = true; }); | |
| 62 | + function up(e) { if (!S.ptr.down) return; S.ptr.down = false; if (h.up) h.up(S.ptr.x, S.ptr.y, e); S.dirty = true; } | |
| 63 | + cv.addEventListener('pointerup', up); cv.addEventListener('pointercancel', up); | |
| 64 | + cv.addEventListener('pointerleave', function () { if (!S.ptr.down) { S.ptr.x = -1; S.ptr.y = -1; S.dirty = true; } }); | |
| 65 | + if (h.wheel) cv.addEventListener('wheel', function (e) { e.preventDefault(); pos(e); h.wheel(e.deltaY, S.ptr.x, S.ptr.y); S.dirty = true; }, { passive: false }); | |
| 66 | + }; | |
| 67 | + // ---- sound (only after a tap) | |
| 68 | + S.tone = function (f, dur, type, vol, when) { | |
| 69 | + try { | |
| 70 | + audio = audio || new (window.AudioContext || window.webkitAudioContext)(); if (audio.state === 'suspended') audio.resume(); | |
| 71 | + var o = audio.createOscillator(), g = audio.createGain(), t0 = audio.currentTime + (when || 0); | |
| 72 | + o.type = type || 'sine'; o.frequency.value = f; g.gain.setValueAtTime(0, t0); g.gain.linearRampToValueAtTime(vol || .12, t0 + .01); g.gain.exponentialRampToValueAtTime(.0001, t0 + (dur || .3)); | |
| 73 | + o.connect(g); g.connect(audio.destination); o.start(t0); o.stop(t0 + (dur || .3) + .05); return o; | |
| 74 | + } catch (x) { } | |
| 75 | + }; | |
| 76 | + // ---- loop | |
| 77 | + var vis = true, raf = 0, last = 0, frame = null; | |
| 78 | + function tick(now) { | |
| 79 | + raf = 0; if (!vis || document.hidden) return; | |
| 80 | + var dt = Math.min(.05, (now - last) / 1000 || 0); last = now; S.t += dt; | |
| 81 | + if (frame) frame(dt, S.t); raf = requestAnimationFrame(tick); | |
| 82 | + } | |
| 83 | + function kick() { if (!raf && frame) { last = performance.now(); raf = requestAnimationFrame(tick); } } | |
| 84 | + S.loop = function (f) { frame = f; kick(); }; | |
| 85 | + if ('IntersectionObserver' in window) new IntersectionObserver(function (en) { vis = en[0].isIntersecting; if (vis) kick(); }, { rootMargin: '80px' }).observe(root); | |
| 86 | + document.addEventListener('visibilitychange', kick); | |
| 87 | + if ('ResizeObserver' in window) new ResizeObserver(size).observe(cv); else window.addEventListener('resize', size); | |
| 88 | + var fs = root.querySelector('.fs'); | |
| 89 | + if (fs) { if (!root.requestFullscreen) fs.hidden = true; fs.addEventListener('click', function () { if (document.fullscreenElement) document.exitFullscreen(); else root.requestFullscreen(); }); } | |
| 90 | + size(); fn(S); size(); | |
| 91 | + } | |
| 92 | + function boot() { [].forEach.call(document.querySelectorAll('.stage[data-exp]'), start); } | |
| 93 | + window.WE = { mount: function (slug, fn) { reg[slug] = fn; if (document.readyState !== 'loading') boot(); }, C: C }; | |
| 94 | + if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot); else boot(); | |
| 95 | + })(); |
binary/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>Binary Numbers | Watch Encyclopedia</title><meta name="description" content="Flip eight switches and see how ones and zeros become numbers, letters and shades."><link rel="canonical" href="https://watchencyclopedia.org/binary/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="Binary Numbers | Watch Encyclopedia"><meta property="og:description" content="Flip eight switches and see how ones and zeros become numbers, letters and shades."><meta property="og:url" content="https://watchencyclopedia.org/binary/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "Binary Numbers", "description": "Flip eight switches and see how ones and zeros become numbers, letters and shades.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Computing</a></div><h1>Binary Numbers</h1><p class="lede">Computers store everything as ones and zeros. Flip eight switches and see how that can mean anything at all.</p></div><section class="stage " data-exp="binary"><div class="scr"><canvas role="img" aria-label="Binary Numbers, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>Each switch is worth double the one to its right: 1, 2, 4, 8 and so on. Add up the ones that are on.</p><p>The same eight bits can be read as a number, a letter or a brightness. A photo, a song and this page are all long rows of switches like these.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Make the number 100.</li><li>Turn on Count up and watch the pattern ripple.</li><li>Press Double it and see every bit slide one place left.</li><li>Find the capital letter A. It is 65.</li></ul></div><div class="panel" style="margin-top:20px"><h2>Numbers</h2><dl class="facts"><dt>Values in one byte</dt><dd>256</dd><dt>Largest value</dt><dd>255</dd><dt>Capital A</dt><dd>65, or 01000001</dd></dl></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/life/" data-cat="computing" data-t="the game of life not a game you play. a grid of cells follows one small rule, and things that look alive appear by themselves. computing"><span class="th" style="background-image:url(/thumb/life.webp)" role="img" aria-label="The Game of Life"></span><span class="tb"><p class="k">Computing</p><h3>The Game of Life</h3><p>Draw a few cells, press run, and watch a tiny rule grow into moving machines.</p></span></a><a class="tile" href="/sorting/" data-cat="computing" data-t="how computers sort putting things in order is one of the most common jobs a computer does. some methods are far smarter than others. computing"><span class="th" style="background-image:url(/thumb/sorting.webp)" role="img" aria-label="How Computers Sort"></span><span class="tb"><p class="k">Computing</p><h3>How Computers Sort</h3><p>Race five classic ways to put a shuffled row of bars in order.</p></span></a><a class="tile" href="/pathfinding/" data-cat="computing" data-t="finding the shortest route how does a map app find your route? build a maze and watch two classic methods search it. computing"><span class="th" style="background-image:url(/thumb/pathfinding.webp)" role="img" aria-label="Finding the Shortest Route"></span><span class="tb"><p class="k">Computing</p><h3>Finding the Shortest Route</h3><p>Draw walls between two points and watch a computer hunt for the way through.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/binary.js?v=12306844"></script></body></html> |
care/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>Caring for a watch | Watch Encyclopedia</title><meta name="description" content="How to care for a watch: water resistance, winding, servicing, magnetism, cleaning and checking accuracy."><link rel="canonical" href="https://watchencyclopedia.org/care/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="Caring for a watch | Watch Encyclopedia"><meta property="og:description" content="How to care for a watch: water resistance, winding, servicing, magnetism, cleaning and checking accuracy."><meta property="og:url" content="https://watchencyclopedia.org/care/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "Article", "headline": "Caring for a watch", "description": "How to care for a watch: water resistance, winding, servicing, magnetism, cleaning and checking accuracy.", "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="page-h"><div class="crumbs"><a href="/">Home</a> / Caring for a watch</div><p class="k">Keep it running</p><h1>Caring for a watch</h1><p class="lede">A little care keeps a watch accurate, sealed and good-looking for decades. Start by taking one underwater.</p></div> | |
| 8 | + <section class="stage " data-exp="water-resistance"><div class="scr"><canvas role="img" aria-label="Interactive model"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="layout"><aside class="toc"><b>On this page</b><a href="#wr">Water resistance, read plainly</a><a href="#winding">Winding and setting</a><a href="#service">Servicing</a><a href="#magnetism">Magnetism</a><a href="#cleaning">Cleaning and storage</a><a href="#accuracy">Checking accuracy</a></aside><article><h2 id="wr">Water resistance, read plainly</h2><p>Water resistance numbers come from a pressure test in a lab, not a real dive. Treat them as a rough guide to what a watch is built for, not a depth limit.</p><div class='fig'><svg viewBox="0 0 900 300" xmlns="http://www.w3.org/2000/svg" class="diagram"><g font-family="system-ui,sans-serif" font-size="17" fill="var(--ink)"><rect x="20" y="20" width="180" height="42" rx="21" fill="var(--accent)" fill-opacity="0.32"/><text x="40" y="47" font-weight="700">30 m / 3 bar</text><text x="230" y="47">Splashes, rain, hand washing</text><rect x="20" y="76" width="240" height="42" rx="21" fill="var(--accent)" fill-opacity="0.46"/><text x="40" y="103" font-weight="700">50 m / 5 bar</text><text x="290" y="103">Brief swims in calm water</text><rect x="20" y="132" width="300" height="42" rx="21" fill="var(--accent)" fill-opacity="0.60"/><text x="40" y="159" font-weight="700">100 m / 10 bar</text><text x="350" y="159">Swimming and snorkeling</text><rect x="20" y="188" width="360" height="42" rx="21" fill="var(--accent)" fill-opacity="0.74"/><text x="40" y="215" font-weight="700">200 m / 20 bar</text><text x="410" y="215">Diving with a dive-rated watch</text><rect x="20" y="244" width="420" height="42" rx="21" fill="var(--accent)" fill-opacity="0.88"/><text x="40" y="271" font-weight="700">300 m+</text><text x="470" y="271">Serious diving, built to dive standards</text></g></svg></div><ul><li>Never use the crown or pushers underwater unless the watch says it is made for it.</li><li>Screw the crown fully down before swimming, if it is a screw-down crown.</li><li>Gaskets age. Have water resistance checked every year or two if you swim with your watch.</li><li>Hot showers, saunas and hot tubs are hard on gaskets. Take the watch off.</li></ul><h2 id="winding">Winding and setting</h2><p>Wind a hand-wound watch at about the same time each day, until you feel firm resistance, then stop. Automatics wind as you wear them; give one 20 to 30 crown turns if it has stopped.</p><p>Avoid changing the date between about 9 PM and 3 AM on many mechanical watches, when the date wheel is already engaged. Set the time past 6 o'clock first, then set the date.</p><h2 id="service">Servicing</h2><p>Mechanical watches use tiny amounts of oil that thicken over time. A watchmaker takes the movement apart, cleans it, oils it, adjusts it and reseals the case. Many makers suggest a service every five to ten years, or sooner if the watch starts running fast, slow or stops early.</p><p>Quartz watches need a new battery every few years. Replace a dead one soon, since an old battery can leak.</p><h2 id="magnetism">Magnetism</h2><p>Phones, laptop lids, speakers and bag clasps hold strong magnets. If they magnetize a steel hairspring, its coils stick together and the watch suddenly runs very fast. A watchmaker can demagnetize it in seconds. Some modern watches use silicon or special alloys that are unaffected.</p><h2 id="cleaning">Cleaning and storage</h2><p>Wipe the case with a soft cloth. Clean a metal bracelet with a soft toothbrush and mild soapy water, if the watch is water resistant. Dry leather straps away from heat.</p><p>Store watches out of direct sun, away from magnets and away from each other so they don't scratch. A watch you won't wear for months can simply be left to stop.</p><h2 id="accuracy">Checking accuracy</h2><p>Set your watch to an atomic time source, then check it at the same time each day for a week. Divide the total gain or loss by seven to get its daily rate. Many mechanical watches run within a few seconds to about 20 seconds a day; how you store it overnight (dial up, crown down) can nudge the rate a few seconds either way.</p></article></div> | |
| 9 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 10 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/water-resistance.js?v=12306844"></script></body></html> |
circuit/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>A Simple Circuit | Watch Encyclopedia</title><meta name="description" content="Turn up the battery or the resistance and watch the current and the bulb respond."><link rel="canonical" href="https://watchencyclopedia.org/circuit/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="A Simple Circuit | Watch Encyclopedia"><meta property="og:description" content="Turn up the battery or the resistance and watch the current and the bulb respond."><meta property="og:url" content="https://watchencyclopedia.org/circuit/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "A Simple Circuit", "description": "Turn up the battery or the resistance and watch the current and the bulb respond.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Physics</a></div><h1>A Simple Circuit</h1><p class="lede">A battery pushes, a resistor holds back, and the current is what gets through. Change both and watch.</p></div><section class="stage " data-exp="circuit"><div class="scr"><canvas role="img" aria-label="A Simple Circuit, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>A loop of wire with a battery, a bulb and a resistor. The moving dots stand for the flow of charge.</p><p>Real electrons drift far slower than this, about a millimeter a second, but the push travels around the loop almost at once.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Double the voltage.</li><li>Double the resistance.</li><li>Find two settings that give the same current.</li></ul></div><div class="panel" style="margin-top:20px"><h2>Numbers</h2><dl class="facts"><dt>Law</dt><dd>Current = voltage ÷ resistance</dd><dt>Power</dt><dd>Voltage × current</dd></dl></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/pendulum/" data-cat="physics" data-t="the pendulum pull the weight back and let go. then change the string and the planet, and see what changes the beat. physics"><span class="th" style="background-image:url(/thumb/pendulum.webp)" role="img" aria-label="The Pendulum"></span><span class="tb"><p class="k">Physics</p><h3>The Pendulum</h3><p>Swing a weight on a string and find out what sets its rhythm.</p></span></a><a class="tile" href="/waves/" data-cat="physics" data-t="waves and interference drop two stones in a pond. where the ripples cross they add up in some places and cancel in others. physics"><span class="th" style="background-image:url(/thumb/waves.webp)" role="img" aria-label="Waves and Interference"></span><span class="tb"><p class="k">Physics</p><h3>Waves and Interference</h3><p>Two ripples cross and build a pattern of bright bands and calm lines.</p></span></a><a class="tile" href="/doppler/" data-cat="physics" data-t="the doppler effect a moving source squashes its waves in front and stretches them behind. speed it up until it breaks the sound barrier. physics"><span class="th" style="background-image:url(/thumb/doppler.webp)" role="img" aria-label="The Doppler Effect"></span><span class="tb"><p class="k">Physics</p><h3>The Doppler Effect</h3><p>See why a siren drops in pitch as it passes, and what happens faster than sound.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/circuit.js?v=12306844"></script></body></html> |
color-mixing/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>Mixing Color | Watch Encyclopedia</title><meta name="description" content="Slide red, green and blue light together, then switch to ink and get the opposite."><link rel="canonical" href="https://watchencyclopedia.org/color-mixing/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="Mixing Color | Watch Encyclopedia"><meta property="og:description" content="Slide red, green and blue light together, then switch to ink and get the opposite."><meta property="og:url" content="https://watchencyclopedia.org/color-mixing/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "Mixing Color", "description": "Slide red, green and blue light together, then switch to ink and get the opposite.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Physics</a></div><h1>Mixing Color</h1><p class="lede">Screens mix light. Printers mix ink. They work in opposite ways, and you can try both.</p></div><section class="stage " data-exp="color-mixing"><div class="scr"><canvas role="img" aria-label="Mixing Color, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>Three overlapping circles. With light, each one adds brightness, and all three make white. With ink, each one soaks up part of the light, and all three make black.</p><p>Your eyes have three kinds of color sensor, which is why three colors are enough.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Overlap red and green light. Most people are surprised by yellow.</li><li>Switch to ink and make red from magenta and yellow.</li><li>Move the ring over each overlap.</li></ul></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/pendulum/" data-cat="physics" data-t="the pendulum pull the weight back and let go. then change the string and the planet, and see what changes the beat. physics"><span class="th" style="background-image:url(/thumb/pendulum.webp)" role="img" aria-label="The Pendulum"></span><span class="tb"><p class="k">Physics</p><h3>The Pendulum</h3><p>Swing a weight on a string and find out what sets its rhythm.</p></span></a><a class="tile" href="/waves/" data-cat="physics" data-t="waves and interference drop two stones in a pond. where the ripples cross they add up in some places and cancel in others. physics"><span class="th" style="background-image:url(/thumb/waves.webp)" role="img" aria-label="Waves and Interference"></span><span class="tb"><p class="k">Physics</p><h3>Waves and Interference</h3><p>Two ripples cross and build a pattern of bright bands and calm lines.</p></span></a><a class="tile" href="/doppler/" data-cat="physics" data-t="the doppler effect a moving source squashes its waves in front and stretches them behind. speed it up until it breaks the sound barrier. physics"><span class="th" style="background-image:url(/thumb/doppler.webp)" role="img" aria-label="The Doppler Effect"></span><span class="tb"><p class="k">Physics</p><h3>The Doppler Effect</h3><p>See why a siren drops in pitch as it passes, and what happens faster than sound.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/color-mixing.js?v=12306844"></script></body></html> |
complications/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>Complications | Watch Encyclopedia</title><meta name="description" content="Watch complications explained: date, chronograph, GMT, moon phase, perpetual calendar, tourbillon, minute repeater and more."><link rel="canonical" href="https://watchencyclopedia.org/complications/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="Complications | Watch Encyclopedia"><meta property="og:description" content="Watch complications explained: date, chronograph, GMT, moon phase, perpetual calendar, tourbillon, minute repeater and more."><meta property="og:url" content="https://watchencyclopedia.org/complications/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "Article", "headline": "Complications", "description": "Watch complications explained: date, chronograph, GMT, moon phase, perpetual calendar, tourbillon, minute repeater and more.", "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="page-h"><div class="crumbs"><a href="/">Home</a> / Complications</div><p class="k">Beyond the time</p><h1>Complications</h1><p class="lede">Any function beyond hours, minutes and seconds is a complication. Switch them on and off on the dial, then read about each.</p></div> | |
| 8 | + <section class="stage " data-exp="complications"><div class="scr"><canvas role="img" aria-label="Interactive model"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="layout"><aside class="toc"><b>On this page</b><a href="#date">Date</a><a href="#day-date">Day and date</a><a href="#gmt">GMT and dual time</a><a href="#world-time">World time</a><a href="#chronograph">Chronograph</a><a href="#flyback">Flyback chronograph</a><a href="#moonphase">Moon phase</a><a href="#power-reserve">Power reserve indicator</a><a href="#annual">Annual calendar</a><a href="#perpetual">Perpetual calendar</a><a href="#alarm">Alarm</a><a href="#repeater">Minute repeater</a><a href="#tourbillon">Tourbillon</a><a href="#equation">Equation of time</a></aside><article><h2 id="date">Date</h2><p>Shows the day of the month in a small window. A wheel printed 1 to 31 advances once each night around midnight. In months shorter than 31 days, a simple date needs to be moved forward by hand.</p><h2 id="day-date">Day and date</h2><p>Adds the day of the week, either in a second window or spelled out beside the date.</p><h2 id="gmt">GMT and dual time</h2><p>An extra hour hand that goes around once every 24 hours, read against a 24-hour scale on the dial or bezel. Set it to a second time zone and you can read home time and local time at a glance.</p><h2 id="world-time">World time</h2><p>A rotating ring of city names and a 24-hour ring show the time in all 24 standard time zones at once.</p><h2 id="chronograph">Chronograph</h2><p>A stopwatch built into the watch. Pushers start, stop and reset a central seconds hand, while small subdials count elapsed minutes and hours. Tachymeter scales on the bezel turn a timed distance into an average speed.</p><h2 id="flyback">Flyback chronograph</h2><p>A chronograph that can be reset and restarted with a single press while running, once prized by pilots timing successive legs of a flight.</p><h2 id="moonphase">Moon phase</h2><p>A disc painted with two moons turns slowly behind a curved opening to show the moon's phase. A common gear ratio is off by about one day every two and a half years; finer designs stay right for over a century.</p><div class='fig'><svg viewBox="0 0 900 190" xmlns="http://www.w3.org/2000/svg" class="diagram"><g font-family="system-ui,sans-serif" font-size="13" fill="var(--ink)" text-anchor="middle"><circle cx="56" cy="80" r="38" fill="#3b362f" stroke="var(--ink)" stroke-width="1.2"/><text x="56" y="150">New</text><circle cx="168" cy="80" r="38" fill="#3b362f" stroke="var(--ink)" stroke-width="1.2"/><path d="M168,42 A38,38 0 0 1 168,118 A26.9,38 0 0 0 168,42 Z" fill="var(--accent)"/><text x="168" y="150">Waxing crescent</text><circle cx="280" cy="80" r="38" fill="#3b362f" stroke="var(--ink)" stroke-width="1.2"/><path d="M280,42 A38,38 0 0 1 280,118 Z" fill="var(--accent)"/><text x="280" y="150">First quarter</text><circle cx="392" cy="80" r="38" fill="#3b362f" stroke="var(--ink)" stroke-width="1.2"/><path d="M392,42 A38,38 0 0 1 392,118 A26.9,38 0 0 1 392,42 Z" fill="var(--accent)"/><text x="392" y="150">Waxing gibbous</text><circle cx="504" cy="80" r="38" fill="#3b362f" stroke="var(--ink)" stroke-width="1.2"/><circle cx="504" cy="80" r="38" fill="var(--accent)"/><text x="504" y="150">Full</text><circle cx="616" cy="80" r="38" fill="#3b362f" stroke="var(--ink)" stroke-width="1.2"/><path d="M616,42 A38,38 0 0 0 616,118 A26.9,38 0 0 0 616,42 Z" fill="var(--accent)"/><text x="616" y="150">Waning gibbous</text><circle cx="728" cy="80" r="38" fill="#3b362f" stroke="var(--ink)" stroke-width="1.2"/><path d="M728,42 A38,38 0 0 0 728,118 Z" fill="var(--accent)"/><text x="728" y="150">Last quarter</text><circle cx="840" cy="80" r="38" fill="#3b362f" stroke="var(--ink)" stroke-width="1.2"/><path d="M840,42 A38,38 0 0 0 840,118 A26.9,38 0 0 1 840,42 Z" fill="var(--accent)"/><text x="840" y="150">Waning crescent</text></g></svg></div><h2 id="power-reserve">Power reserve indicator</h2><p>A small hand that shows how much energy is left in the mainspring, like a fuel gauge.</p><h2 id="annual">Annual calendar</h2><p>Knows which months have 30 days and which have 31, so it only needs one correction a year, at the end of February.</p><h2 id="perpetual">Perpetual calendar</h2><p>Tracks the date, day, month and leap-year cycle mechanically. Most will not need a date correction until the year 2100, which skips its leap day.</p><h2 id="alarm">Alarm</h2><p>A second mainspring powers a small hammer that buzzes against a pin or the case at a time you set.</p><h2 id="repeater">Minute repeater</h2><p>Chimes the time on demand. Slide a lever and tiny hammers strike gongs: low tones for hours, paired tones for quarter hours, high tones for minutes. Among the hardest mechanisms to build.</p><h2 id="tourbillon">Tourbillon</h2><p>Puts the escapement and balance in a small rotating cage, usually turning once a minute, to average out the effect of gravity when a watch sits in one position. Today it is admired mostly as a feat of craft.</p><h2 id="equation">Equation of time</h2><p>Shows the difference between clock time and solar time, which drifts by up to about 16 minutes over the year.</p></article></div> | |
| 9 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 10 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/complications.js?v=12306844"></script></body></html> |
dna/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>Reading DNA | Watch Encyclopedia</title><meta name="description" content="Change one letter of a real human gene and see what it does to the protein."><link rel="canonical" href="https://watchencyclopedia.org/dna/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="Reading DNA | Watch Encyclopedia"><meta property="og:description" content="Change one letter of a real human gene and see what it does to the protein."><meta property="og:url" content="https://watchencyclopedia.org/dna/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "Reading DNA", "description": "Change one letter of a real human gene and see what it does to the protein.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Life</a></div><h1>Reading DNA</h1><p class="lede">DNA is a message written in four letters. Change one and watch the meaning change.</p></div><section class="stage " data-exp="dna"><div class="scr"><canvas role="img" aria-label="Reading DNA, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>The letters are the first 30 of a real human gene, HBB. The cell reads them three at a time, and each triplet names an amino acid, a building block of a protein.</p><p>The short names are standard: Glu is glutamic acid, Val is valine, and so on. The helix is a simple drawing and not to scale.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Press Make the sickle cell change and find the one letter that moved.</li><li>Change the last letter of a triplet. Often nothing happens.</li><li>Try to make a Stop signal.</li></ul></div><div class="panel" style="margin-top:20px"><h2>Numbers</h2><dl class="facts"><dt>Letters in the DNA alphabet</dt><dd>4</dd><dt>Letters in human DNA</dt><dd>About 3 billion</dd><dt>Triplets that mean Stop</dt><dd>3</dd></dl></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/heart/" data-cat="life" data-t="how the heart pumps your heart is two pumps in one. follow the blood out to the lungs, back, and around the whole body. life"><span class="th" style="background-image:url(/thumb/heart.webp)" role="img" aria-label="How the Heart Pumps"></span><span class="tb"><p class="k">Life</p><h3>How the Heart Pumps</h3><p>Follow blood around the body's double loop and set the pace of the beat.</p></span></a><a class="tile" href="/everything-launched/" data-cat="space" data-t="everything we've ever launched since sputnik in 1957, people have put tens of thousands of objects into orbit. press play and watch them pile up around the earth. space"><span class="th" style="background-image:url(/thumb/everything-launched.webp)" role="img" aria-label="Everything We've Ever Launched"></span><span class="tb"><p class="k">Space</p><h3>Everything We've Ever Launched</h3><p>Every tracked object in Earth orbit since 1957, on a 3D Earth you can scrub through time.</p></span></a><a class="tile" href="/phone-teardown/" data-cat="machines" data-t="folding phone teardown what is inside a folding phone? take one apart in your browser, one part at a time, in the order a real repair would go. machines"><span class="th" style="background-image:url(/img/phone-teardown.webp)" role="img" aria-label="Folding Phone Teardown"></span><span class="tb"><p class="k">Machines</p><h3>Folding Phone Teardown</h3><p>Take a folding phone apart in 3D, piece by piece, in the order a repair goes.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/dna.js?v=12306844"></script></body></html> |
doppler/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>The Doppler Effect | Watch Encyclopedia</title><meta name="description" content="See why a siren drops in pitch as it passes, and what happens faster than sound."><link rel="canonical" href="https://watchencyclopedia.org/doppler/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="The Doppler Effect | Watch Encyclopedia"><meta property="og:description" content="See why a siren drops in pitch as it passes, and what happens faster than sound."><meta property="og:url" content="https://watchencyclopedia.org/doppler/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "The Doppler Effect", "description": "See why a siren drops in pitch as it passes, and what happens faster than sound.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Physics</a></div><h1>The Doppler Effect</h1><p class="lede">A moving source squashes its waves in front and stretches them behind. Speed it up until it breaks the sound barrier.</p></div><section class="stage " data-exp="doppler"><div class="scr"><canvas role="img" aria-label="The Doppler Effect, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>Each ring is a sound wave spreading out from where the source was when it made it. Because the source keeps moving, the rings are not centered on each other.</p><p>The same effect on light tells us that distant galaxies are moving away.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Press Hear it pass.</li><li>Set the speed to exactly 100%. Every wave piles up at the nose.</li><li>Go faster and watch the cone form.</li></ul></div><div class="panel" style="margin-top:20px"><h2>Numbers</h2><dl class="facts"><dt>Speed of sound in air</dt><dd>About 343 m/s at 20 °C</dd></dl></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/pendulum/" data-cat="physics" data-t="the pendulum pull the weight back and let go. then change the string and the planet, and see what changes the beat. physics"><span class="th" style="background-image:url(/thumb/pendulum.webp)" role="img" aria-label="The Pendulum"></span><span class="tb"><p class="k">Physics</p><h3>The Pendulum</h3><p>Swing a weight on a string and find out what sets its rhythm.</p></span></a><a class="tile" href="/waves/" data-cat="physics" data-t="waves and interference drop two stones in a pond. where the ripples cross they add up in some places and cancel in others. physics"><span class="th" style="background-image:url(/thumb/waves.webp)" role="img" aria-label="Waves and Interference"></span><span class="tb"><p class="k">Physics</p><h3>Waves and Interference</h3><p>Two ripples cross and build a pattern of bright bands and calm lines.</p></span></a><a class="tile" href="/projectile/" data-cat="physics" data-t="throwing things what angle throws farthest? launch, compare and find out, then add air or go to the moon. physics"><span class="th" style="background-image:url(/thumb/projectile.webp)" role="img" aria-label="Throwing Things"></span><span class="tb"><p class="k">Physics</p><h3>Throwing Things</h3><p>Launch a ball at any angle and speed, with or without air, on three worlds.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/doppler.js?v=12306844"></script></body></html> |
double-pendulum/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>The Double Pendulum | Watch Encyclopedia</title><meta name="description" content="Two swinging arms, simple rules, wild motion. Start two almost alike and watch them part."><link rel="canonical" href="https://watchencyclopedia.org/double-pendulum/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="The Double Pendulum | Watch Encyclopedia"><meta property="og:description" content="Two swinging arms, simple rules, wild motion. Start two almost alike and watch them part."><meta property="og:url" content="https://watchencyclopedia.org/double-pendulum/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "The Double Pendulum", "description": "Two swinging arms, simple rules, wild motion. Start two almost alike and watch them part.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Physics</a></div><h1>The Double Pendulum</h1><p class="lede">Hang one pendulum from another and the tidy swing turns into chaos. The rules are simple. The motion is not.</p></div><section class="stage " data-exp="double-pendulum"><div class="scr"><canvas role="img" aria-label="The Double Pendulum, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>The second set of arms starts a tiny fraction of a degree away from the first. For a while they move together. Then they split and never agree again.</p><p>This is what chaos means in physics: not random, but so sensitive to the start that long forecasts fail. Weather works the same way.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Drag the arms up high and let go.</li><li>Start from a small angle. The motion stays calm and the twins stay together.</li><li>Watch how long the two take to split apart.</li></ul></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/pendulum/" data-cat="physics" data-t="the pendulum pull the weight back and let go. then change the string and the planet, and see what changes the beat. physics"><span class="th" style="background-image:url(/thumb/pendulum.webp)" role="img" aria-label="The Pendulum"></span><span class="tb"><p class="k">Physics</p><h3>The Pendulum</h3><p>Swing a weight on a string and find out what sets its rhythm.</p></span></a><a class="tile" href="/waves/" data-cat="physics" data-t="waves and interference drop two stones in a pond. where the ripples cross they add up in some places and cancel in others. physics"><span class="th" style="background-image:url(/thumb/waves.webp)" role="img" aria-label="Waves and Interference"></span><span class="tb"><p class="k">Physics</p><h3>Waves and Interference</h3><p>Two ripples cross and build a pattern of bright bands and calm lines.</p></span></a><a class="tile" href="/doppler/" data-cat="physics" data-t="the doppler effect a moving source squashes its waves in front and stretches them behind. speed it up until it breaks the sound barrier. physics"><span class="th" style="background-image:url(/thumb/doppler.webp)" role="img" aria-label="The Doppler Effect"></span><span class="tb"><p class="k">Physics</p><h3>The Doppler Effect</h3><p>See why a siren drops in pitch as it passes, and what happens faster than sound.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/double-pendulum.js?v=12306844"></script></body></html> |
earth-layers/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>Inside the Earth | Watch Encyclopedia</title><meta name="description" content="Sink from your feet to the center of the planet through rock, liquid iron and a solid core."><link rel="canonical" href="https://watchencyclopedia.org/earth-layers/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="Inside the Earth | Watch Encyclopedia"><meta property="og:description" content="Sink from your feet to the center of the planet through rock, liquid iron and a solid core."><meta property="og:url" content="https://watchencyclopedia.org/earth-layers/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "Inside the Earth", "description": "Sink from your feet to the center of the planet through rock, liquid iron and a solid core.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Earth</a></div><h1>Inside the Earth</h1><p class="lede">Nobody has ever been deeper than a few kilometers. Slide a probe 6,371 km down to the center and see what it passes through.</p></div><section class="stage " data-exp="earth-layers"><div class="scr"><canvas role="img" aria-label="Inside the Earth, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>A slice of the Earth from the surface to the center. Temperature and pressure rise all the way down. The figures are best estimates, since nobody can measure them directly.</p><p>We know the layers from earthquake waves, which bend and bounce where the rock changes.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Tap anywhere on the slice to send the probe there.</li><li>Find where solid rock gives way to liquid metal.</li><li>The crust is so thin it barely shows. That is the part we live on.</li></ul></div><div class="panel" style="margin-top:20px"><h2>Numbers</h2><dl class="facts"><dt>Radius</dt><dd>6,371 km</dd><dt>Center</dt><dd>About 5,400 °C</dd><dt>Deepest hole drilled</dt><dd>12.3 km</dd></dl></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/tides/" data-cat="earth" data-t="tides the sea rises and falls twice a day because the moon stretches the oceans. watch the bulges and the earth turning through them. earth"><span class="th" style="background-image:url(/thumb/tides.webp)" role="img" aria-label="Tides"></span><span class="tb"><p class="k">Earth</p><h3>Tides</h3><p>Watch the Moon and Sun pull the oceans into two bulges as the Earth turns beneath them.</p></span></a><a class="tile" href="/pendulum/" data-cat="physics" data-t="the pendulum pull the weight back and let go. then change the string and the planet, and see what changes the beat. physics"><span class="th" style="background-image:url(/thumb/pendulum.webp)" role="img" aria-label="The Pendulum"></span><span class="tb"><p class="k">Physics</p><h3>The Pendulum</h3><p>Swing a weight on a string and find out what sets its rhythm.</p></span></a><a class="tile" href="/waves/" data-cat="physics" data-t="waves and interference drop two stones in a pond. where the ripples cross they add up in some places and cancel in others. physics"><span class="th" style="background-image:url(/thumb/waves.webp)" role="img" aria-label="Waves and Interference"></span><span class="tb"><p class="k">Physics</p><h3>Waves and Interference</h3><p>Two ripples cross and build a pattern of bright bands and calm lines.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/earth-layers.js?v=12306844"></script></body></html> |
engine/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>The Four-Stroke Engine | Watch Encyclopedia</title><meta name="description" content="Suck, squeeze, bang, blow. Watch one cylinder run through all four strokes."><link rel="canonical" href="https://watchencyclopedia.org/engine/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="The Four-Stroke Engine | Watch Encyclopedia"><meta property="og:description" content="Suck, squeeze, bang, blow. Watch one cylinder run through all four strokes."><meta property="og:url" content="https://watchencyclopedia.org/engine/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "The Four-Stroke Engine", "description": "Suck, squeeze, bang, blow. Watch one cylinder run through all four strokes.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Machines</a></div><h1>The Four-Stroke Engine</h1><p class="lede">Most car engines make power the same way: four strokes of a piston, over and over. Slow one down and watch each step.</p></div><section class="stage " data-exp="engine"><div class="scr"><canvas role="img" aria-label="The Four-Stroke Engine, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>One cylinder, cut open. The piston rides up and down, two valves open and shut, and a spark sets off the fuel at just the right moment.</p><p>A real engine idles at about 800 turns a minute and has several cylinders taking turns. The timing here is simplified: real valves open a little early and close a little late.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Set the speed to paused and press Next stroke to step through.</li><li>Watch the valves. Only one is ever open, and during two strokes both are shut.</li><li>Count the crank turns for one full cycle. It is two.</li></ul></div><div class="panel" style="margin-top:20px"><h2>Numbers</h2><dl class="facts"><dt>Strokes in a cycle</dt><dd>4</dd><dt>Crank turns in a cycle</dt><dd>2</dd><dt>Strokes that make power</dt><dd>1</dd></dl></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/phone-teardown/" data-cat="machines" data-t="folding phone teardown what is inside a folding phone? take one apart in your browser, one part at a time, in the order a real repair would go. machines"><span class="th" style="background-image:url(/img/phone-teardown.webp)" role="img" aria-label="Folding Phone Teardown"></span><span class="tb"><p class="k">Machines</p><h3>Folding Phone Teardown</h3><p>Take a folding phone apart in 3D, piece by piece, in the order a repair goes.</p></span></a><a class="tile" href="/gears/" data-cat="machines" data-t="gears two gears, locked tooth to tooth. change how many teeth each one has and see what you gain and what you give up. machines"><span class="th" style="background-image:url(/thumb/gears.webp)" role="img" aria-label="Gears"></span><span class="tb"><p class="k">Machines</p><h3>Gears</h3><p>Change the tooth counts on two gears and trade speed for strength.</p></span></a><a class="tile" href="/lock/" data-cat="machines" data-t="the pin tumbler lock the lock on most front doors is a row of spring-loaded pins. see why only one key shape lets it turn. machines"><span class="th" style="background-image:url(/thumb/lock.webp)" role="img" aria-label="The Pin Tumbler Lock"></span><span class="tb"><p class="k">Machines</p><h3>The Pin Tumbler Lock</h3><p>Lift five pins to the shear line by hand, then see how a key does it at once.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/engine.js?v=12306844"></script></body></html> |
enigma/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>The Enigma Machine | Watch Encyclopedia</title><meta name="description" content="Type a message and trace the current through the wheels of a wartime cipher machine."><link rel="canonical" href="https://watchencyclopedia.org/enigma/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="The Enigma Machine | Watch Encyclopedia"><meta property="og:description" content="Type a message and trace the current through the wheels of a wartime cipher machine."><meta property="og:url" content="https://watchencyclopedia.org/enigma/"><meta property="og:image" content="https://watchencyclopedia.org/img/og.jpg"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "The Enigma Machine", "description": "Type a message and trace the current through the wheels of a wartime cipher machine.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Computing</a></div><h1>The Enigma Machine</h1><p class="lede">The Enigma scrambled German military messages in the Second World War. Type a letter and follow the wire.</p></div><section class="stage " data-exp="enigma"><div class="scr"><canvas role="img" aria-label="The Enigma Machine, interactive"></canvas><button class="fs" type="button" aria-label="Full screen" title="Full screen">⛶</button></div><p class="cap" aria-live="polite"></p><div class="ctl"></div></section><div class="below"><div class="panel"><h2>What you are seeing</h2><p>This is a working model of the three-wheel Enigma I, using the real wiring of wheels I, II and III and reflector B. The plugboard on the front of the real machine is left out.</p><p>A letter can never come out as itself. That small flaw helped the codebreakers in Poland and at Bletchley Park to break it.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Type the same letter five times and look at the output.</li><li>Press Feed the output back in. Your message returns.</li><li>Change one starting wheel by one click and see the whole output change.</li><li>Try to make any letter come out as itself.</li></ul></div><div class="panel" style="margin-top:20px"><h2>Numbers</h2><dl class="facts"><dt>Wheel orders and positions here</dt><dd>17,576 starts</dd><dt>With the real plugboard</dt><dd>About 159 million million million settings</dd></dl></div></div></div><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/life/" data-cat="computing" data-t="the game of life not a game you play. a grid of cells follows one small rule, and things that look alive appear by themselves. computing"><span class="th" style="background-image:url(/thumb/life.webp)" role="img" aria-label="The Game of Life"></span><span class="tb"><p class="k">Computing</p><h3>The Game of Life</h3><p>Draw a few cells, press run, and watch a tiny rule grow into moving machines.</p></span></a><a class="tile" href="/sorting/" data-cat="computing" data-t="how computers sort putting things in order is one of the most common jobs a computer does. some methods are far smarter than others. computing"><span class="th" style="background-image:url(/thumb/sorting.webp)" role="img" aria-label="How Computers Sort"></span><span class="tb"><p class="k">Computing</p><h3>How Computers Sort</h3><p>Race five classic ways to put a shuffled row of bars in order.</p></span></a><a class="tile" href="/binary/" data-cat="computing" data-t="binary numbers computers store everything as ones and zeros. flip eight switches and see how that can mean anything at all. computing"><span class="th" style="background-image:url(/thumb/binary.webp)" role="img" aria-label="Binary Numbers"></span><span class="tb"><p class="k">Computing</p><h3>Binary Numbers</h3><p>Flip eight switches and see how ones and zeros become numbers, letters and shades.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script><script src="/assets/we.js?v=12306844"></script><script src="/exp/enigma.js?v=12306844"></script></body></html> |
everything-launched/index.html added
| 1 | + <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> | |
| 2 | + <title>Everything We've Ever Launched | Watch Encyclopedia</title><meta name="description" content="Every tracked object in Earth orbit since 1957, on a 3D Earth you can scrub through time."><link rel="canonical" href="https://watchencyclopedia.org/everything-launched/"> | |
| 3 | + <meta property="og:type" content="website"><meta property="og:site_name" content="Watch Encyclopedia"><meta property="og:title" content="Everything We've Ever Launched | Watch Encyclopedia"><meta property="og:description" content="Every tracked object in Earth orbit since 1957, on a 3D Earth you can scrub through time."><meta property="og:url" content="https://watchencyclopedia.org/everything-launched/"><meta property="og:image" content="https://watchencyclopedia.org/thumb/everything-launched.webp"><meta name="twitter:card" content="summary_large_image"> | |
| 4 | + <meta name="theme-color" content="#f6f2ea" media="(prefers-color-scheme: light)"><meta name="theme-color" content="#121110" media="(prefers-color-scheme: dark)"> | |
| 5 | + <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%23f6f2ea' stroke='%231d1a16' stroke-width='2.5'/%3E%3Cpath d='M16 8v8l5 3' stroke='%23b07a33' stroke-width='2.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"><link rel="stylesheet" href="/assets/site.css?v=12306844"><script type="application/ld+json">{"@context": "https://schema.org", "@type": "LearningResource", "name": "Everything We've Ever Launched", "description": "Every tracked object in Earth orbit since 1957, on a 3D Earth you can scrub through time.", "learningResourceType": "Interactive simulation", "isAccessibleForFree": true, "publisher": {"@type": "Organization", "name": "Watch Encyclopedia"}}</script></head><body><div class="wrap"> | |
| 6 | + <header><a class="brand" href="/"><svg viewBox="0 0 32 32" aria-hidden="true"><circle cx="16" cy="16" r="13" fill="none" stroke="currentColor" stroke-width="2.4"/><path d="M16 8v8l5 3" stroke="#b07a33" stroke-width="2.6" fill="none" stroke-linecap="round"/></svg>Watch Encyclopedia</a><button class="menu" aria-expanded="false" aria-controls="nav">Menu</button><nav id="nav"><a href="/#explore">Explore</a><a href="/watches/">Watches</a><a href="/glossary/">Glossary</a><a href="/about/">About</a></nav></header> | |
| 7 | + <div class="entry-h"><div class="crumbs"><a href="/">Home</a> / <a href="/#explore">Space</a></div><h1>Everything We've Ever Launched</h1><p class="lede">Since Sputnik in 1957, people have put tens of thousands of objects into orbit. Press play and watch them pile up around the Earth.</p></div><div class="frame"><iframe src="/x/everything-launched/" title="Everything We've Ever Launched" allow="fullscreen; accelerometer; gyroscope" allowfullscreen loading="eager"></iframe></div><div class="frame-links"><a class="btn" href="/x/everything-launched/">Open full screen</a></div><div class="below"><div class="panel"><h2>What you are seeing</h2><p>Every dot is a tracked object: a satellite, a spent rocket stage or a piece of debris. Scrub the timeline to any day since October 1957 and the sky fills in.</p><p>Tap a mission to see a 3D model of the spacecraft with its size, mass and story.</p></div><div><div class="panel"><h2>Try this</h2><ul><li>Press play and watch 1957 turn into today.</li><li>Search for a satellite or a launch by name.</li><li>Open a famous mission, such as Apollo 11 or the Hubble telescope, and spin its model.</li><li>Look for the sudden bursts of dots. Those are breakups and collisions.</li></ul></div><div class="panel" style="margin-top:20px"><h2>Numbers</h2><dl class="facts"><dt>Objects tracked</dt><dd>69,177</dd><dt>Still in orbit</dt><dd>33,884</dd><dt>Ships with 3D models and specs</dt><dd>81</dd></dl></div></div></div><p class="note" style="max-width:760px;margin:-30px 0 50px">Orbit data from Jonathan McDowell's General Catalog of Artificial Space Objects (CC BY 4.0). Positions along each orbit are illustrative. Full sources are listed inside the entry.</p><section class="sec-b"><p class="k">Keep watching</p><h2>More to explore</h2><div class="grid"><a class="tile" href="/solar-system/" data-cat="space" data-t="the solar system eight planets, one star. speed up time and watch each planet keep its own year. space"><span class="th" style="background-image:url(/thumb/solar-system.webp)" role="img" aria-label="The Solar System"></span><span class="tb"><p class="k">Space</p><h3>The Solar System</h3><p>Eight planets circling the Sun at their true speeds. Speed up time and watch.</p></span></a><a class="tile" href="/moon-phases/" data-cat="space" data-t="phases of the moon the moon doesn't change shape. we just see different amounts of its sunlit half. drag it around and see why. space"><span class="th" style="background-image:url(/thumb/moon-phases.webp)" role="img" aria-label="Phases of the Moon"></span><span class="tb"><p class="k">Space</p><h3>Phases of the Moon</h3><p>Drag the Moon around the Earth and watch its shape change in the sky.</p></span></a><a class="tile" href="/seasons/" data-cat="space" data-t="why we have seasons seasons come from the earth's tilt, not from how close it is to the sun. slide through the year and set your own latitude. space"><span class="th" style="background-image:url(/thumb/seasons.webp)" role="img" aria-label="Why We Have Seasons"></span><span class="tb"><p class="k">Space</p><h3>Why We Have Seasons</h3><p>Tilt, not distance. Move through the year and watch the daylight change where you live.</p></span></a></div></section> | |
| 8 | + <footer><span>Watch Encyclopedia</span><span><a href="/about/">About</a> · · <a href="/privacy/">Privacy</a></span></footer> | |
| 9 | + </div><script>(function(){var b=document.querySelector('.menu'),n=document.getElementById('nav');b.addEventListener('click',function(){var o=n.classList.toggle('open');b.setAttribute('aria-expanded',o)})})();</script></body></html> |
exp/binary.js added
| 1 | + WE.mount('binary', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, v = 42, acc = 0, G = {}; | |
| 3 | + var cnt = S.toggle('Count up', false); S.button('Add 1', function () { v = (v + 1) % 256; }); S.button('Double it', function () { v = (v * 2) % 256; }); S.button('Clear', function () { v = 0; cnt.set(false); }); | |
| 4 | + S.pointer({ scroll: true, down: function (x, y) { if (y < G.y0 - 30 || y > G.y0 + G.bh + 10) return; var i = Math.floor((x - G.x0) / G.bw); if (i >= 0 && i < 8) { v ^= 1 << (7 - i); cnt.set(false); S.tone(300 + (7 - i) * 60, .08, 'triangle', .06); } } }); | |
| 5 | + S.loop(function (dt) { | |
| 6 | + if (cnt.v) { acc += dt * 4; while (acc >= 1) { acc--; v = (v + 1) % 256; } } | |
| 7 | + var w = S.W, h = S.H, sm = S.small(), bw = Math.min((w - 24) / 8, 110), bh = Math.min(bw * 1.25, h * .3), x0 = (w - bw * 8) / 2, y0 = h * .2; G.x0 = x0; G.bw = bw; G.y0 = y0; G.bh = bh; | |
| 8 | + S.clear(); var parts = []; | |
| 9 | + for (var i = 0; i < 8; i++) { var bit = (v >> (7 - i)) & 1, pv = 1 << (7 - i), x = x0 + i * bw; if (bit) parts.push(pv); | |
| 10 | + S.txt(pv, x + bw / 2, y0 - 16, bit ? C.acc : C.dim, sm ? 12 : 15, 'center', 700); | |
| 11 | + S.rr(x + 4, y0, bw - 8, bh, 10, bit ? C.acc : '#1b2028', bit ? null : C.dim); S.txt(bit, x + bw / 2, y0 + bh / 2 + 2, bit ? '#1a1206' : C.dim, Math.min(bw * .5, 54), 'center', 700); } | |
| 12 | + var ty = y0 + bh + (sm ? 34 : 48); | |
| 13 | + S.txt(parts.length ? parts.join(' + ') + ' =' : 'Nothing switched on =', w / 2, ty, C.mut, sm ? 12.5 : 15, 'center'); S.txt(v, w / 2, ty + (sm ? 40 : 56), C.ink, sm ? 44 : 64, 'center', 700); | |
| 14 | + var ch = v >= 33 && v <= 126 ? String.fromCharCode(v) : v === 32 ? 'space' : null, by = ty + (sm ? 92 : 126), cw = Math.min(w * .3, 200), items = [['As a letter', ch || 'none'], ['In base 16', (v < 16 ? '0' : '') + v.toString(16).toUpperCase()], ['As a shade', '']]; | |
| 15 | + items.forEach(function (it, k) { var cx = w / 2 + (k - 1) * cw; S.txt(it[0], cx, by, C.mut, 11.5, 'center'); if (k === 2) S.rr(cx - 22, by + 12, 44, 26, 6, 'rgb(' + v + ',' + v + ',' + v + ')', C.dim); else S.txt(it[1], cx, by + 26, k === 0 && !ch ? C.dim : C.ink, sm ? 17 : 22, 'center', 700); }); | |
| 16 | + S.say('<b>Tap the switches.</b> Each one is a bit: off is 0, on is 1. Each place is worth twice the one to its right. Eight bits make a byte, which can hold any number from 0 to 255. Inside a computer, that one byte can stand for a number, a letter or a shade of gray. It all depends on how the program reads it.'); | |
| 17 | + }); | |
| 18 | + }); |
exp/circuit.js added
| 1 | + WE.mount('circuit', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, off = 0; | |
| 3 | + var V = S.slider('Battery', 1, 24, 9, .5, function (v) { return v.toFixed(1) + ' volts'; }), R = S.slider('Resistance', 2, 100, 30, 1, function (v) { return v + ' ohms'; }); | |
| 4 | + S.loop(function (dt) { | |
| 5 | + var I = V.v / R.v, P = V.v * I; off += dt * I * 90; | |
| 6 | + S.clear(); var w = S.W, h = S.H, x0 = w * .18, x1 = w * .82, y0 = h * .2, y1 = h * .72, per = 2 * (x1 - x0) + 2 * (y1 - y0); | |
| 7 | + ctx.strokeStyle = '#b87333'; ctx.lineWidth = 5; ctx.lineJoin = 'round'; ctx.strokeRect(x0, y0, x1 - x0, y1 - y0); | |
| 8 | + function pt(d) { d = ((d % per) + per) % per; if (d < x1 - x0) return [x0 + d, y0]; d -= x1 - x0; if (d < y1 - y0) return [x1, y0 + d]; d -= y1 - y0; if (d < x1 - x0) return [x1 - d, y1]; d -= x1 - x0; return [x0, y1 - d]; } | |
| 9 | + for (var i = 0; i < 46; i++) { var p = pt(i * per / 46 + off); S.dot(p[0], p[1], 3.2, C.blue); } | |
| 10 | + // battery (left side) | |
| 11 | + var by = (y0 + y1) / 2; S.rr(x0 - 20, by - 38, 40, 76, 6, '#22262e', C.mut); S.rr(x0 - 9, by - 46, 18, 9, 2, C.mut); S.txt('+', x0, by - 20, C.red, 18, 'center', 700); S.txt('−', x0, by + 22, C.blue, 20, 'center', 700); | |
| 12 | + // resistor (bottom) | |
| 13 | + var rx = (x0 + x1) / 2; S.rr(rx - 46, y1 - 13, 92, 26, 6, '#3a2f22', C.acc); for (var k = 0; k < Math.round(R.v / 12) + 1; k++) S.ln(rx - 36 + k * 9, y1 - 9, rx - 36 + k * 9, y1 + 9, C.acc, 2); S.txt('Resistor', rx, y1 + 30, C.mut, 12, 'center'); | |
| 14 | + // bulb (top) | |
| 15 | + var glow = Math.min(1, P / 20), g = ctx.createRadialGradient(rx, y0 - 26, 2, rx, y0 - 26, 30 + glow * 80); g.addColorStop(0, 'rgba(255,230,140,' + (.25 + glow * .75) + ')'); g.addColorStop(1, 'rgba(255,230,140,0)'); ctx.fillStyle = g; ctx.fillRect(rx - 120, y0 - 140, 240, 240); | |
| 16 | + S.dot(rx, y0 - 26, 24, 'rgba(255,240,190,' + (.12 + glow * .8) + ')'); S.ring(rx, y0 - 26, 24, C.mut, 1.5); S.rr(rx - 9, y0 - 4, 18, 10, 2, C.mut); | |
| 17 | + var tx = x1 + 14, sm = S.small(); if (sm) { tx = x0 + 30; } | |
| 18 | + S.txt(I.toFixed(2) + ' A', sm ? rx : (x0 + x1) / 2, by - 12, C.ink, sm ? 26 : 38, 'center', 700); S.txt('current', (x0 + x1) / 2, by + 16, C.mut, 13, 'center'); S.txt(P.toFixed(1) + ' watts of power', (x0 + x1) / 2, by + 38, C.yellow, 13.5, 'center', 600); | |
| 19 | + S.say('Current = voltage ÷ resistance: <b>' + V.v.toFixed(1) + ' V ÷ ' + R.v + ' Ω = ' + I.toFixed(2) + ' A</b>. Raise the voltage to push harder. Raise the resistance to hold the flow back. The dots show the flow speeding up and slowing down.'); | |
| 20 | + }); | |
| 21 | + }); |
exp/color-mixing.js added
| 1 | + WE.mount('color-mixing', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, P = [[.4, .4], [.6, .4], [.5, .64]], grab = -1; | |
| 3 | + var mode = S.select('Mix', [['light', 'Light (screens)'], ['paint', 'Ink (printing)']], 'light'); | |
| 4 | + S.pointer({ down: function (x, y) { grab = -1; var bd = 1e9; P.forEach(function (p, i) { var d = Math.hypot(p[0] * S.W - x, p[1] * S.H - y); if (d < bd) { bd = d; grab = i; } }); }, move: function (x, y, d) { if (d && grab >= 0) { P[grab][0] = Math.max(.05, Math.min(.95, x / S.W)); P[grab][1] = Math.max(.08, Math.min(.92, y / S.H)); } }, up: function () { grab = -1; } }); | |
| 5 | + S.loop(function () { | |
| 6 | + var L = mode.v === 'light', w = S.W, h = S.H, r = Math.min(w, h) * .27, cols = L ? ['#ff0000', '#00ff00', '#0000ff'] : ['#00ffff', '#ff00ff', '#ffff00'], names = L ? ['Red', 'Green', 'Blue'] : ['Cyan', 'Magenta', 'Yellow']; | |
| 7 | + S.clear(L ? '#000' : '#fbfaf5'); ctx.globalCompositeOperation = L ? 'lighter' : 'multiply'; | |
| 8 | + P.forEach(function (p, i) { S.dot(p[0] * w, p[1] * h, r, cols[i]); }); ctx.globalCompositeOperation = 'source-over'; | |
| 9 | + P.forEach(function (p, i) { S.txt(names[i], p[0] * w + (p[0] - .5) * r * 1.6, p[1] * h + (p[1] - .48) * r * 2.2, L ? '#fff' : '#111', 13, 'center', 700); }); | |
| 10 | + var px = S.ptr.x > 0 ? S.ptr.x : w / 2, py = S.ptr.x > 0 ? S.ptr.y : h * .47, inn = P.map(function (p) { return Math.hypot(p[0] * w - px, p[1] * h - py) < r; }), key = inn.map(Number).join(''); | |
| 11 | + var NM = L ? { '000': 'black: no light at all', '100': 'red', '010': 'green', '001': 'blue', '110': 'yellow (red + green)', '101': 'magenta (red + blue)', '011': 'cyan (green + blue)', '111': 'white: all three together' } : { '000': 'white paper', '100': 'cyan', '010': 'magenta', '001': 'yellow', '110': 'blue (cyan + magenta)', '101': 'green (cyan + yellow)', '011': 'red (magenta + yellow)', '111': 'black: all light soaked up' }; | |
| 12 | + S.ring(px, py, 9, L ? '#fff' : '#111', 2); | |
| 13 | + S.say((L ? 'Screens start dark and <b>add</b> light. ' : 'Ink starts with white paper and <b>takes light away</b>. ') + 'Under the ring: <b>' + NM[key] + '</b>. Drag the circles apart and together.'); | |
| 14 | + }); | |
| 15 | + }); |
exp/complications.js added
| 1 | + WE.mount('complications', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, T = Date.now(), ch = 0, running = false, SYN = 29.530588853, REF = Date.UTC(2000, 0, 6, 18, 14); | |
| 3 | + var date = S.toggle('Date', true), day = S.toggle('Day', false), moon = S.toggle('Moon phase', true), gmt = S.toggle('Second time zone', false), chr = S.toggle('Stopwatch', false); | |
| 4 | + var bS = S.button('Start', function () { if (!chr.v) chr.set(true); running = !running; bS.textContent = running ? 'Stop' : 'Start'; }); | |
| 5 | + S.button('Reset', function () { ch = 0; running = false; bS.textContent = 'Start'; }); | |
| 6 | + var spd = S.slider('Time speed', 0, 100, 0, 1, function (v) { var m = Math.pow(10, v / 20); return m < 1.5 ? 'Real time' : m < 3600 ? Math.round(m / 60) < 1 ? Math.round(m) + ' seconds a second' : Math.round(m / 60) + ' minutes a second' : m < 86400 ? (m / 3600).toFixed(1) + ' hours a second' : (m / 86400).toFixed(1) + ' days a second'; }); | |
| 7 | + function hand(x, y, a, len, w, col, tail) { S.ln(x - (tail || 0) * Math.sin(a), y + (tail || 0) * Math.cos(a), x + len * Math.sin(a), y - len * Math.cos(a), col, w); } | |
| 8 | + function drawMoon(x, y, r, p) { | |
| 9 | + S.dot(x, y, r, '#1a2233'); var k = Math.cos(p * S.TAU), s = p < .5 ? 1 : -1; ctx.beginPath(); ctx.arc(x, y, r, -Math.PI / 2, Math.PI / 2, s < 0); ctx.ellipse(x, y, Math.abs(k) * r, r, 0, Math.PI / 2, -Math.PI / 2, (k > 0) === (s > 0)); ctx.fillStyle = '#f0e2b4'; ctx.fill(); S.ring(x, y, r, C.dim, 1); | |
| 10 | + } | |
| 11 | + S.loop(function (dt) { | |
| 12 | + T += dt * 1000 * Math.pow(10, spd.v / 20); if (running) ch += dt; | |
| 13 | + var d = new Date(T), w = S.W, h = S.H, x = w / 2, y = h / 2, r = Math.min(w, h) * .44; | |
| 14 | + S.clear(); ctx.lineCap = 'round'; | |
| 15 | + S.dot(x, y, r, '#161a22'); S.ring(x, y, r, '#8d8676', 5); | |
| 16 | + if (gmt.v) for (var g = 0; g < 24; g += 2) { var ga = g * S.TAU / 24; S.txt(String(g || 24), x + r * .93 * Math.sin(ga), y - r * .93 * Math.cos(ga), C.red, r * .055, 'center', 650); } | |
| 17 | + for (var i = 0; i < 60; i++) { var a = i * S.TAU / 60, b = i % 5 === 0, o = gmt.v ? .86 : .93; S.ln(x + r * (b ? o - .1 : o - .04) * Math.sin(a), y - r * (b ? o - .1 : o - .04) * Math.cos(a), x + r * o * Math.sin(a), y - r * o * Math.cos(a), b ? C.ink : C.dim, b ? 3 : 1); } | |
| 18 | + var fs = r * .085; | |
| 19 | + if (day.v) { S.rr(x - r * .16, y - r * .52, r * .32, r * .13, 4, '#f1ece2'); S.txt(['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'][d.getDay()], x, y - r * .455, '#14161a', fs, 'center', 700); } | |
| 20 | + if (date.v) { S.rr(x + r * .44, y - r * .075, r * .2, r * .15, 4, '#f1ece2'); S.txt(String(d.getDate()), x + r * .54, y, '#14161a', fs, 'center', 700); } | |
| 21 | + var age = (((T - REF) / 864e5) % SYN + SYN) % SYN; | |
| 22 | + if (moon.v) drawMoon(x, y + r * .46, r * .15, age / SYN); | |
| 23 | + if (chr.v) { var sx = x - r * .46, sr = r * .17; S.ring(sx, y, sr, C.dim, 1); for (var m = 0; m < 30; m += 5) { var ma = m * S.TAU / 30; S.ln(sx + sr * .8 * Math.sin(ma), y - sr * .8 * Math.cos(ma), sx + sr * Math.sin(ma), y - sr * Math.cos(ma), C.mut, 1); } hand(sx, y, (ch / 60 % 30) * S.TAU / 30, sr * .8, 2, C.blue); S.txt('30 min', sx, y + sr + 10, C.mut, r * .05, 'center'); } | |
| 24 | + var sec = d.getSeconds() + d.getMilliseconds() / 1000, min = d.getMinutes() + sec / 60, hr = d.getHours() % 12 + min / 60; | |
| 25 | + if (gmt.v) { var ua = (d.getUTCHours() + d.getUTCMinutes() / 60) * S.TAU / 24; hand(x, y, ua, r * .8, 2.5, C.red); var tx = x + r * .8 * Math.sin(ua), ty = y - r * .8 * Math.cos(ua); S.dot(tx, ty, 5, C.red); } | |
| 26 | + hand(x, y, hr * S.TAU / 12, r * .5, 8, C.ink, r * .08); hand(x, y, min * S.TAU / 60, r * .76, 5, C.ink, r * .08); | |
| 27 | + if (chr.v) hand(x, y, (ch % 60) * S.TAU / 60, r * .84, 2, C.blue, r * .16); else hand(x, y, Math.floor(sec * 8) / 8 * S.TAU / 60, r * .84, 1.6, C.acc, r * .16); | |
| 28 | + S.dot(x, y, 6, C.ink); S.dot(x, y, 2.5, C.acc); | |
| 29 | + var names = ['new moon', 'waxing crescent', 'first quarter', 'waxing gibbous', 'full moon', 'waning gibbous', 'last quarter', 'waning crescent']; | |
| 30 | + S.say(d.toLocaleDateString(undefined, { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric' }) + '. ' + (moon.v ? 'Moon: <b>' + names[Math.round(age / SYN * 8) % 8] + '</b>, ' + age.toFixed(1) + ' days old. ' : '') + (gmt.v ? 'The red hand circles once a day and shows <b>UTC</b> on the 24 hour ring. ' : '') + (chr.v ? 'Stopwatch: <b>' + Math.floor(ch / 60) + ':' + ('0' + (ch % 60).toFixed(1)).slice(-4) + '</b>.' : '')); | |
| 31 | + }); | |
| 32 | + }); |
exp/dna.js added
| 1 | + WE.mount('dna', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, NORMAL = 'ATGGTGCATCTGACTCCTGAGGAGAAGTCT', seq = NORMAL.split(''), G = { cells: [] }, last = -1; | |
| 3 | + var T = 'FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG', NM = { F: 'Phe', L: 'Leu', S: 'Ser', Y: 'Tyr', C: 'Cys', W: 'Trp', P: 'Pro', H: 'His', Q: 'Gln', R: 'Arg', I: 'Ile', M: 'Met', T: 'Thr', N: 'Asn', K: 'Lys', V: 'Val', A: 'Ala', D: 'Asp', E: 'Glu', G: 'Gly', '*': 'Stop' }; | |
| 4 | + var COL = { A: C.green, T: C.red, G: C.yellow, C: C.blue }, PAIR = { A: 'T', T: 'A', G: 'C', C: 'G' }; | |
| 5 | + function aa(i) { var c = seq.slice(i * 3, i * 3 + 3), ix = function (b) { return 'TCAG'.indexOf(b); }; return T[16 * ix(c[0]) + 4 * ix(c[1]) + ix(c[2])]; } | |
| 6 | + S.button('Make the sickle cell change', function () { seq = NORMAL.split(''); seq[19] = 'T'; last = 19; }); S.button('Put it back', function () { seq = NORMAL.split(''); last = -1; }); | |
| 7 | + S.pointer({ scroll: true, down: function (x, y) { G.cells.forEach(function (c, i) { if (x >= c[0] && x < c[0] + c[2] && y >= c[1] - 6 && y < c[1] + c[3] + 6) { seq[i] = 'ACGT'[('ACGT'.indexOf(seq[i]) + 1) % 4]; last = i; } }); } }); | |
| 8 | + S.loop(function (dt, t) { | |
| 9 | + var w = S.W, h = S.H, sm = S.small(), n = 30, hx0 = w * .04, hx1 = w * .96, hy = sm ? h * .16 : h * .24, amp = sm ? h * .08 : h * .13; | |
| 10 | + S.clear(); | |
| 11 | + // helix | |
| 12 | + var items = []; for (var i = 0; i < n; i++) { var a = i * .62 + t * .7, x = hx0 + (hx1 - hx0) * (i + .5) / n, y1 = hy + Math.sin(a) * amp, y2 = hy - Math.sin(a) * amp, z = Math.cos(a); items.push([x, y1, y2, z, i]); } | |
| 13 | + [0, 1].forEach(function (s) { ctx.beginPath(); for (var k = 0; k <= 240; k++) { var u = k / 240 * n - .5, a = u * .62 + t * .7; ctx.lineTo(hx0 + (hx1 - hx0) * (u + .5) / n, hy + (s ? -1 : 1) * Math.sin(a) * amp); } ctx.strokeStyle = s ? '#6a7080' : '#8a90a0'; ctx.lineWidth = sm ? 3 : 5; ctx.stroke(); }); | |
| 14 | + items.forEach(function (q) { var b = seq[q[4]], mid = (q[1] + q[2]) / 2, lw = sm ? 3 : 6; ctx.globalAlpha = .55 + .45 * Math.abs(q[3]); S.ln(q[0], q[1], q[0], mid, COL[b], lw); S.ln(q[0], mid, q[0], q[2], COL[PAIR[b]], lw); ctx.globalAlpha = 1; if (q[4] === last) S.ring(q[0], hy, amp + 8, C.ink, 1.5); }); | |
| 15 | + // letters and codons | |
| 16 | + var per = sm ? 15 : 30, rowsN = n / per, cw = (w - (sm ? 16 : 40)) / per, x0 = sm ? 8 : 20, ry = sm ? h * .34 : h * .5, rh = sm ? h * .3 : h * .42, stop = false; G.cells = []; | |
| 17 | + for (var c = 0; c < 10; c++) { var r = Math.floor(c * 3 / per), cx = x0 + ((c * 3) % per) * cw, cy = ry + r * rh, A = aa(c), norm = (function () { var s = NORMAL.slice(c * 3, c * 3 + 3), ix = function (b) { return 'TCAG'.indexOf(b); }; return T[16 * ix(s[0]) + 4 * ix(s[1]) + ix(s[2])]; })(), changed = A !== norm; | |
| 18 | + S.rr(cx + 2, cy, cw * 3 - 4, sm ? 84 : 118, 10, stop ? '#12151a' : '#181d25', changed ? C.red : C.grid); | |
| 19 | + for (var j = 0; j < 3; j++) { var idx = c * 3 + j, b = seq[idx], bx = cx + j * cw, bh = sm ? 26 : 34; G.cells[idx] = [bx, cy + 8, cw, bh]; S.rr(bx + 4, cy + 8, cw - 8, bh, 6, COL[b]); if (b !== NORMAL[idx]) S.rr(bx + 4, cy + 8, cw - 8, bh, 6, null, C.ink); S.txt(b, bx + cw / 2, cy + 8 + bh / 2 + 1, '#14110a', sm ? 14 : 17, 'center', 700); } | |
| 20 | + S.txt(NM[A], cx + cw * 1.5, cy + (sm ? 54 : 70), A === '*' ? C.red : stop ? C.dim : changed ? C.red : C.ink, sm ? 14 : 19, 'center', 700); S.txt(stop ? 'never made' : changed ? 'was ' + NM[norm] : c === 0 ? 'start' : A === '*' ? 'chain ends' : '', cx + cw * 1.5, cy + (sm ? 71 : 94), C.mut, sm ? 9.5 : 11.5, 'center'); | |
| 21 | + if (A === '*') stop = true; } | |
| 22 | + if (!sm) S.txt('Each rung is a pair of bases. A always pairs with T, and G always pairs with C.', hx0, h * .44, C.mut, 12.5); | |
| 23 | + var cur = seq.join(''), nd = 0; for (i = 0; i < n; i++) if (seq[i] !== NORMAL[i]) nd++; | |
| 24 | + var sick = nd === 1 && seq[19] === 'T', same = true; for (c = 0; c < 10; c++) { var s2 = NORMAL.slice(c * 3, c * 3 + 3), ix2 = function (b) { return 'TCAG'.indexOf(b); }; if (aa(c) !== T[16 * ix2(s2[0]) + 4 * ix2(s2[1]) + ix2(s2[2])]) same = false; } | |
| 25 | + S.say(nd === 0 ? 'These are the first 30 letters of the human gene for beta-globin, part of the protein that carries oxygen in blood. The cell reads the letters <b>three at a time</b>. Each group of three names one building block of the protein. <b>Tap any letter to change it.</b>' : sick ? '<b>One letter changed: A became T.</b> The seventh block switches from Glu to Val. That single swap makes the protein clump when oxygen is low and bends red blood cells into a sickle shape. It is the cause of sickle cell disease.' : stop ? 'Your change made a <b>Stop</b> signal. The cell quits building here, so the rest of the protein is never made. Changes like this usually break the protein.' : same ? 'You changed a letter, but every block is the same as before. Most blocks can be spelled more than one way, so some changes are <b>silent</b>.' : 'Your change swapped a building block, marked in red. Some swaps do nothing much. Others change how the whole protein folds and works.'); | |
| 26 | + }); | |
| 27 | + }); |
exp/doppler.js added
| 1 | + WE.mount('doppler', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, x = 0, rings = [], acc = 0, Cs = 120; | |
| 3 | + var v = S.slider('Speed of the source', 0, 1.6, .5, .05, function (m) { return m === 0 ? 'Standing still' : (m * 100).toFixed(0) + '% of the speed of sound'; }); | |
| 4 | + S.button('Hear it pass', function () { var m = Math.min(.9, v.v); try { var o = S.tone(440 / (1 - m), 2.2, 'sawtooth', .06); o.frequency.setValueAtTime(440 / (1 - m), o.context.currentTime); o.frequency.exponentialRampToValueAtTime(440 / (1 + m), o.context.currentTime + 1.3); } catch (e) { } }); | |
| 5 | + S.loop(function (dt) { | |
| 6 | + var w = S.W, h = S.H, m = v.v; x += m * Cs * dt; if (x > w + 80) { x = -80; rings = []; } | |
| 7 | + acc += dt; while (acc > .22) { acc -= .22; rings.push({ x: x, r: 0 }); } | |
| 8 | + rings.forEach(function (r) { r.r += Cs * dt; }); rings = rings.filter(function (r) { return r.r < w; }); | |
| 9 | + S.clear(); rings.forEach(function (r) { S.ring(r.x, h / 2, r.r, 'rgba(111,177,230,' + Math.max(.08, .7 - r.r / w) + ')', 1.5); }); | |
| 10 | + if (m > 1) { var a = Math.asin(1 / m), L = w; S.ln(x, h / 2, x - L * Math.cos(a), h / 2 - L * Math.sin(a), C.red, 2); S.ln(x, h / 2, x - L * Math.cos(a), h / 2 + L * Math.sin(a), C.red, 2); } | |
| 11 | + S.dot(x, h / 2, 9, C.acc); S.arrow(x + 12, h / 2, x + 22 + m * 30, h / 2, C.acc, 2); | |
| 12 | + var f = 440, ahead = m < 1 ? f / (1 - m) : null, behind = f / (1 + m); | |
| 13 | + S.txt('Behind: ' + behind.toFixed(0) + ' Hz, lower', 14, 22, C.blue, 13.5, 'left', 600); S.txt(ahead ? 'Ahead: ' + ahead.toFixed(0) + ' Hz, higher' : 'Ahead: silence, then a boom', w - 60, 22, C.red, 13.5, 'right', 600); | |
| 14 | + S.say(m === 0 ? 'A still source sends out even rings: a steady <b>440 Hz</b> note in every direction.' : m < 1 ? 'The source chases its own waves. They bunch up in front, so the pitch is <b>higher</b>, and stretch out behind, so it is <b>lower</b>. That is the drop you hear as a siren passes.' : 'Faster than sound. The waves cannot get ahead, so they pile into a cone: a <b>shock wave</b>, heard on the ground as a sonic boom.'); | |
| 15 | + }); | |
| 16 | + }); |
exp/double-pendulum.js added
| 1 | + WE.mount('double-pendulum', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, P = [], g = 9.81, grab = false; | |
| 3 | + var diff = S.select('Second pendulum starts off by', [['0.001', 'a thousandth of a degree'], ['0.1', 'a tenth of a degree'], ['2', '2 degrees']], '0.1', function () { reset(); }); | |
| 4 | + S.button('Start again', function () { reset(); }); | |
| 5 | + function reset(a1, a2) { a1 = a1 === undefined ? 2.2 : a1; a2 = a2 === undefined ? 2.6 : a2; var d = +diff.v * Math.PI / 180; P = [{ a: a1, b: a2, wa: 0, wb: 0, tr: [], c: C.acc }, { a: a1 + d, b: a2, wa: 0, wb: 0, tr: [], c: C.blue }]; } reset(); | |
| 6 | + function acc(p) { var d = p.a - p.b, den = 3 - Math.cos(2 * d); return [(-3 * g * Math.sin(p.a) - g * Math.sin(p.a - 2 * p.b) - 2 * Math.sin(d) * (p.wb * p.wb + p.wa * p.wa * Math.cos(d))) / den, (2 * Math.sin(d) * (2 * p.wa * p.wa + 2 * g * Math.cos(p.a) + p.wb * p.wb * Math.cos(d))) / den]; } | |
| 7 | + S.pointer({ down: function (x, y) { grab = true; set(x, y); }, move: function (x, y, d) { if (d && grab) set(x, y); }, up: function () { grab = false; } }); | |
| 8 | + function set(x, y) { var a = Math.atan2(x - S.W / 2, y - S.H * .4); reset(a, a + .4); } | |
| 9 | + S.loop(function (dt, t) { | |
| 10 | + var w = S.W, h = S.H, L = Math.min(w, h) * .21, ox = w / 2, oy = h * .4; | |
| 11 | + if (!grab) P.forEach(function (p) { for (var i = 0; i < 24; i++) { var st = dt * 1.6 / 24, k = acc(p); p.wa += k[0] * st / 1; p.wb += k[1] * st / 1; p.a += p.wa * st; p.b += p.wb * st; } }); | |
| 12 | + S.clear(); | |
| 13 | + P.forEach(function (p) { var x1 = ox + L * Math.sin(p.a), y1 = oy + L * Math.cos(p.a), x2 = x1 + L * Math.sin(p.b), y2 = y1 + L * Math.cos(p.b); if (!grab) p.tr.push([x2, y2]); if (p.tr.length > 420) p.tr.shift(); | |
| 14 | + for (var i = 1; i < p.tr.length; i++) { ctx.globalAlpha = i / p.tr.length * .8; S.ln(p.tr[i - 1][0], p.tr[i - 1][1], p.tr[i][0], p.tr[i][1], p.c, 1.5); } ctx.globalAlpha = 1; | |
| 15 | + S.ln(ox, oy, x1, y1, C.ink, 2); S.ln(x1, y1, x2, y2, C.ink, 2); S.dot(x1, y1, 7, p.c); S.dot(x2, y2, 9, p.c); }); | |
| 16 | + S.dot(ox, oy, 5, C.mut); | |
| 17 | + var sep = Math.abs(P[0].b - P[1].b) + Math.abs(P[0].a - P[1].a); | |
| 18 | + S.say((sep < .05 ? 'Two pendulums, gold and blue, start almost exactly together. Watch closely.' : sep < 1.5 ? 'They are <b>starting to drift apart</b>.' : 'Now they are doing <b>completely different things</b>.') + ' Nothing here is random. The rules are exact, yet a tiny difference at the start grows until the future cannot be predicted. This is chaos. Drag to set a new start.'); | |
| 19 | + }); | |
| 20 | + }); |
exp/earth-layers.js added
| 1 | + WE.mount('earth-layers', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, RE = 6371; | |
| 3 | + var L = [[0, 35, 'Crust', '#8a6f52', 'Solid rock. The thin skin we live on, about 35 km thick under the continents and only 7 km under the oceans.'], [35, 660, 'Upper mantle', '#c2552f', 'Hot rock that flows very slowly, like thick tar over millions of years. It carries the plates of the crust along.'], [660, 2891, 'Lower mantle', '#d9732e', 'Solid but slowly creeping rock under huge pressure. More than half of the whole planet by volume.'], [2891, 5150, 'Outer core', '#f0a63a', 'Liquid iron and nickel. Its swirling makes the Earth’s magnetic field.'], [5150, 6371, 'Inner core', '#ffe08a', 'A solid ball of iron and nickel, about as hot as the surface of the Sun but squeezed solid by pressure.']]; | |
| 4 | + var TP = [[0, 15, 0], [35, 600, 1], [660, 1600, 24], [2891, 3700, 136], [5150, 5000, 330], [6371, 5400, 364]]; | |
| 5 | + function at(d, k) { for (var i = 1; i < TP.length; i++) if (d <= TP[i][0]) { var a = TP[i - 1], b = TP[i], f = (d - a[0]) / (b[0] - a[0]); return a[k] + (b[k] - a[k]) * f; } return TP[5][k]; } | |
| 6 | + var dep = S.slider('Depth', 0, 6371, 1200, 1, function (v) { return v.toLocaleString() + ' km down'; }), dive = S.toggle('Sink to the center', false); | |
| 7 | + S.pointer({ scroll: true, down: pick, move: function (x, y, d) { if (d) pick(x, y); } }); | |
| 8 | + function geo() { var sm = S.small(), w = S.W, h = S.H; return sm ? { cx: w / 2, cy: h * .98, R: Math.min(w * .9, h * .62) } : { cx: w * .36, cy: h * 1.02, R: Math.min(w * .5, h * .9) }; } | |
| 9 | + function pick(x, y) { var g = geo(), r = Math.hypot(x - g.cx, y - g.cy); if (r <= g.R + 10) dep.set(Math.round(Math.max(0, Math.min(RE, (1 - r / g.R) * RE)))); } | |
| 10 | + S.loop(function (dt, t) { | |
| 11 | + if (dive.v) { var nv = dep.v + dt * 500; if (nv >= RE) { nv = RE; dive.set(false); } dep.set(Math.round(nv)); } | |
| 12 | + S.clear(); var g = geo(), d = dep.v, cur = L[0]; L.forEach(function (l) { if (d >= l[0]) cur = l; }); | |
| 13 | + L.forEach(function (l) { var r = g.R * (1 - l[0] / RE); ctx.beginPath(); ctx.moveTo(g.cx, g.cy); ctx.arc(g.cx, g.cy, Math.max(r, l[2] === 'Crust' ? r : 0), Math.PI * 1.12, Math.PI * 1.88); ctx.closePath(); ctx.fillStyle = l[3]; ctx.globalAlpha = l === cur ? 1 : .55; ctx.fill(); ctx.globalAlpha = 1; }); | |
| 14 | + S.ln(g.cx - 1, g.cy, g.cx + g.R * Math.cos(Math.PI * 1.12), g.cy + g.R * Math.sin(Math.PI * 1.12), C.bg, 2); | |
| 15 | + var pr = g.R * (1 - d / RE), py = g.cy - pr; ctx.setLineDash([3, 4]); S.ln(g.cx, g.cy - g.R, g.cx, py, C.ink, 1.5); ctx.setLineDash([]); S.dot(g.cx, py, 6 + Math.sin(t * 4), '#fff'); S.ring(g.cx, py, 11, C.ink, 1.5); | |
| 16 | + ctx.beginPath(); ctx.arc(g.cx, g.cy, pr, Math.PI * 1.12, Math.PI * 1.88); ctx.strokeStyle = 'rgba(255,255,255,.6)'; ctx.lineWidth = 1; ctx.stroke(); | |
| 17 | + var sm = S.small(), tx = sm ? 14 : S.W * .66, ty = sm ? 24 : S.H * .2; | |
| 18 | + S.txt(cur[2], tx, ty, cur[3], sm ? 22 : 30, 'left', 700); S.txt(d.toLocaleString() + ' km below your feet', tx, ty + (sm ? 26 : 36), C.ink, sm ? 13 : 15); | |
| 19 | + S.txt('About ' + (Math.round(at(d, 1) / 10) * 10).toLocaleString() + ' °C', tx, ty + (sm ? 50 : 72), C.red, sm ? 15 : 19, 'left', 650); | |
| 20 | + var gp = at(d, 2); S.txt(gp < 1 ? 'Pressure: up to ' + Math.max(1, Math.round(gp * 10000)).toLocaleString() + ' times the air' : 'Pressure: about ' + (Math.round(gp * 9869 / 1000) * 1000).toLocaleString() + ' times the air', tx, ty + (sm ? 72 : 102), C.blue, sm ? 12.5 : 15); | |
| 21 | + if (!sm) S.txt('Deepest hole ever drilled: 12 km', tx, ty + 140, C.mut, 13); | |
| 22 | + S.say('<b>' + cur[2] + '</b> ' + cur[4]); | |
| 23 | + }); | |
| 24 | + }); |
exp/engine.js added
| 1 | + WE.mount('engine', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, th = 0, PI = Math.PI; | |
| 3 | + var NAMES = ['Intake', 'Compression', 'Power', 'Exhaust'], COL = [C.blue, C.violet, C.red, C.mut]; | |
| 4 | + var TXT = ['<b>Intake.</b> The piston slides down and pulls a mix of air and fuel in through the open valve on the left.', | |
| 5 | + '<b>Compression.</b> Both valves are shut. The piston comes back up and squeezes the mix into a small space, which makes it burn harder.', | |
| 6 | + '<b>Power.</b> The spark plug fires. The burning gas swells and shoves the piston down. This is the only stroke that makes power.', | |
| 7 | + '<b>Exhaust.</b> The valve on the right opens and the rising piston pushes the burned gas out. Then it all starts again.']; | |
| 8 | + var sp = S.slider('Speed', 0, 120, 30, 1, function (v) { return v === 0 ? 'paused' : v + ' turns a minute'; }); | |
| 9 | + S.button('Next stroke', function () { th = ((Math.floor(th / PI + 1e-6) + 1) * PI) % (4 * PI) + .02; sp.set(0); }); | |
| 10 | + S.loop(function (dt) { | |
| 11 | + th = (th + dt * sp.v / 60 * S.TAU) % (4 * PI); | |
| 12 | + var w = S.W, h = S.H, sm = S.small(), k = Math.floor(th / PI) % 4, f = th / PI - Math.floor(th / PI); | |
| 13 | + var cx = sm ? w * .5 : w * .34, cy = h * .8, r = h * .1, l = h * .3, ph = h * .1, bw = Math.min(w * .32, h * .36), head = cy - r - l - ph / 2 - h * .035; | |
| 14 | + var pin = cy - (r * Math.cos(th) + Math.sqrt(l * l - r * r * Math.sin(th) * Math.sin(th))), top = pin - ph / 2; | |
| 15 | + S.clear(); | |
| 16 | + // gas | |
| 17 | + var a = k === 0 ? .25 : k === 1 ? .25 + f * .45 : k === 2 ? .85 - f * .5 : .3, gc = k === 0 ? '111,177,230' : k === 1 ? '150,150,240' : k === 2 ? '240,140,70' : '150,146,135'; | |
| 18 | + ctx.fillStyle = 'rgba(' + gc + ',' + a + ')'; ctx.fillRect(cx - bw / 2, head, bw, top - head); | |
| 19 | + // cylinder walls and head | |
| 20 | + S.ln(cx - bw / 2, head, cx - bw / 2, cy - r * .2, C.ink, 3); S.ln(cx + bw / 2, head, cx + bw / 2, cy - r * .2, C.ink, 3); | |
| 21 | + var vw = bw * .28, io = k === 0 ? Math.sin(f * PI) : 0, eo = k === 3 ? Math.sin(f * PI) : 0, pw = h * .1; | |
| 22 | + S.ln(cx - bw / 2, head, cx - bw / 2 + bw * .08, head, C.ink, 3); S.ln(cx - bw / 2 + bw * .08 + vw, head, cx + bw / 2 - bw * .08 - vw, head, C.ink, 3); S.ln(cx + bw / 2 - bw * .08, head, cx + bw / 2, head, C.ink, 3); | |
| 23 | + // ports | |
| 24 | + [[-1, io, C.blue, 'Air and fuel in'], [1, eo, C.mut, 'Burned gas out']].forEach(function (p) { | |
| 25 | + var vx = cx + p[0] * (bw / 2 - bw * .08 - vw / 2), d = p[1] * h * .035; | |
| 26 | + S.ln(vx - vw / 2, head, vx - vw / 2 + p[0] * 0, head - pw, C.dim, 2); S.ln(vx + vw / 2, head, vx + vw / 2, head - pw, C.dim, 2); | |
| 27 | + S.ln(vx, head - pw - h * .03 + d, vx, head + d, p[1] > .02 ? p[2] : C.ink, 3); S.ln(vx - vw / 2 + 1, head + d + 2, vx + vw / 2 - 1, head + d + 2, p[1] > .02 ? p[2] : C.ink, 5); | |
| 28 | + if (p[1] > .05) { if (p[0] < 0) S.arrow(vx - vw * .28, head - pw - 4, vx - vw * .28, head - 6, p[2], 2); else S.arrow(vx + vw * .28, head - 6, vx + vw * .28, head - pw - 4, p[2], 2); } | |
| 29 | + S.txt(p[3], vx + p[0] * (vw / 2 + 8), head - pw * .6, p[1] > .02 ? p[2] : C.dim, sm ? 10.5 : 12, p[0] < 0 ? 'right' : 'left'); | |
| 30 | + }); | |
| 31 | + // spark plug | |
| 32 | + S.ln(cx, head - pw - h * .03, cx, head + 5, C.ink, 4); S.txt('Spark plug', cx, head - pw - h * .03 - 12, k === 2 && f < .25 ? C.yellow : C.dim, sm ? 10.5 : 12, 'center'); | |
| 33 | + if (k === 2 && f < .22) { for (var i = 0; i < 9; i++) { var an = i / 9 * S.TAU + th * 5, rr = (1 - f / .22) * h * .06 + 6; S.ln(cx, head + 8, cx + Math.cos(an) * rr, head + 8 + Math.abs(Math.sin(an)) * rr, C.yellow, 2); } } | |
| 34 | + // piston, rod, crank | |
| 35 | + S.rr(cx - bw / 2 + 3, top, bw - 6, ph, 5, '#5b606b', C.ink); S.ln(cx - bw / 2 + 5, top + ph * .22, cx + bw / 2 - 5, top + ph * .22, C.bg, 2); S.ln(cx - bw / 2 + 5, top + ph * .4, cx + bw / 2 - 5, top + ph * .4, C.bg, 2); | |
| 36 | + var kx = cx + r * Math.sin(th), ky = cy - r * Math.cos(th); | |
| 37 | + S.ring(cx, cy, r, C.dim, 2); S.ln(cx, pin, kx, ky, C.acc, 7); S.ln(cx, cy, kx, ky, C.ink, 6); S.dot(cx, pin, 6, C.ink); S.dot(kx, ky, 7, C.ink); S.dot(cx, cy, 9, C.acc); | |
| 38 | + if (k === 2) S.arrow(cx + bw / 2 + 16, top - 4, cx + bw / 2 + 16, top + ph + 6, C.red, 3); | |
| 39 | + // readout | |
| 40 | + var tx = sm ? 12 : w * .6, ty = sm ? 16 : h * .2; | |
| 41 | + if (sm) { S.txt((k + 1) + '. ' + NAMES[k], tx, ty, COL[k] === C.mut ? C.ink : COL[k], 17, 'left', 700); } | |
| 42 | + else { | |
| 43 | + S.txt('Stroke ' + (k + 1) + ' of 4', tx, ty, C.mut, 13); S.txt(NAMES[k], tx, ty + 34, COL[k] === C.mut ? C.ink : COL[k], 40, 'left', 700); | |
| 44 | + for (var j = 0; j < 4; j++) { var yy = ty + 90 + j * 34; S.rr(tx, yy - 12, w * .3, 26, 13, j === k ? 'rgba(255,255,255,.08)' : null, j === k ? C.dim : null); S.dot(tx + 14, yy + 1, 5, j === k ? (COL[j] === C.mut ? C.ink : COL[j]) : C.dim); S.txt(NAMES[j], tx + 28, yy + 1, j === k ? C.ink : C.mut, 13.5, 'left', j === k ? 700 : 500); if (j === k) S.rr(tx + w * .14, yy - 2, (w * .14) * f, 6, 3, C.acc); } | |
| 45 | + S.txt('The crank turns twice for every one power stroke.', tx, ty + 240, C.mut, 12.5); | |
| 46 | + } | |
| 47 | + S.say(TXT[k]); | |
| 48 | + }); | |
| 49 | + }); |
exp/enigma.js added
| 1 | + WE.mount('enigma', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ROT = [['EKMFLGDQVZNTOWYHXUSPAIBRCJ', 'Q'], ['AJDKSIRUXBLHWTMCQGZNPYFVOE', 'E'], ['BDFHJLCPRTXVZNYEIWGAKMUSQO', 'V']], REF = 'YRUHQSLDPXNGOKMIEBFZCWVJAT'; | |
| 3 | + var F = ROT.map(function (r) { return r[0].split('').map(function (c) { return A.indexOf(c); }); }), B = F.map(function (f) { var b = []; f.forEach(function (v, i) { b[v] = i; }); return b; }), RF = REF.split('').map(function (c) { return A.indexOf(c); }), NT = ROT.map(function (r) { return A.indexOf(r[1]); }); | |
| 4 | + function L(v) { return A[v]; } | |
| 5 | + var s1 = S.slider('Left wheel', 0, 25, 0, 1, L), s2 = S.slider('Middle wheel', 0, 25, 0, 1, L), s3 = S.slider('Right wheel', 0, 25, 0, 1, L); | |
| 6 | + var inp = S.input('Type a message', 'HELLO', null, 40); | |
| 7 | + S.button('Feed the output back in', function () { var o = run(inp.v).out; inp.el.value = o; inp.v = o; }); | |
| 8 | + function run(msg) { var p = [s1.v, s2.v, s3.v], out = '', last = null; msg.toUpperCase().split('').forEach(function (ch) { var c = A.indexOf(ch); if (c < 0) { if (ch === ' ') out += ' '; return; } | |
| 9 | + if (p[1] === NT[1]) { p[0] = (p[0] + 1) % 26; p[1] = (p[1] + 1) % 26; } else if (p[2] === NT[2]) p[1] = (p[1] + 1) % 26; p[2] = (p[2] + 1) % 26; | |
| 10 | + var tr = [c], x = c; for (var i = 2; i >= 0; i--) { x = (F[i][(x + p[i]) % 26] - p[i] + 26) % 26; tr.push(x); } x = RF[x]; tr.push(x); for (i = 0; i < 3; i++) { x = (B[i][(x + p[i]) % 26] - p[i] + 26) % 26; tr.push(x); } out += A[x]; last = { tr: tr, p: p.slice() }; }); | |
| 11 | + return { out: out, last: last, p: p }; } | |
| 12 | + S._enigma = run; | |
| 13 | + S.loop(function () { | |
| 14 | + var w = S.W, h = S.H, sm = S.small(), R = run(inp.v), top = sm ? 96 : 56, rh = (h - top - 10) / 26, x0 = sm ? 26 : w * .06, x1 = sm ? w - 12 : w * .6, colw = (x1 - x0) / 4.4, fs = Math.max(8, Math.min(12, rh * .8)); | |
| 15 | + S.clear(); | |
| 16 | + function Y(i) { return top + (i + .5) * rh; } | |
| 17 | + var names = ['Mirror', 'Left wheel', 'Middle wheel', 'Right wheel'], xs = [0, 1, 2, 3].map(function (k) { return x0 + colw * (.2 + k * 1.1); }); | |
| 18 | + xs.forEach(function (x, k) { S.rr(x, top - 4, colw * .8, rh * 26 + 8, 8, '#161a21', C.grid); S.txt(sm ? names[k].split(' ')[0] : names[k], x + colw * .4, top - 30, C.mut, 11, 'center'); if (k > 0) { S.rr(x + colw * .4 - 13, top - 22, 26, 17, 5, C.bg, C.dim); S.txt(A[R.p[k - 1]], x + colw * .4, top - 13, C.acc, 11.5, 'center', 700); } }); | |
| 19 | + var kx = x1 - colw * .05; for (var i = 0; i < 26; i++) S.txt(A[i], kx + 8, Y(i), C.dim, fs, 'center'); | |
| 20 | + if (R.last) { var t = R.last.tr; // t: [in, afterR, afterM, afterL, afterRef, backL, backM, backR] | |
| 21 | + function seg(pts, col) { ctx.beginPath(); pts.forEach(function (q) { ctx.lineTo(q[0], q[1]); }); ctx.strokeStyle = col; ctx.lineWidth = 2.5; ctx.lineJoin = 'round'; ctx.stroke(); } | |
| 22 | + var e = colw * .8, f = [[kx, Y(t[0])], [xs[3] + e, Y(t[0])], [xs[3], Y(t[1])], [xs[2] + e, Y(t[1])], [xs[2], Y(t[2])], [xs[1] + e, Y(t[2])], [xs[1], Y(t[3])], [xs[0] + e, Y(t[3])], [xs[0] + e * .3, Y(t[3])]]; | |
| 23 | + var b = [[xs[0] + e * .3, Y(t[4])], [xs[0] + e, Y(t[4])], [xs[1], Y(t[4])], [xs[1] + e, Y(t[5])], [xs[2], Y(t[5])], [xs[2] + e, Y(t[6])], [xs[3], Y(t[6])], [xs[3] + e, Y(t[7])], [kx, Y(t[7])]]; | |
| 24 | + seg(f, C.acc); seg([[xs[0] + e * .3, Y(t[3])], [xs[0] + e * .3, Y(t[4])]], C.ink); seg(b, C.blue); | |
| 25 | + S.dot(kx + 8, Y(t[0]), fs * .85, C.acc); S.txt(A[t[0]], kx + 8, Y(t[0]) + .5, '#1a1206', fs, 'center', 700); S.dot(kx + 8, Y(t[7]), fs * .85, C.blue); S.txt(A[t[7]], kx + 8, Y(t[7]) + .5, '#0b1520', fs, 'center', 700); } | |
| 26 | + var tx = sm ? 12 : w * .66, ty = sm ? 14 : h * .22, big = sm ? 15 : 24, shown = inp.v.toUpperCase().replace(/[^A-Z ]/g, ''); | |
| 27 | + if (sm) { S.txt('In: ' + shown.slice(-26), tx, ty, C.acc, big, 'left', 700); S.txt('Out: ' + R.out.slice(-26), tx, ty + 22, C.blue, big, 'left', 700); } | |
| 28 | + else { S.txt('You type', tx, ty, C.mut, 12.5); S.txt(shown.slice(-22) || ' ', tx, ty + 30, C.acc, big, 'left', 700); S.txt('The machine lights up', tx, ty + 80, C.mut, 12.5); S.txt(R.out.slice(-22) || ' ', tx, ty + 110, C.blue, big, 'left', 700); S.txt('Wheels now at ' + R.p.map(L).join(' '), tx, ty + 160, C.mut, 13); } | |
| 29 | + S.say('Each key press sends a current through three wired wheels, off a mirror, and back by a different route to light another letter. Then the right wheel <b>clicks forward</b>, so the wiring changes for every letter. The same letter typed twice comes out different. To read a message, set the same starting wheels and type the scrambled text back in.'); | |
| 30 | + }); | |
| 31 | + }); |
exp/fourier.js added
| 1 | + WE.mount('fourier', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, t = 0, tr = []; | |
| 3 | + var shape = S.select('Target shape', [['square', 'Square'], ['saw', 'Sawtooth'], ['tri', 'Triangle']], 'square', function () { tr = []; }); | |
| 4 | + var n = S.slider('Circles', 1, 40, 3, 1, null, function () { tr = []; }); | |
| 5 | + function terms() { var out = [], k; for (var i = 0; i < n.v; i++) { if (shape.v === 'square') { k = 2 * i + 1; out.push([k, 4 / Math.PI / k]); } else if (shape.v === 'saw') { k = i + 1; out.push([k, 2 / Math.PI / k * (k % 2 ? 1 : -1)]); } else { k = 2 * i + 1; out.push([k, 8 / Math.PI / Math.PI / k / k * (i % 2 ? -1 : 1)]); } } return out; } | |
| 6 | + function target(x) { var p = ((x % S.TAU) + S.TAU) % S.TAU; return shape.v === 'square' ? (p < Math.PI ? 1 : -1) : shape.v === 'saw' ? (p < Math.PI ? p / Math.PI : p / Math.PI - 2) : (p < Math.PI / 2 ? p / (Math.PI / 2) : p < 1.5 * Math.PI ? 2 - p / (Math.PI / 2) : p / (Math.PI / 2) - 4); } | |
| 7 | + S.loop(function (dt) { | |
| 8 | + t += dt * 1.1; var w = S.W, h = S.H, sm = S.small(), A = sm ? Math.min(w * .13, h * .2) : Math.min(w * .1, h * .24), cx = sm ? w * .2 : w * .2, cy = h * .5, x = cx, y = cy, T = terms(); | |
| 9 | + S.clear(); | |
| 10 | + T.forEach(function (q) { var r = Math.abs(q[1]) * A, ph = q[0] * t + (q[1] < 0 ? Math.PI : 0), nx = x + r * Math.cos(ph), ny = y - r * Math.sin(ph); S.ring(x, y, r, 'rgba(255,255,255,.14)', 1); S.ln(x, y, nx, ny, C.ink, 1.5); x = nx; y = ny; }); | |
| 11 | + S.dot(x, y, 4, C.acc); tr.unshift([t, y]); var gx = sm ? w * .42 : w * .42, gw = w - gx - 14, step = 1.6; if (tr.length > gw / step) tr.length = Math.floor(gw / step); | |
| 12 | + S.ln(x, y, gx, y, 'rgba(213,163,90,.5)', 1); S.ln(gx, cy - A * 1.4, gx, cy + A * 1.4, C.grid, 1); S.ln(gx, cy, gx + gw, cy, C.grid, 1); | |
| 13 | + ctx.beginPath(); tr.forEach(function (v, i) { ctx.lineTo(gx + i * step, cy - target(v[0]) * A); }); ctx.strokeStyle = 'rgba(111,177,230,.4)'; ctx.lineWidth = 1.5; ctx.stroke(); | |
| 14 | + ctx.beginPath(); tr.forEach(function (v, i) { ctx.lineTo(gx + i * step, v[1]); }); ctx.strokeStyle = C.acc; ctx.lineWidth = 2.5; ctx.stroke(); S.dot(gx, y, 4, C.acc); | |
| 15 | + S.txt(n.v + (n.v === 1 ? ' circle' : ' circles'), 14, 18, C.ink, 15, 'left', 700); S.txt('Target', gx + gw, cy - A * 1.4 - 6, 'rgba(111,177,230,.8)', 11.5, 'right'); S.txt('Sum of the circles', gx + 8, cy - A * 1.4 - 6, C.acc, 11.5); | |
| 16 | + S.say('Each circle spins at a steady speed and rides on the end of the one before it. With one circle you get a smooth wave. Add more, smaller and faster, and the gold line closes in on the <b>blue target shape</b>. Any repeating shape can be built this way.'); | |
| 17 | + }); | |
| 18 | + }); |
exp/galton.js added
| 1 | + WE.mount('galton', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, balls = [], bins = [], total = 0, acc = 0; | |
| 3 | + var rows = S.slider('Rows of pegs', 2, 16, 10, 1, null, reset), bias = S.slider('Chance of bouncing right', 10, 90, 50, 5, function (v) { return v + '%'; }, reset), rate = S.slider('Balls a second', 1, 200, 30, 1); | |
| 4 | + S.button('Empty it', reset); | |
| 5 | + function reset() { balls = []; bins = []; for (var i = 0; i <= rows.v; i++) bins.push(0); total = 0; } | |
| 6 | + reset(); | |
| 7 | + function binom(n, k, p) { var c = 1; for (var i = 0; i < k; i++) c = c * (n - i) / (i + 1); return c * Math.pow(p, k) * Math.pow(1 - p, n - k); } | |
| 8 | + S.loop(function (dt) { | |
| 9 | + var w = S.W, h = S.H, n = rows.v, p = bias.v / 100, top = h * .06, ph = h * .5, gap = Math.min(w * .9 / (n + 2), ph / n), cx = w / 2, by = top + n * gap + gap * .5, bh = h - by - 26; | |
| 10 | + acc += dt * rate.v; while (acc >= 1) { acc--; balls.push({ r: 0, k: 0, f: 0, nx: Math.random() < p ? 1 : 0 }); } | |
| 11 | + S.clear(); | |
| 12 | + for (var r = 0; r < n; r++) for (var k = 0; k <= r; k++) S.dot(cx + (k - r / 2) * gap, top + (r + .5) * gap, Math.max(1.5, gap * .09), C.mut); | |
| 13 | + var sp = Math.max(3, rate.v / 6); | |
| 14 | + for (var i = balls.length - 1; i >= 0; i--) { | |
| 15 | + var b = balls[i]; b.f += dt * sp; | |
| 16 | + while (b.f >= 1 && b.r < n) { b.f -= 1; b.k += b.nx; b.r++; b.nx = Math.random() < p ? 1 : 0; } | |
| 17 | + if (b.r >= n) { bins[b.k]++; total++; balls.splice(i, 1); continue; } | |
| 18 | + var x1 = cx + (b.k - b.r / 2) * gap, x2 = cx + (b.k + b.nx - (b.r + 1) / 2) * gap, y = top + (b.r + b.f) * gap + gap * .1 - Math.sin(b.f * Math.PI) * gap * .22; if (b.r === 0 && b.f < 0) continue; | |
| 19 | + S.dot(x1 + (x2 - x1) * b.f, y, Math.max(2, gap * .13), C.acc); | |
| 20 | + } | |
| 21 | + var mx = Math.max.apply(null, bins.concat([1])), pm = 0; for (k = 0; k <= n; k++) pm = Math.max(pm, binom(n, k, p)); var scale = Math.max(mx, total * pm); | |
| 22 | + for (k = 0; k <= n; k++) { var x = cx + (k - n / 2) * gap, hh = bins[k] / scale * bh; S.rr(x - gap * .42, by + bh - hh, gap * .84, hh, 2, 'rgba(213,163,90,.75)'); if (gap > 26) S.txt(bins[k], x, by + bh + 12, C.mut, 10.5, 'center'); } | |
| 23 | + if (total > 0) { ctx.beginPath(); for (k = 0; k <= n; k++) ctx.lineTo(cx + (k - n / 2) * gap, by + bh - binom(n, k, p) * total / scale * bh); ctx.strokeStyle = C.blue; ctx.lineWidth = 2; ctx.stroke(); for (k = 0; k <= n; k++) S.dot(cx + (k - n / 2) * gap, by + bh - binom(n, k, p) * total / scale * bh, 3, C.blue); } | |
| 24 | + S.txt(total.toLocaleString('en-US') + ' balls', 14, 18, C.ink, 15, 'left', 700); S.txt('Blue line: what the math predicts', 14, 40, C.blue, 12); | |
| 25 | + S.say('Every ball bounces left or right at each peg, by pure chance. No one can say where a single ball will land. Yet the pile always grows into the same <b>bell shape</b>, because there are many more paths to the middle than to the edges.'); | |
| 26 | + }); | |
| 27 | + }); |
exp/gas.js added
| 1 | + WE.mount('gas', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, P = [], imp = 0, win = 0, pres = 0; | |
| 3 | + var T = S.slider('Temperature', 50, 900, 300, 10, function (v) { return v + ' K (' + (v - 273) + ' °C)'; }), V = S.slider('Volume', 30, 100, 100, 1, function (v) { return v + '%'; }), N = S.slider('Particles', 10, 300, 120, 10); | |
| 4 | + function mk() { return { x: Math.random(), y: Math.random(), a: Math.random() * 6.283, s: .5 + Math.random() }; } | |
| 5 | + S.loop(function (dt) { | |
| 6 | + while (P.length < N.v) P.push(mk()); P.length = N.v; | |
| 7 | + S.clear(); var w = S.W, h = S.H, sm = S.small(), bx = 20, by = 30, bh = h - 60, full = (sm ? w - 40 : w * .62), bw = full * V.v / 100, sp = Math.sqrt(T.v / 300) * 150; | |
| 8 | + P.forEach(function (p) { | |
| 9 | + var vx = Math.cos(p.a) * sp * p.s, vy = Math.sin(p.a) * sp * p.s; p.x += vx * dt / bw; p.y += vy * dt / bh; | |
| 10 | + if (p.x < 0) { p.x = -p.x; p.a = Math.PI - p.a; imp += 2 * Math.abs(vx); } if (p.x > 1) { p.x = 2 - p.x; if (p.x < 0) p.x = .5; p.a = Math.PI - p.a; imp += 2 * Math.abs(vx); } | |
| 11 | + if (p.y < 0) { p.y = -p.y; p.a = -p.a; imp += 2 * Math.abs(vy); } if (p.y > 1) { p.y = 2 - p.y; if (p.y < 0) p.y = .5; p.a = -p.a; imp += 2 * Math.abs(vy); } | |
| 12 | + var heat = Math.min(1, (T.v - 50) / 850); S.dot(bx + p.x * bw, by + p.y * bh, 3.2, 'rgb(' + Math.round(110 + 140 * heat) + ',' + Math.round(170 - 60 * heat) + ',' + Math.round(230 - 150 * heat) + ')'); | |
| 13 | + }); | |
| 14 | + win += dt; if (win > .5) { pres = (pres ? pres * .6 : 0) + (pres ? .4 : 1) * (imp / win / (2 * (bw + bh))) / 60 * full * bh / 24372; imp = 0; win = 0; } | |
| 15 | + S.rr(bx, by, bw, bh, 4, null, C.mut); S.rr(bx + bw, by - 6, 12, bh + 12, 3, C.dim); S.ln(bx + bw + 12, by + bh / 2, bx + full + 26, by + bh / 2, C.dim, 6); | |
| 16 | + var ideal = N.v * T.v / V.v / 360, tx = sm ? bx + 8 : w * .72, ty = sm ? by + 20 : h * .3; | |
| 17 | + if (sm) S.rr(tx - 6, ty - 16, 190, 74, 8, 'rgba(13,15,19,.75)'); | |
| 18 | + S.txt('Pressure', tx, ty, C.mut, 13); S.txt(pres.toFixed(1), tx, ty + 28, C.ink, sm ? 24 : 38, 'left', 700); S.txt('The gas law predicts ' + ideal.toFixed(1), tx, ty + (sm ? 48 : 62), C.green, 12.5, 'left', 600); | |
| 19 | + S.say('Pressure is nothing but countless tiny hits on the walls. <b>Heat the gas</b> and the particles hit harder. <b>Squeeze it</b> and they hit more often. Halve the volume and the pressure doubles.'); | |
| 20 | + }); | |
| 21 | + }); |
exp/gears.js added
| 1 | + WE.mount('gears', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, th = 0, turns = 0; | |
| 3 | + var na = S.slider('Gold gear teeth', 8, 40, 12, 1), nb = S.slider('Blue gear teeth', 8, 40, 30, 1), sp = S.slider('Gold gear speed', 0, 60, 20, 1, function (v) { return v + ' turns a minute'; }); | |
| 4 | + function gear(x, y, N, m, ang, col) { | |
| 5 | + var rp = N * m / 2, ro = rp + m * .9, rr = rp - m * 1.1, p = S.TAU / N; | |
| 6 | + ctx.beginPath(); | |
| 7 | + for (var i = 0; i < N; i++) { var a = ang + i * p; [[rr, -.27], [ro, -.14], [ro, .14], [rr, .27]].forEach(function (q) { ctx.lineTo(x + q[0] * Math.cos(a + q[1] * p), y + q[0] * Math.sin(a + q[1] * p)); }); } | |
| 8 | + ctx.closePath(); ctx.fillStyle = C.panel; ctx.fill(); ctx.strokeStyle = col; ctx.lineWidth = 2; ctx.stroke(); | |
| 9 | + S.ring(x, y, rp, 'rgba(255,255,255,.07)', 1); | |
| 10 | + for (var s = 0; s < 3; s++) { var b = ang + s * S.TAU / 3; S.ln(x + Math.cos(b) * m * 1.2, y + Math.sin(b) * m * 1.2, x + Math.cos(b) * (rr - m * .5), y + Math.sin(b) * (rr - m * .5), 'rgba(255,255,255,.1)', Math.max(2, m * .5)); } | |
| 11 | + S.dot(x + Math.cos(ang) * (rr - m * .2), y + Math.sin(ang) * (rr - m * .2), Math.max(3, m * .35), col); S.dot(x, y, Math.max(4, m * .7), col); | |
| 12 | + } | |
| 13 | + S.loop(function (dt) { | |
| 14 | + var w = S.W, h = S.H, sm = S.small(), A = na.v, B = nb.v, d = dt * sp.v / 60 * S.TAU; th += d; turns += d / S.TAU; | |
| 15 | + var top = sm ? 50 : 20, m = Math.min(w * .9 / (A + B + 4), (h - top - 20) / (Math.max(A, B) + 3)), ra = A * m / 2, rb = B * m / 2, xa = w / 2 - (ra + rb) / 2 - (rb - ra) / 2 + 0, y = top + (h - top) / 2; | |
| 16 | + xa = w / 2 - (ra + rb) + ra; var xb = xa + ra + rb; | |
| 17 | + S.clear(); gear(xa, y, A, m, th, C.acc); gear(xb, y, B, m, Math.PI + Math.PI / B - th * A / B, C.blue); | |
| 18 | + var ratio = B / A, tb = turns * A / B; | |
| 19 | + S.txt('Gold: ' + turns.toFixed(1) + ' turns', 14, 18, C.acc, sm ? 13 : 15, 'left', 700); S.txt('Blue: ' + tb.toFixed(1) + ' turns', 14, sm ? 38 : 42, C.blue, sm ? 13 : 15, 'left', 700); | |
| 20 | + S.txt(A + ' : ' + B, w - 54, 18, C.ink, sm ? 15 : 20, 'right', 700); S.txt('Blue turns at ' + (sp.v / ratio).toFixed(1) + ' a minute', w - 54, sm ? 38 : 44, C.mut, 12.5, 'right'); | |
| 21 | + S.say(A === B ? 'Same teeth, same speed. The second gear just turns the <b>other way</b>.' : A < B ? 'The small gear drives the big one. The big gear turns <b>' + ratio.toFixed(2) + ' times slower</b>, but with ' + ratio.toFixed(2) + ' times the twisting force. This is a low gear: slow and strong.' : 'The big gear drives the small one. The small gear spins <b>' + (1 / ratio).toFixed(2) + ' times faster</b>, with less twisting force. This is a high gear: fast and light.'); | |
| 22 | + }); | |
| 23 | + }); |
exp/heart.js added
| 1 | + WE.mount('heart', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, ph = 0, beats = 0, ecg = [], pos = 0; | |
| 3 | + var bpm = S.slider('Heart rate', 40, 190, 70, 1, function (v) { return v + ' beats a minute'; }), snd = S.toggle('Sound', false); | |
| 4 | + var PTS = [[.5, .88], [.1, .88], [.1, .3], [.37, .3], [.37, .6], [.47, .5], [.47, .1], [.52, .06], [.9, .06], [.9, .3], [.63, .3], [.63, .6], [.63, .88], [.5, .88]], LUNG = 7, len = [0]; | |
| 5 | + for (var i = 1; i < PTS.length; i++) len.push(len[i - 1] + Math.hypot(PTS[i][0] - PTS[i - 1][0], PTS[i][1] - PTS[i - 1][1])); | |
| 6 | + var TOT = len[len.length - 1], LF = len[LUNG] / TOT; | |
| 7 | + function at(s) { var d = (s % 1) * TOT; for (var i = 1; i < len.length; i++) if (d <= len[i]) { var f = (d - len[i - 1]) / (len[i] - len[i - 1]); return [PTS[i - 1][0] + (PTS[i][0] - PTS[i - 1][0]) * f, PTS[i - 1][1] + (PTS[i][1] - PTS[i - 1][1]) * f]; } return PTS[0]; } | |
| 8 | + function g(x, m, s) { return Math.exp(-(x - m) * (x - m) / (2 * s * s)); } | |
| 9 | + function wave(p) { return .12 * g(p, .08, .025) - .12 * g(p, .185, .008) + 1 * g(p, .2, .01) - .22 * g(p, .218, .009) + .28 * g(p, .42, .045); } | |
| 10 | + S.loop(function (dt) { | |
| 11 | + var prev = ph, rate = bpm.v / 60; ph += dt * rate; if (Math.floor(ph) > Math.floor(prev)) beats++; | |
| 12 | + var p = ph % 1, pp = prev % 1; if (snd.v) { if (pp < .2 && p >= .2) S.tone(55, .14, 'sine', .5); if (pp < .5 && p >= .5) S.tone(75, .1, 'sine', .35); } | |
| 13 | + var atr = Math.sin(Math.PI * Math.min(1, Math.max(0, p / .16))), ven = Math.sin(Math.PI * Math.min(1, Math.max(0, (p - .2) / .3))); | |
| 14 | + pos += dt * rate * (.012 + .09 * ven); ecg.push(wave(p)); if (ecg.length > 420) ecg.shift(); | |
| 15 | + var w = S.W, h = S.H, sm = S.small(), bs = sm ? Math.min(w * .96, h * .66) : Math.min(w * .5, h * .96), bx = sm ? (w - bs) / 2 : w * .04, by = sm ? 4 : (h - bs) / 2; | |
| 16 | + function X(v) { return bx + v * bs; } function Y(v) { return by + v * bs; } | |
| 17 | + S.clear(); | |
| 18 | + for (var i = 1; i < PTS.length; i++) S.ln(X(PTS[i - 1][0]), Y(PTS[i - 1][1]), X(PTS[i][0]), Y(PTS[i][1]), i <= LUNG ? 'rgba(111,177,230,.22)' : 'rgba(232,115,92,.22)', bs * .035); | |
| 19 | + function box(x, y, ww, hh, name, sq, col) { var k = 1 - sq * .16; S.rr(X(x + ww * (1 - k) / 2), Y(y + hh * (1 - k) / 2), ww * k * bs, hh * k * bs, bs * .03, col, C.ink); var L = x < .5, lx = L ? X(x + .018) : X(x + ww - .018), fs = sm ? 9.5 : 12.5; name.forEach(function (nm, j) { S.txt(nm, lx, Y(y + hh / 2) + (j - .5) * (fs + 3), C.ink, fs, L ? 'left' : 'right', 600); }); } | |
| 20 | + box(.22, .2, .2, .2, ['Right', 'atrium'], atr, '#2b4763'); box(.22, .46, .2, .28, ['Right', 'ventricle'], ven, '#2b4763'); box(.58, .2, .2, .2, ['Left', 'atrium'], atr, '#6b3329'); box(.58, .46, .2, .28, ['Left', 'ventricle'], ven, '#6b3329'); | |
| 21 | + S.rr(X(.35), Y(.015), .3 * bs, .09 * bs, bs * .03, '#1b2028', C.dim); S.txt('Lungs', X(.6), Y(.035), C.ink, sm ? 11 : 13, 'center', 600); S.rr(X(.3), Y(.85), .4 * bs, .1 * bs, bs * .03, '#1b2028', C.dim); S.txt('Rest of the body', X(.5), Y(.925), C.ink, sm ? 11 : 13, 'center', 600); | |
| 22 | + for (var k = 0; k < 70; k++) { var s = (k / 70 + pos) % 1, q = at(s); S.dot(X(q[0]), Y(q[1]), Math.max(2, bs * .009), s < LF ? C.blue : C.red); } | |
| 23 | + // readout | |
| 24 | + var tx = sm ? 12 : w * .6, ty = sm ? by + bs + 14 : h * .16, gw = sm ? w - 24 : w * .36, gy = sm ? ty + 54 : h * .62, gh = sm ? Math.min(40, (h - gy) * .7) : h * .16; | |
| 25 | + S.txt(bpm.v + '', tx, ty + (sm ? 0 : 10), C.ink, sm ? 22 : 44, 'left', 700); S.txt('beats a minute', tx + (sm ? 44 : 84), ty + (sm ? 2 : 16), C.mut, 13); | |
| 26 | + S.txt((bpm.v * 1440).toLocaleString('en-US') + ' beats a day at this pace', sm ? w - 12 : tx, sm ? ty + 2 : ty + 56, C.mut, sm ? 11 : 13.5, sm ? 'right' : 'left'); | |
| 27 | + if (!sm) { S.dot(tx + 6, ty + 96, 5, C.blue); S.txt('Used blood, low in oxygen', tx + 20, ty + 96, C.mut, 12.5); S.dot(tx + 6, ty + 118, 5, C.red); S.txt('Fresh blood, rich in oxygen', tx + 20, ty + 118, C.mut, 12.5); } | |
| 28 | + ctx.beginPath(); ecg.forEach(function (v, i) { ctx.lineTo(tx + gw * i / 420, gy - v * gh); }); ctx.strokeStyle = C.green; ctx.lineWidth = 2; ctx.stroke(); S.txt('Electrical signal', tx, gy + gh * .5 + 6, C.dim, 11.5); | |
| 29 | + S.say('The heart is two pumps side by side. The right side sends used blood to the <b style="color:#6fb1e6">lungs</b> to pick up oxygen. The left side sends that fresh blood to the <b style="color:#e8735c">whole body</b>. The small top rooms fill the big bottom rooms, then the bottom rooms squeeze. This is a diagram, not a drawing of a real heart.'); | |
| 30 | + }); | |
| 31 | + }); |
exp/life.js added
| 1 | + WE.mount('life', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, cols = 0, rws = 0, g, age, gen = 0, acc = 0, cs = 10, paint = 1, G = {}; | |
| 3 | + var PAT = { glider: ['.O.', '..O', 'OOO'], pulsar: ['..OOO...OOO..', '.............', 'O....O.O....O', 'O....O.O....O', 'O....O.O....O', '..OOO...OOO..', '.............', '..OOO...OOO..', 'O....O.O....O', 'O....O.O....O', 'O....O.O....O', '.............', '..OOO...OOO..'], rpent: ['.OO', 'OO.', '.O.'], | |
| 4 | + gun: ['........................O...........', '......................O.O...........', '............OO......OO............OO', '...........O...O....OO............OO', 'OO........O.....O...OO..............', 'OO........O...O.OO....O.O...........', '..........O.....O.......O...........', '...........O...O....................', '............OO......................'] }; | |
| 5 | + var play = S.toggle('Run', true), spd = S.slider('Speed', 1, 40, 12, 1, function (v) { return v + ' steps a second'; }); | |
| 6 | + S.button('One step', function () { play.set(false); step(); }); | |
| 7 | + var pat = S.select('Start with', [['gun', 'Glider gun'], ['glider', 'Glider'], ['pulsar', 'Pulsar'], ['rpent', 'Five cells'], ['rand', 'Random'], ['clear', 'Empty']], 'gun', load); | |
| 8 | + function init() { var w = S.W, h = S.H; cs = S.small() ? 8 : 11; var c = Math.floor(w / cs), r = Math.floor(h / cs); if (c === cols && r === rws) return; cols = c; rws = r; g = new Uint8Array(cols * rws); age = new Uint8Array(cols * rws); load(pat.v); } | |
| 9 | + function load(v) { if (!cols) return; g.fill(0); age.fill(0); gen = 0; if (v === 'rand') { for (var i = 0; i < g.length; i++) g[i] = Math.random() < .28 ? 1 : 0; return; } if (v === 'clear') { play.set(false); return; } var P = PAT[v], ox = v === 'gun' ? 2 : Math.floor((cols - P[0].length) / 2), oy = v === 'gun' ? 2 : Math.floor((rws - P.length) / 2); P.forEach(function (row, y) { for (var x = 0; x < row.length; x++) if (row[x] === 'O' && x + ox < cols && y + oy < rws) g[(y + oy) * cols + x + ox] = 1; }); play.set(true); } | |
| 10 | + function step() { var n = new Uint8Array(g.length); for (var y = 0; y < rws; y++) for (var x = 0; x < cols; x++) { var c = 0; for (var dy = -1; dy <= 1; dy++) for (var dx = -1; dx <= 1; dx++) { if (!dx && !dy) continue; var xx = (x + dx + cols) % cols, yy = (y + dy + rws) % rws; c += g[yy * cols + xx]; } var i = y * cols + x, a = g[i]; n[i] = a ? (c === 2 || c === 3 ? 1 : 0) : (c === 3 ? 1 : 0); age[i] = n[i] ? Math.min(250, age[i] + 1) : 0; } g = n; gen++; } | |
| 11 | + function at(x, y) { var c = Math.floor(x / cs), r = Math.floor(y / cs); return c >= 0 && c < cols && r >= 0 && r < rws ? r * cols + c : -1; } | |
| 12 | + S.pointer({ cursor: 'crosshair', down: function (x, y) { var i = at(x, y); if (i < 0) return; paint = g[i] ? 0 : 1; g[i] = paint; age[i] = 0; }, move: function (x, y, d) { if (!d) return; var i = at(x, y); if (i >= 0) { g[i] = paint; if (!paint) age[i] = 0; } } }); | |
| 13 | + S.onresize = init; init(); | |
| 14 | + S.loop(function (dt) { | |
| 15 | + if (!cols) { init(); return; } | |
| 16 | + if (play.v && !S.ptr.down) { acc += dt * spd.v; var k = 0; while (acc >= 1 && k++ < 4) { acc--; step(); } if (acc > 4) acc = 0; } | |
| 17 | + S.clear(); var live = 0, ox = (S.W - cols * cs) / 2, oy = (S.H - rws * cs) / 2; | |
| 18 | + for (var i = 0; i < g.length; i++) if (g[i]) { live++; var a = age[i]; ctx.fillStyle = a < 2 ? C.ink : a < 8 ? C.acc : '#a57a3e'; ctx.fillRect(ox + (i % cols) * cs + .5, oy + Math.floor(i / cols) * cs + .5, cs - 1, cs - 1); } | |
| 19 | + S.rr(8, 8, 210, 28, 14, 'rgba(13,15,19,.8)'); S.txt('Step ' + gen + ' · ' + live + ' alive', 20, 22, C.ink, 12.5, 'left', 600); | |
| 20 | + S.say('Each square looks at its eight neighbors. A live square with <b>2 or 3</b> live neighbors stays alive. An empty square with <b>exactly 3</b> comes alive. Everything else dies or stays empty. That is the whole rule. <b>Draw on the grid</b> to add your own cells.'); | |
| 21 | + }); | |
| 22 | + }); |
exp/lock.js added
| 1 | + WE.mount('lock', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, N = 5, req = [], lift = [0, 0, 0, 0, 0], show = [0, 0, 0, 0, 0], key = false, turn = 0, G = {}; | |
| 3 | + function fresh() { req = []; for (var i = 0; i < N; i++) req.push(1 + Math.floor(Math.random() * 5)); lift = [0, 0, 0, 0, 0]; key = false; } | |
| 4 | + fresh(); req = [3, 5, 2, 4, 1]; | |
| 5 | + S.button('Use the right key', function () { lift = req.slice(); key = true; }); | |
| 6 | + S.button('Try a wrong key', function () { do { lift = req.map(function () { return 1 + Math.floor(Math.random() * 5); }); } while (lift.every(function (v, i) { return v === req[i]; })); key = true; }); | |
| 7 | + S.button('Take the key out', function () { lift = [0, 0, 0, 0, 0]; key = false; }); | |
| 8 | + S.button('New lock', fresh); | |
| 9 | + S.pointer({ scroll: true, down: function (x, y) { for (var i = 0; i < N; i++) if (Math.abs(x - G.px(i)) < G.gap / 2) { if (key) { key = false; } lift[i] = (lift[i] + 1) % 6; } } }); | |
| 10 | + S.loop(function (dt) { | |
| 11 | + var w = S.W, h = S.H, sm = S.small(), u = h * .034, ys = h * .46, x0 = w * (sm ? .04 : .08), x1 = w * (sm ? .96 : .66), gap = (x1 - x0) / (N + 1.2), pw = Math.min(gap * .5, u * 2.4); | |
| 12 | + G.gap = gap; G.px = function (i) { return x0 + gap * (i + 1.1); }; | |
| 13 | + var open = lift.every(function (v, i) { return v === req[i]; }), ok = 0; | |
| 14 | + for (var i = 0; i < N; i++) { show[i] += (lift[i] - show[i]) * Math.min(1, dt * 14); } | |
| 15 | + turn += ((open ? 1 : 0) - turn) * Math.min(1, dt * 5); | |
| 16 | + S.clear(); | |
| 17 | + S.rr(x0, ys - 12 * u, x1 - x0, 12 * u, 6, '#1d222b', C.dim); S.rr(x0, ys, x1 - x0, 12.6 * u, 6, '#262c37', C.dim); | |
| 18 | + ctx.fillStyle = C.bg; ctx.fillRect(x0, ys + 6 * u, x1 - x0, 6 * u); | |
| 19 | + S.txt('Housing (fixed)', x0 + 8, ys - 12 * u + 12, C.mut, 11.5); S.txt('Plug (turns)', x0 + 8, ys + 13 * u + 8, C.mut, 11.5); | |
| 20 | + if (key) { ctx.beginPath(); ctx.moveTo(x0 - 4, ys + 12 * u); ctx.lineTo(x0 - 4, ys + 9 * u); for (var j = 0; j < N; j++) { var kx = G.px(j), ky = ys + 11 * u - show[j] * u; ctx.lineTo(kx - gap * .32, ky + (j === 0 ? 0 : 0)); ctx.lineTo(kx - pw * .2, ky); ctx.lineTo(kx + pw * .2, ky); ctx.lineTo(kx + gap * .32, ky); if (j < N - 1) ctx.lineTo(kx + gap / 2, ys + 11.4 * u); } ctx.lineTo(x1 - gap * .25, ys + 12 * u); ctx.closePath(); ctx.fillStyle = '#8f8a7c'; ctx.fill(); ctx.strokeStyle = C.ink; ctx.lineWidth = 1; ctx.stroke(); } | |
| 21 | + for (i = 0; i < N; i++) { | |
| 22 | + var px = G.px(i), bot = ys + 11 * u - show[i] * u, kl = (11 - req[i]) * u, kt = bot - kl, dt2 = kt - 6 * u, good = Math.abs(show[i] - req[i]) < .08; if (lift[i] === req[i]) ok++; | |
| 23 | + ctx.fillStyle = C.bg; ctx.fillRect(px - pw / 2 - 2, ys - 11.4 * u, pw + 4, 22.4 * u); | |
| 24 | + ctx.strokeStyle = C.mut; ctx.lineWidth = 1.5; ctx.beginPath(); var sy0 = ys - 11.2 * u, n = 9; for (var z = 0; z <= n; z++) ctx.lineTo(px + (z % 2 ? pw * .35 : -pw * .35), sy0 + (dt2 - sy0) * z / n); ctx.stroke(); | |
| 25 | + S.rr(px - pw / 2, dt2, pw, 6 * u - 1.5, 3, C.blue, good ? C.green : null); S.rr(px - pw / 2, kt + 1.5, pw, kl - 1.5, 3, C.acc, good ? C.green : null); | |
| 26 | + ctx.beginPath(); ctx.moveTo(px - pw / 2, bot - 4); ctx.lineTo(px, bot + 3); ctx.lineTo(px + pw / 2, bot - 4); ctx.fillStyle = C.acc; ctx.fill(); | |
| 27 | + S.dot(px, ys, 4, good ? C.green : C.red); | |
| 28 | + } | |
| 29 | + ctx.setLineDash([6, 5]); S.ln(x0 - 6, ys, x1 + 6, ys, open ? C.green : C.red, 1.5); ctx.setLineDash([]); if (!sm) S.txt('Shear line', x1 + 10, ys, open ? C.green : C.red, 11.5); | |
| 30 | + // front view | |
| 31 | + var fx = sm ? w - 46 : w * .87, fy = sm ? 96 : h * .4, fr = sm ? 26 : Math.min(w * .075, h * .2); | |
| 32 | + if (!sm) {S.ring(fx, fy, fr * 1.25, C.dim, 6); S.dot(fx, fy, fr, '#262c37'); S.ring(fx, fy, fr, open ? C.green : C.mut, 2); | |
| 33 | + ctx.save(); ctx.translate(fx, fy); ctx.rotate(turn * Math.PI / 2); S.rr(-fr * .1, -fr * .6, fr * .2, fr * 1.2, 3, C.bg, C.mut); ctx.restore(); } | |
| 34 | + if (!sm) { S.txt(open ? 'Open' : 'Locked', fx, fy + fr * 1.25 + 34, open ? C.green : C.red, 26, 'center', 700); S.txt(ok + ' of 5 pins lined up', fx, fy + fr * 1.25 + 62, C.mut, 13, 'center'); } | |
| 35 | + else S.txt(open ? 'Open' : 'Locked: ' + ok + ' of 5 lined up', w - 12, ys + 13 * u + 8, open ? C.green : C.red, 12.5, 'right', 700); | |
| 36 | + S.say(open ? '<b>Open.</b> Every gap between a gold pin and a blue pin sits exactly on the shear line, so nothing blocks the plug and it can turn.' : key ? 'This key lifts the pins to the wrong heights. Wherever a pin crosses the red line, it <b>blocks the plug</b> like a bolt through two plates.' : 'Springs push the pins down so they cross the line and jam the plug. A key works by lifting each pin just the right amount. <b>Tap a pin</b> to lift it a notch and try to line up all five by hand.'); | |
| 37 | + }); | |
| 38 | + }); |
exp/mandelbrot.js added
| 1 | + WE.mount('mandelbrot', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, cx = -.6, cy = 0, span = 3.2, off = document.createElement('canvas'), octx = off.getContext('2d'), img = null, row = 0, bw = 0, bh = 0, pass = 0, zooms = 0; | |
| 3 | + var HOME = [-.6, 0, 3.2], SPOTS = { home: HOME, valley: [-.7453, .1127, .012], spiral: [-.7436, .1318, .004], mini: [-1.7549, 0, .06], tendril: [.2815, .0085, .03] }; | |
| 4 | + S.select('Go to', [['home', 'Whole set'], ['valley', 'Seahorse valley'], ['spiral', 'Spiral'], ['mini', 'A tiny copy'], ['tendril', 'Elephant valley']], 'home', function (v) { var p = SPOTS[v]; cx = p[0]; cy = p[1]; span = p[2]; redo(); }); | |
| 5 | + S.button('Zoom out', function () { span = Math.min(3.2, span * 3); redo(); }); | |
| 6 | + function redo() { row = 0; pass = 0; } | |
| 7 | + S.onresize = function () { bw = 0; }; | |
| 8 | + S.pointer({ scroll: true, cursor: 'zoom-in', down: function (x, y) { var sc = span / S.W; cx += (x - S.W / 2) * sc; cy += (y - S.H / 2) * sc; span = Math.max(2e-13, span / 3); zooms++; redo(); } }); | |
| 9 | + function col(n, max, d) { if (n >= max) return [8, 9, 12]; var v = n + 1 - Math.log(Math.log(Math.sqrt(d))) / Math.LN2, t = v * .045; return [Math.round(140 + 115 * Math.cos(t * 2.1 + 3.6)), Math.round(120 + 110 * Math.cos(t * 2.1 + 4.6)), Math.round(110 + 120 * Math.cos(t * 2.1 + 5.9))]; } | |
| 10 | + S.loop(function () { | |
| 11 | + var w = S.W, h = S.H, res = pass === 0 ? 4 : S.dpr > 1 ? 1 : 1, tw = Math.ceil(w / res), thh = Math.ceil(h / res); | |
| 12 | + if (bw !== tw || bh !== thh) { bw = tw; bh = thh; off.width = bw; off.height = bh; img = octx.createImageData(bw, bh); row = 0; } | |
| 13 | + if (row < bh) { | |
| 14 | + var max = Math.min(2000, Math.round(120 + 60 * Math.log(3.2 / span) / Math.LN10 * 2)), sc = span / bw, t0 = performance.now(), d = img.data; | |
| 15 | + while (row < bh && performance.now() - t0 < 14) { | |
| 16 | + var y0 = cy + (row - bh / 2) * sc; | |
| 17 | + for (var i = 0; i < bw; i++) { var x0 = cx + (i - bw / 2) * sc, x = 0, y = 0, n = 0, xx = 0, yy = 0; while (n < max && xx + yy < 64) { y = 2 * x * y + y0; x = xx - yy + x0; xx = x * x; yy = y * y; n++; } var c = col(n, max, xx + yy), o = (row * bw + i) * 4; d[o] = c[0]; d[o + 1] = c[1]; d[o + 2] = c[2]; d[o + 3] = 255; } | |
| 18 | + row++; | |
| 19 | + } | |
| 20 | + octx.putImageData(img, 0, 0, 0, 0, bw, row); | |
| 21 | + if (row >= bh && pass === 0) { ctx.imageSmoothingEnabled = true; ctx.drawImage(off, 0, 0, w, h); pass = 1; bw = 0; return; } | |
| 22 | + } | |
| 23 | + if (pass === 0) { ctx.drawImage(off, 0, 0, bw, row, 0, 0, w, row * res); } | |
| 24 | + else ctx.drawImage(off, 0, 0, bw, row, 0, 0, w, row * res); | |
| 25 | + var mag = 3.2 / span; S.rr(10, 10, 150, 30, 15, 'rgba(13,15,19,.75)'); S.txt('Zoom ' + (mag < 1000 ? mag.toFixed(mag < 10 ? 1 : 0) : mag.toExponential(1).replace('e+', ' × 10^')) + '×', 22, 25, C.ink, 13, 'left', 700); | |
| 26 | + S.say(span < 1e-12 ? 'You have reached the limit of this page’s arithmetic, about a trillion times zoom. The real shape keeps going <b>forever</b>.' : '<b>Tap anywhere to zoom in.</b> One short rule, repeated, draws all of this: take a number, square it, add your starting point, and do it again. Black points stay small forever. Colors show how fast the others fly away. The edge never gets smooth, however deep you go.'); | |
| 27 | + }); | |
| 28 | + }); |
exp/materials.js added
| 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 | + }); |
exp/moon-phases.js added
| 1 | + WE.mount('moon-phases', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, e = .9, grab = false, NAMES = ['New Moon', 'Waxing crescent', 'First quarter', 'Waxing gibbous', 'Full Moon', 'Waning gibbous', 'Last quarter', 'Waning crescent']; | |
| 3 | + var play = S.toggle('Orbit', true), spd = S.slider('Speed', 1, 10, 3, 1, function (v) { return v + ' days a second'; }); | |
| 4 | + var G = function () { var sm = S.small(), w = S.W, h = S.H; return sm ? { ex: w / 2, ey: h * .3, R: Math.min(w * .3, h * .2), vx: w / 2, vy: h * .76, vr: Math.min(w, h) * .15 } : { ex: w * .34, ey: h / 2, R: Math.min(w * .2, h * .34), vx: w * .78, vy: h * .46, vr: Math.min(w * .13, h * .26) }; }; | |
| 5 | + S.pointer({ down: function (x, y) { grab = true; set(x, y); }, move: function (x, y, d) { if (d && grab) set(x, y); }, up: function () { grab = false; } }); | |
| 6 | + function set(x, y) { var g = G(); e = (Math.atan2(-(y - g.ey), x - g.ex) - Math.PI + S.TAU * 2) % S.TAU; } | |
| 7 | + function moon(x, y, r, p) { S.dot(x, y, r, '#1a1f2b'); var k = Math.cos(p * S.TAU), s = p < .5 ? 1 : -1; ctx.beginPath(); ctx.arc(x, y, r, -Math.PI / 2, Math.PI / 2, s < 0); ctx.ellipse(x, y, Math.abs(k) * r, r, 0, Math.PI / 2, -Math.PI / 2, (k > 0) === (s > 0)); ctx.fillStyle = '#f2e7c4'; ctx.fill(); } | |
| 8 | + S.loop(function (dt) { | |
| 9 | + if (play.v && !grab) e = (e + dt * spd.v / 29.53 * S.TAU) % S.TAU; | |
| 10 | + S.clear(); var g = G(), p = e / S.TAU, mx = g.ex + g.R * Math.cos(Math.PI + e), my = g.ey - g.R * Math.sin(Math.PI + e); | |
| 11 | + for (var i = -3; i <= 3; i++) S.arrow(8, g.ey + i * g.R * .3, 8 + Math.min(46, S.W * .06), g.ey + i * g.R * .3, 'rgba(240,210,100,.7)', 1.5); | |
| 12 | + S.txt('Sunlight', 10, g.ey - g.R * .9 - 22, C.yellow, 12); | |
| 13 | + S.ring(g.ex, g.ey, g.R, 'rgba(255,255,255,.14)', 1); | |
| 14 | + // Earth: lit half faces the Sun (left) | |
| 15 | + var er = g.R * .2; S.dot(g.ex, g.ey, er, '#16283f'); ctx.beginPath(); ctx.arc(g.ex, g.ey, er, Math.PI / 2, -Math.PI / 2); ctx.fillStyle = C.blue; ctx.fill(); S.txt('Earth', g.ex, g.ey + er + 13, C.mut, 12, 'center'); | |
| 16 | + var mr = g.R * .11; S.dot(mx, my, mr, '#2a2f3a'); ctx.beginPath(); ctx.arc(mx, my, mr, Math.PI / 2, -Math.PI / 2); ctx.fillStyle = '#f2e7c4'; ctx.fill(); S.ring(mx, my, mr + 5, grab ? C.acc : 'rgba(213,163,90,.5)', 1.5); | |
| 17 | + ctx.setLineDash([4, 5]); S.ln(g.ex, g.ey, mx, my, 'rgba(255,255,255,.3)', 1); ctx.setLineDash([]); | |
| 18 | + moon(g.vx, g.vy, g.vr, p); S.txt('Seen from Earth', g.vx, g.vy - g.vr - 18, C.mut, 12.5, 'center'); | |
| 19 | + var nm = NAMES[Math.round(p * 8) % 8]; S.txt(nm, g.vx, g.vy + g.vr + 22, C.ink, S.small() ? 17 : 21, 'center', 700); S.txt('Day ' + (p * 29.53).toFixed(1) + ' of 29.5', g.vx, g.vy + g.vr + 46, C.mut, 13, 'center'); | |
| 20 | + S.say('<b>' + nm + '</b> The Sun always lights half of the Moon. ' + (Math.round((1 - Math.cos(e)) / 2 * 100)) + '% of the side facing us is lit right now. Drag the Moon around its orbit.'); | |
| 21 | + }); | |
| 22 | + }); |
exp/morse.js added
| 1 | + WE.mount('morse', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, M = { A: '.-', B: '-...', C: '-.-.', D: '-..', E: '.', F: '..-.', G: '--.', H: '....', I: '..', J: '.---', K: '-.-', L: '.-..', M: '--', N: '-.', O: '---', P: '.--.', Q: '--.-', R: '.-.', S: '...', T: '-', U: '..-', V: '...-', W: '.--', X: '-..-', Y: '-.--', Z: '--..', 0: '-----', 1: '.----', 2: '..---', 3: '...--', 4: '....-', 5: '.....', 6: '-....', 7: '--...', 8: '---..', 9: '----.' }; | |
| 3 | + var inp = S.input('Type a message', 'SOS HELLO', function () { stop(); }, 24), wpm = S.slider('Speed', 5, 25, 12, 1, function (v) { return v + ' words a minute'; }, function () { stop(); }); | |
| 4 | + var t0 = -1, osc = []; function stop() { t0 = -1; osc.forEach(function (o) { try { o.stop(); } catch (e) { } }); osc = []; } | |
| 5 | + function plan() { var u = 1.2 / wpm.v, t = 0, out = [], chars = inp.v.toUpperCase().split(''); chars.forEach(function (ch, ci) { if (ch === ' ') { t += 4 * u; return; } var code = M[ch]; if (!code) return; code.split('').forEach(function (s, si) { var d = (s === '.' ? 1 : 3) * u; out.push({ ci: ci, si: si, t: t, d: d }); t += d + u; }); t += 2 * u; }); return { ev: out, end: t }; } | |
| 6 | + S.button('Play', function () { stop(); var p = plan(); p.ev.forEach(function (e) { var o = S.tone(620, e.d, 'sine', .14, e.t + .05); if (o) osc.push(o); }); t0 = S.t + .05; }); | |
| 7 | + S.button('Stop', stop); | |
| 8 | + S.loop(function () { | |
| 9 | + var w = S.W, h = S.H, sm = S.small(), chars = inp.v.toUpperCase().split(''), p = plan(), now = t0 < 0 ? -1 : S.t - t0; if (now > p.end) { t0 = -1; now = -1; } | |
| 10 | + S.clear(); var pad = sm ? 10 : 24, tot = 0; chars.forEach(function (ch) { var cd = M[ch]; if (ch === ' ') tot += 4; else if (cd) { cd.split('').forEach(function (s) { tot += s === '.' ? 2 : 4; }); tot += 1.4; } }); var U = Math.max(sm ? 5 : 7, Math.min(sm ? 12 : 22, (w - 2 * pad) * (sm ? 3.2 : 1.6) / Math.max(tot, 1))), x = pad, lh = U * 7.5, y = Math.max(46, h * .2), active = {}; | |
| 11 | + p.ev.forEach(function (e) { if (now >= e.t && now < e.t + e.d) active[e.ci + '_' + e.si] = 1; }); | |
| 12 | + chars.forEach(function (ch, ci) { var code = M[ch]; if (ch === ' ') { x += U * 4; return; } if (!code) return; var cw = 0; code.split('').forEach(function (s) { cw += (s === '.' ? 1 : 3) * U + U; }); cw -= U; var bw = Math.max(cw, U * 2.4); if (x + bw > w - pad) { x = pad; y += lh; } | |
| 13 | + var lit = false, cx = x; code.split('').forEach(function (s, si) { var on = active[ci + '_' + si], ww = (s === '.' ? 1 : 3) * U; if (on) lit = true; S.rr(cx, y + U * 2.2, ww, U, U / 2, on ? C.ink : C.acc); cx += ww + U; }); | |
| 14 | + S.txt(ch, x + cw / 2, y, lit ? C.ink : C.mut, U * 2.2, 'center', 700); x += bw + U * 2.4; }); | |
| 15 | + if (!chars.some(function (c) { return M[c]; })) S.txt('Type letters or numbers below.', w / 2, h / 2, C.mut, 14, 'center'); | |
| 16 | + if (now >= 0) { var any = Object.keys(active).length > 0; S.dot(w - 70, 22, 9, any ? C.yellow : '#2a2f38'); if (any) S.ring(w - 70, 22, 14, 'rgba(240,210,100,.4)', 2); } | |
| 17 | + S.say('Morse code spells every letter with short and long signals, called dots and dashes. A dash lasts as long as three dots. Common letters get short codes: <b>E is a single dot</b>, T is a single dash. Press Play to hear your message.'); | |
| 18 | + }); | |
| 19 | + }); |
exp/movement.js added
| 1 | + WE.mount('movement', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, power = .7, phase = 0, beats = 0, esc = 0, escTarget = 0, lastSign = 1, part = -1; | |
| 3 | + var rate = S.select('Beat rate', [['18000', '18,000'], ['21600', '21,600'], ['28800', '28,800'], ['36000', '36,000']], '28800'); | |
| 4 | + var slow = S.slider('Slow motion', 0, 100, 55, 1, function (v) { var f = Math.pow(10, -v / 50); return f > .95 ? 'Real time' : '1/' + Math.round(1 / f) + ' speed'; }); | |
| 5 | + S.button('Wind the crown', function () { power = Math.min(1, power + .22); }); | |
| 6 | + var snd = S.toggle('Tick sound', false); | |
| 7 | + var NAMES = [['Mainspring barrel', 'A coiled spring stores the energy. As it unwinds it turns the barrel and drives everything else.'], ['Gear train', 'Three wheels step the slow, strong turn of the barrel up into a fast, light one.'], ['Escape wheel', 'It always tries to spin. The fork lets it advance only one tooth at a time. That is the tick.'], ['Pallet fork', 'It rocks side to side, locking the escape wheel and passing a small push to the balance.'], ['Balance wheel', 'It swings back and forth at a steady beat, like a tiny pendulum. Its rhythm sets the time.']]; | |
| 8 | + function gear(x, y, r, n, ang, col, hl) { | |
| 9 | + ctx.beginPath(); | |
| 10 | + for (var i = 0; i < n * 2; i++) { var a = ang + Math.PI * i / n, rr = i % 2 ? r * .9 : r; ctx.lineTo(x + rr * Math.cos(a - .5 * Math.PI / n * .5), y + rr * Math.sin(a - .5 * Math.PI / n * .5)); ctx.lineTo(x + rr * Math.cos(a + .5 * Math.PI / n * .5), y + rr * Math.sin(a + .5 * Math.PI / n * .5)); } | |
| 11 | + ctx.closePath(); ctx.fillStyle = hl ? 'rgba(213,163,90,.28)' : 'rgba(255,255,255,.06)'; ctx.fill(); ctx.strokeStyle = hl ? C.acc : col; ctx.lineWidth = 1.5; ctx.stroke(); | |
| 12 | + for (var k = 0; k < 5; k++) { var b = ang + k * S.TAU / 5; S.ln(x + r * .18 * Math.cos(b), y + r * .18 * Math.sin(b), x + r * .78 * Math.cos(b), y + r * .78 * Math.sin(b), hl ? C.acc : col, 1.5); } | |
| 13 | + S.ring(x, y, r * .78, hl ? C.acc : col, 1.5); S.dot(x, y, r * .1, C.acc); | |
| 14 | + } | |
| 15 | + var L = {}; | |
| 16 | + function layout() { | |
| 17 | + var w = S.W, h = S.H, u = Math.min(w / 8.4, h / 4.4), cy = h * .56, x0 = (w - u * 7.4) / 2; | |
| 18 | + L = { u: u, bar: [x0 + u * 1.1, cy, u * 1.1], g1: [x0 + u * 2.75, cy - u * .25, u * .7], g2: [x0 + u * 3.9, cy + u * .35, u * .58], g3: [x0 + u * 4.9, cy - u * .2, u * .5], esc: [x0 + u * 5.85, cy + u * .35, u * .48], fork: [x0 + u * 6.25, cy - u * .55], bal: [x0 + u * 6.55, cy - u * 1.45, u * .78] }; | |
| 19 | + } | |
| 20 | + S.onresize = layout; layout(); | |
| 21 | + S.pointer({ scroll: true, move: function (x, y) { part = hit(x, y); }, down: function (x, y) { part = hit(x, y); } }); | |
| 22 | + function hit(x, y) { var d = function (p) { return Math.hypot(x - p[0], y - p[1]); }; if (d(L.bal) < L.bal[2]) return 4; if (d(L.fork) < L.u * .35) return 3; if (d(L.esc) < L.esc[2]) return 2; if (d(L.bar) < L.bar[2]) return 0; if (d(L.g1) < L.g1[2] || d(L.g2) < L.g2[2] || d(L.g3) < L.g3[2]) return 1; return -1; } | |
| 23 | + S.loop(function (dt) { | |
| 24 | + var f = +rate.v / 7200, sp = Math.pow(10, -slow.v / 50), run = power > 0; | |
| 25 | + if (run) { phase += dt * sp * f * S.TAU; power = Math.max(0, power - dt * sp * .012 - dt * .0006); } | |
| 26 | + var s = Math.sin(phase), sign = s >= 0 ? 1 : -1; | |
| 27 | + if (sign !== lastSign) { lastSign = sign; beats++; escTarget += S.TAU / 30; if (snd.v && sp > .02) S.tone(sign > 0 ? 2600 : 2100, .03, 'square', .05); } | |
| 28 | + esc += (escTarget - esc) * Math.min(1, dt * sp * f * 40 + .08); | |
| 29 | + S.clear(); | |
| 30 | + var u = L.u, b = L.bar; | |
| 31 | + // barrel + spring | |
| 32 | + S.ring(b[0], b[1], b[2], part === 0 ? C.acc : C.mut, 2); ctx.beginPath(); | |
| 33 | + var turns = 3 + power * 7; for (var i = 0; i <= 220; i++) { var t = i / 220, a = t * turns * S.TAU - esc / 600, r = b[2] * (.12 + (.8 - power * .35) * t); ctx.lineTo(b[0] + r * Math.cos(a), b[1] + r * Math.sin(a)); } | |
| 34 | + ctx.strokeStyle = C.acc; ctx.lineWidth = 1.6; ctx.stroke(); | |
| 35 | + gear(L.g1[0], L.g1[1], L.g1[2], 26, esc / 100, C.mut, part === 1); gear(L.g2[0], L.g2[1], L.g2[2], 22, -esc / 12, C.mut, part === 1); gear(L.g3[0], L.g3[1], L.g3[2], 18, esc / 2.5, C.mut, part === 1); | |
| 36 | + // escape wheel (15 club teeth) | |
| 37 | + var e = L.esc; ctx.beginPath(); for (var k = 0; k < 15; k++) { var a0 = -esc + k * S.TAU / 15; ctx.lineTo(e[0] + e[2] * .62 * Math.cos(a0 - .12), e[1] + e[2] * .62 * Math.sin(a0 - .12)); ctx.lineTo(e[0] + e[2] * Math.cos(a0 + .16), e[1] + e[2] * Math.sin(a0 + .16)); ctx.lineTo(e[0] + e[2] * .62 * Math.cos(a0 + .22), e[1] + e[2] * .62 * Math.sin(a0 + .22)); } | |
| 38 | + ctx.closePath(); ctx.fillStyle = part === 2 ? 'rgba(213,163,90,.28)' : 'rgba(255,255,255,.06)'; ctx.fill(); ctx.strokeStyle = part === 2 ? C.acc : C.blue; ctx.lineWidth = 1.5; ctx.stroke(); S.dot(e[0], e[1], 4, C.acc); | |
| 39 | + // pallet fork | |
| 40 | + var fk = L.fork, tilt = Math.max(-1, Math.min(1, s * 6)) * .16, col = part === 3 ? C.acc : C.red; | |
| 41 | + ctx.save(); ctx.translate(fk[0], fk[1]); ctx.rotate(tilt); ctx.strokeStyle = col; ctx.lineWidth = 3; ctx.lineCap = 'round'; ctx.beginPath(); ctx.moveTo(-u * .42, u * .34); ctx.lineTo(0, 0); ctx.lineTo(u * .42, u * .34); ctx.moveTo(0, 0); ctx.lineTo(0, -u * .5); ctx.stroke(); S.dot(-u * .42, u * .34, 4, C.pink); S.dot(u * .42, u * .34, 4, C.pink); ctx.restore(); S.dot(fk[0], fk[1], 4, col); | |
| 42 | + // balance | |
| 43 | + var bl = L.bal, ang = s * 2.4 * (run ? 1 : 0) + (run ? 0 : 0); ctx.save(); ctx.translate(bl[0], bl[1]); ctx.rotate(ang); | |
| 44 | + ctx.strokeStyle = part === 4 ? C.acc : C.ink; ctx.lineWidth = 4; ctx.beginPath(); ctx.arc(0, 0, bl[2], 0, S.TAU); ctx.stroke(); ctx.lineWidth = 2.5; ctx.beginPath(); ctx.moveTo(-bl[2], 0); ctx.lineTo(bl[2], 0); ctx.moveTo(0, -bl[2]); ctx.lineTo(0, bl[2]); ctx.stroke(); S.dot(0, bl[2] * .32, 3.5, C.pink); ctx.restore(); | |
| 45 | + ctx.beginPath(); for (var j = 0; j <= 160; j++) { var tt = j / 160, aa = tt * 5 * S.TAU + ang * tt, rr = bl[2] * (.08 + .5 * tt * (1 + s * .08)); ctx.lineTo(bl[0] + rr * Math.cos(aa), bl[1] + rr * Math.sin(aa)); } ctx.strokeStyle = C.acc; ctx.lineWidth = 1.1; ctx.stroke(); | |
| 46 | + // labels + meters | |
| 47 | + var fs = S.small() ? 11 : 13; S.txt('Mainspring', b[0], b[1] + b[2] + 16, C.mut, fs, 'center'); S.txt('Gear train', L.g2[0], L.g2[1] + L.g2[2] + 16, C.mut, fs, 'center'); S.txt('Escape wheel', e[0], e[1] + e[2] + 16, C.mut, fs, 'center'); S.txt('Balance', bl[0], bl[1] - bl[2] - 14, C.mut, fs, 'center'); | |
| 48 | + var bw = Math.min(220, S.W * .4); S.txt('Power reserve', 16, 22, C.mut, 12); S.rr(16, 32, bw, 8, 4, C.grid); S.rr(16, 32, bw * power, 8, 4, power > .15 ? C.acc : C.red); | |
| 49 | + S.txt(beats.toLocaleString() + ' beats', S.W - 54, 22, C.mut, 12, 'right'); | |
| 50 | + if (part >= 0) S.say('<b>' + NAMES[part][0] + '</b> ' + NAMES[part][1]); | |
| 51 | + else S.say(run ? 'Running at <b>' + (+rate.v).toLocaleString() + ' beats an hour</b>, which is ' + (f * 2) + ' ticks every second. Point at any part to see what it does.' : '<b>Out of power.</b> The mainspring has run down. Wind the crown to start it again.'); | |
| 52 | + }); | |
| 53 | + }); |
exp/orbits.js added
| 1 | + WE.mount('orbits', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, GM = 398600, RE = 6371, R0 = RE + 800, shots = [], msg = 'Pick a speed and fire. Too slow and it falls. Fast enough and it never comes down.'; | |
| 3 | + var v = S.slider('Launch speed', 0, 11.5, 7.9, .1, function (x) { return x.toFixed(1) + ' km/s'; }); | |
| 4 | + S.button('Fire', function () { shots.push({ x: 0, y: R0, vx: v.v, vy: 0, tr: [], done: false, v: v.v, t: 0, ang: 0 }); if (shots.length > 6) shots.shift(); }); | |
| 5 | + shots.push({ x: 0, y: R0, vx: 7.9, vy: 0, tr: [], done: false, v: 7.9, t: 0, ang: 0 }); | |
| 6 | + S.button('Clear', function () { shots = []; }); | |
| 7 | + S.loop(function (dt) { | |
| 8 | + S.clear(); var w = S.W, h = S.H, sc = Math.min(w, h) / (RE * 5.2), cx = w / 2, cy = h * .56; | |
| 9 | + shots.forEach(function (s) { | |
| 10 | + if (s.done) return; | |
| 11 | + for (var i = 0; i < 60; i++) { var r = Math.hypot(s.x, s.y), a = -GM / (r * r * r), st = 4; s.vx += a * s.x * st; s.vy += a * s.y * st; s.x += s.vx * st; s.y += s.vy * st; s.t += st; if (i % 6 === 0) s.tr.push([s.x, s.y]); | |
| 12 | + var r2 = Math.hypot(s.x, s.y), an = Math.atan2(s.x, s.y); if (an < 0) an += S.TAU; if (an < s.ang - 3) { s.done = true; var sa = 1 / (2 / R0 - s.v * s.v / GM), T = S.TAU * Math.sqrt(sa * sa * sa / GM) / 60; msg = '<b>Orbit.</b> At ' + s.v.toFixed(1) + ' km/s it keeps missing the ground. One lap takes ' + (T < 180 ? T.toFixed(0) + ' minutes' : (T / 60).toFixed(1) + ' hours') + '.'; break; } s.ang = an; | |
| 13 | + if (r2 < RE) { s.done = true; msg = '<b>It fell back</b> after ' + Math.round(an * RE).toLocaleString() + ' km along the ground. Try a little faster.'; break; } | |
| 14 | + if (r2 > RE * 9) { s.done = true; msg = s.v * s.v / 2 - GM / R0 >= 0 ? '<b>Escape.</b> At ' + s.v.toFixed(1) + ' km/s it leaves the Earth for good.' : '<b>A long, stretched orbit.</b> It swings far out before the Earth pulls it back.'; break; } } | |
| 15 | + if (s.tr.length > 4000) s.tr.splice(0, 500); | |
| 16 | + }); | |
| 17 | + var g = ctx.createRadialGradient(cx - RE * sc * .3, cy - RE * sc * .3, RE * sc * .2, cx, cy, RE * sc); g.addColorStop(0, '#3f86c4'); g.addColorStop(1, '#14324f'); ctx.fillStyle = g; ctx.beginPath(); ctx.arc(cx, cy, RE * sc, 0, S.TAU); ctx.fill(); S.ring(cx, cy, RE * sc + 3, 'rgba(111,177,230,.3)', 4); | |
| 18 | + ctx.fillStyle = C.mut; ctx.beginPath(); ctx.moveTo(cx - 7, cy - RE * sc + 1); ctx.lineTo(cx, cy - R0 * sc); ctx.lineTo(cx + 7, cy - RE * sc + 1); ctx.fill(); | |
| 19 | + var vc = Math.sqrt(GM / R0); S.arrow(cx, cy - R0 * sc, cx + 14 + v.v * 7, cy - R0 * sc, C.acc, 2); | |
| 20 | + shots.forEach(function (s, i) { ctx.beginPath(); s.tr.forEach(function (p) { ctx.lineTo(cx + p[0] * sc, cy - p[1] * sc); }); ctx.strokeStyle = [C.acc, C.blue, C.green, C.pink, C.violet, C.teal][i % 6]; ctx.lineWidth = 1.6; ctx.stroke(); if (!s.done) S.dot(cx + s.x * sc, cy - s.y * sc, 4, C.ink); }); | |
| 21 | + S.txt('Circular orbit here needs ' + vc.toFixed(1) + ' km/s. Escape needs ' + (vc * Math.SQRT2).toFixed(1) + ' km/s.', 14, 20, C.mut, 12.5); | |
| 22 | + S.say(msg); | |
| 23 | + }); | |
| 24 | + }); |
exp/pathfinding.js added
| 1 | + WE.mount('pathfinding', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, cols = 0, rws = 0, cs = 20, wall, st, gl, order = [], path = [], shown = 0, drag = null, paint = 1, ox = 0, oy = 0; | |
| 3 | + var algo = S.select('Method', [['bfs', 'Search everywhere'], ['astar', 'Aim for the goal']], 'bfs', solve); | |
| 4 | + S.button('Random walls', function () { for (var i = 0; i < wall.length; i++) wall[i] = Math.random() < .28 && i !== st && i !== gl ? 1 : 0; solve(); }); | |
| 5 | + S.button('Clear walls', function () { wall.fill(0); solve(); }); S.button('Search again', function () { shown = 0; }); | |
| 6 | + function init() { var w = S.W, h = S.H; cs = S.small() ? Math.floor(w / 18) : Math.floor(w / 44); var c = Math.floor(w / cs), r = Math.floor(h / cs); if (c === cols && r === rws) return; cols = c; rws = r; ox = (w - c * cs) / 2; oy = (h - r * cs) / 2; wall = new Uint8Array(c * r); var my = Math.floor(r / 2); st = my * c + Math.floor(c * .15); gl = my * c + Math.floor(c * .85); var wx = Math.floor(c / 2); for (var y = 2; y < r - 2; y++) wall[y * c + wx] = 1; solve(); } | |
| 7 | + function solve() { | |
| 8 | + order = []; path = []; shown = 0; var n = cols * rws, prev = new Int32Array(n).fill(-1), g = new Float32Array(n).fill(1e9), seen = new Uint8Array(n), open = [st], gx = gl % cols, gy = Math.floor(gl / cols), A = algo.v === 'astar'; | |
| 9 | + function hh(i) { return Math.abs(i % cols - gx) + Math.abs(Math.floor(i / cols) - gy); } | |
| 10 | + g[st] = 0; seen[st] = 1; var head = 0, found = false; | |
| 11 | + while (A ? open.length : head < open.length) { | |
| 12 | + var cur; if (A) { var bi = 0, bf = 1e9, bh = 1e9; for (var k = 0; k < open.length; k++) { var f = g[open[k]] + hh(open[k]), q = hh(open[k]); if (f < bf || (f === bf && q < bh)) { bf = f; bh = q; bi = k; } } cur = open.splice(bi, 1)[0]; if (seen[cur] === 2) continue; seen[cur] = 2; } else cur = open[head++]; | |
| 13 | + order.push(cur); if (cur === gl) { found = true; break; } | |
| 14 | + var x = cur % cols, y = Math.floor(cur / cols), nb = []; if (x > 0) nb.push(cur - 1); if (x < cols - 1) nb.push(cur + 1); if (y > 0) nb.push(cur - cols); if (y < rws - 1) nb.push(cur + cols); | |
| 15 | + nb.forEach(function (m) { if (wall[m]) return; if (A) { if (g[cur] + 1 < g[m]) { g[m] = g[cur] + 1; prev[m] = cur; open.push(m); } } else if (!seen[m]) { seen[m] = 1; prev[m] = cur; open.push(m); } }); | |
| 16 | + } | |
| 17 | + if (found) for (var p = gl; p !== -1; p = prev[p]) path.unshift(p); | |
| 18 | + } | |
| 19 | + function at(x, y) { var c = Math.floor((x - ox) / cs), r = Math.floor((y - oy) / cs); return c >= 0 && c < cols && r >= 0 && r < rws ? r * cols + c : -1; } | |
| 20 | + S.pointer({ cursor: 'crosshair', down: function (x, y) { var i = at(x, y); if (i < 0) return; if (i === st) drag = 's'; else if (i === gl) drag = 'g'; else { drag = 'w'; paint = wall[i] ? 0 : 1; wall[i] = paint; solve(); } }, | |
| 21 | + move: function (x, y, d) { if (!d || !drag) return; var i = at(x, y); if (i < 0) return; if (drag === 'w') { if (i !== st && i !== gl && wall[i] !== paint) { wall[i] = paint; solve(); } } else if (!wall[i] && i !== st && i !== gl) { if (drag === 's') st = i; else gl = i; solve(); } }, up: function () { drag = null; } }); | |
| 22 | + S.onresize = function () { cols = 0; init(); }; init(); | |
| 23 | + S.loop(function (dt) { | |
| 24 | + if (!cols) { init(); return; } if (!S.ptr.down) shown = Math.min(order.length + path.length, shown + dt * Math.max(60, order.length / 2.2)); else shown = order.length + path.length; | |
| 25 | + S.clear(); var i, n = Math.min(order.length, Math.floor(shown)); | |
| 26 | + for (i = 0; i < wall.length; i++) { var x = ox + (i % cols) * cs, y = oy + Math.floor(i / cols) * cs; ctx.fillStyle = wall[i] ? '#59606d' : '#141820'; ctx.fillRect(x + .5, y + .5, cs - 1, cs - 1); } | |
| 27 | + for (i = 0; i < n; i++) { var c = order[i]; ctx.fillStyle = i > n - 14 && n < order.length ? C.blue : 'rgba(111,177,230,.28)'; ctx.fillRect(ox + (c % cols) * cs + .5, oy + Math.floor(c / cols) * cs + .5, cs - 1, cs - 1); } | |
| 28 | + var pn = Math.max(0, Math.floor(shown) - order.length); if (pn > 0 && path.length) { ctx.beginPath(); for (i = 0; i < Math.min(pn + 1, path.length); i++) ctx.lineTo(ox + (path[i] % cols + .5) * cs, oy + (Math.floor(path[i] / cols) + .5) * cs); ctx.strokeStyle = C.acc; ctx.lineWidth = Math.max(3, cs * .3); ctx.lineJoin = 'round'; ctx.lineCap = 'round'; ctx.stroke(); } | |
| 29 | + [[st, C.green, 'A'], [gl, C.red, 'B']].forEach(function (q) { var x = ox + (q[0] % cols + .5) * cs, y = oy + (Math.floor(q[0] / cols) + .5) * cs; S.dot(x, y, cs * .46, q[1]); S.txt(q[2], x, y + 1, '#111', Math.max(10, cs * .5), 'center', 700); }); | |
| 30 | + S.rr(8, 8, 250, 28, 14, 'rgba(13,15,19,.85)'); S.txt(n + ' squares checked' + (shown >= order.length ? (path.length ? ' · route: ' + (path.length - 1) + ' steps' : ' · no way through') : ''), 20, 22, C.ink, 12.5, 'left', 600); | |
| 31 | + S.say((algo.v === 'bfs' ? '<b>Search everywhere</b> spreads out evenly from A, one step at a time, like water. It always finds the shortest route, but it checks a lot of squares.' : '<b>Aim for the goal</b> checks the squares that look closest to B first. It finds a route just as short, usually after checking far fewer squares. Map apps work this way.') + ' <b>Draw walls</b> on the grid, or drag A and B.'); | |
| 32 | + }); | |
| 33 | + }); |
exp/pendulum.js added
| 1 | + WE.mount('pendulum', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, th = .6, om = 0, grab = false, tr = [], lastCross = null, period = 0, clock = 0; | |
| 3 | + var len = S.slider('Length', .2, 3, 1, .05, function (v) { return v.toFixed(2) + ' m'; }), grav = S.select('Gravity', [['1.62', 'Moon'], ['3.71', 'Mars'], ['9.81', 'Earth'], ['24.79', 'Jupiter']], '9.81'); | |
| 4 | + var G = function () { return { px: S.W * (S.small() ? .5 : .36), py: S.H * .1, sc: S.H * .78 / 3 }; }; | |
| 5 | + S.pointer({ down: function (x, y) { grab = true; set(x, y); }, move: function (x, y, d) { if (d && grab) set(x, y); }, up: function () { grab = false; om = 0; lastCross = null; period = 0; } }); | |
| 6 | + function set(x, y) { var g = G(); th = Math.max(-1.5, Math.min(1.5, Math.atan2(x - g.px, Math.max(5, y - g.py)))); om = 0; } | |
| 7 | + S.loop(function (dt) { | |
| 8 | + var g = +grav.v, L = len.v; | |
| 9 | + if (!grab) for (var i = 0; i < 8; i++) { var h = dt / 8, prev = th; om += -g / L * Math.sin(th) * h; th += om * h; clock += h; if (prev < 0 && th >= 0) { if (lastCross !== null) period = clock - lastCross; lastCross = clock; } } | |
| 10 | + tr.push(th); if (tr.length > 300) tr.shift(); | |
| 11 | + S.clear(); var q = G(), bx = q.px + Math.sin(th) * L * q.sc, by = q.py + Math.cos(th) * L * q.sc; | |
| 12 | + S.ln(q.px - 50, q.py, q.px + 50, q.py, C.mut, 3); ctx.setLineDash([4, 5]); S.ln(q.px, q.py, q.px, q.py + L * q.sc + 20, 'rgba(255,255,255,.2)', 1); ctx.setLineDash([]); | |
| 13 | + S.ln(q.px, q.py, bx, by, C.ink, 2); S.dot(bx, by, 16, C.acc); S.ring(bx, by, 21, grab ? C.ink : 'rgba(213,163,90,.4)', 1.5); | |
| 14 | + var T = S.TAU * Math.sqrt(L / g); | |
| 15 | + if (!S.small()) { var gx = S.W * .62, gw = S.W * .33, gy = S.H * .62; S.ln(gx, gy, gx + gw, gy, C.grid, 1); ctx.beginPath(); tr.forEach(function (v, i) { ctx.lineTo(gx + gw * i / 300, gy - v * 60); }); ctx.strokeStyle = C.blue; ctx.lineWidth = 2; ctx.stroke(); S.txt('Swing over time', gx, gy - 110, C.mut, 12.5); } | |
| 16 | + var tx = S.small() ? 14 : S.W * .62; S.txt(T.toFixed(2) + ' s', tx, S.H * .16, C.ink, S.small() ? 26 : 40, 'left', 700); S.txt('for one full swing', tx, S.H * .16 + (S.small() ? 24 : 34), C.mut, 13); | |
| 17 | + if (period) S.txt('Measured: ' + period.toFixed(2) + ' s', tx, S.H * .16 + (S.small() ? 44 : 58), C.green, 13, 'left', 600); | |
| 18 | + S.say('Drag the weight and let go. The time for one swing depends only on the <b>length</b> and the <b>gravity</b>, not on how heavy the weight is. Four times the length gives twice the time.'); | |
| 19 | + }); | |
| 20 | + }); |
exp/projectile.js added
| 1 | + WE.mount('projectile', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, shots = [], last = null; | |
| 3 | + var ang = S.slider('Angle', 5, 85, 45, 1, function (v) { return v + '°'; }), spd = S.slider('Speed', 5, 50, 30, 1, function (v) { return v + ' m/s'; }), air = S.toggle('Air', false), grav = S.select('World', [['1.62', 'Moon'], ['3.71', 'Mars'], ['9.81', 'Earth']], '9.81'); | |
| 4 | + S.button('Launch', function () { var a = ang.v * Math.PI / 180; shots.push({ x: 0, y: 0, vx: spd.v * Math.cos(a), vy: spd.v * Math.sin(a), g: +grav.v, k: air.v ? .012 : 0, tr: [[0, 0]], top: 0, t: 0, done: false, lab: ang.v + '°' }); if (shots.length > 7) shots.shift(); }); | |
| 5 | + shots.push({ x: 0, y: 0, vx: 30 * Math.cos(1.05), vy: 30 * Math.sin(1.05), g: 9.81, k: 0, tr: [[0, 0]], top: 0, t: 0, done: false, lab: '60°' }); | |
| 6 | + S.button('Clear', function () { shots = []; last = null; }); | |
| 7 | + S.loop(function (dt) { | |
| 8 | + S.clear(); var w = S.W, h = S.H, gy = h * .86, x0 = 30, maxR = Math.max(60, 50 * 50 / (+grav.v) * 1.05), sc = (w - 60) / maxR; if (+grav.v < 9) sc = (w - 60) / Math.max(260, spd.v * spd.v / (+grav.v) * 1.05); | |
| 9 | + shots.forEach(function (s) { if (s.done) return; for (var i = 0; i < 6; i++) { var st = dt * 2.2 / 6, sp = Math.hypot(s.vx, s.vy); s.vx -= s.k * sp * s.vx * st; s.vy -= (s.g + s.k * sp * s.vy) * st; s.x += s.vx * st; s.y += s.vy * st; s.t += st; s.top = Math.max(s.top, s.y); if (s.y <= 0 && s.t > 0.05) { s.y = 0; s.done = true; last = s; break; } } s.tr.push([s.x, s.y]); }); | |
| 10 | + S.ln(0, gy, w, gy, C.dim, 2); for (var m = 0; m * sc < w; m += (sc > 2 ? 50 : sc > .5 ? 100 : 500)) { S.ln(x0 + m * sc, gy, x0 + m * sc, gy + 6, C.dim, 1); S.txt(m + ' m', x0 + m * sc, gy + 18, C.mut, 11, 'center'); } | |
| 11 | + var a = ang.v * Math.PI / 180; ctx.save(); ctx.translate(x0, gy); ctx.rotate(-a); S.rr(0, -6, 38, 12, 3, C.mut); ctx.restore(); S.dot(x0, gy, 9, C.dim); | |
| 12 | + shots.forEach(function (s, i) { ctx.beginPath(); s.tr.forEach(function (p) { ctx.lineTo(x0 + p[0] * sc, gy - p[1] * sc); }); ctx.strokeStyle = [C.acc, C.blue, C.green, C.pink, C.violet, C.teal, C.yellow][i % 7]; ctx.lineWidth = 2; ctx.stroke(); var p = s.tr[s.tr.length - 1]; S.dot(x0 + p[0] * sc, gy - p[1] * sc, 5, C.ink); if (s.done) S.txt(s.lab, x0 + p[0] * sc, gy - 12, C.mut, 11, 'center'); }); | |
| 13 | + S.say(last ? 'Landed <b>' + last.x.toFixed(0) + ' m</b> away after ' + last.t.toFixed(1) + ' seconds, reaching ' + last.top.toFixed(0) + ' m high. ' + (last.k ? 'With air, the path is no longer a clean arch and the best angle drops below 45°.' : 'With no air, 45° always goes farthest, and angles the same distance either side of 45° land in the same place.') : 'Set an angle and a speed, then launch. Leave the old paths on screen to compare.'); | |
| 14 | + }); | |
| 15 | + }); |
exp/pythagoras.js added
| 1 | + WE.mount('pythagoras', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, mix = 0; | |
| 3 | + var view = S.select('Show', [['sq', 'Squares on the sides'], ['proof', 'Proof by sliding']], 'sq'); | |
| 4 | + var a = S.slider('Side a', 1, 8, 3, .5), b = S.slider('Side b', 1, 8, 4, .5), sl = S.toggle('Slide the triangles', false); | |
| 5 | + function poly(p, fill, stroke) { ctx.beginPath(); p.forEach(function (q) { ctx.lineTo(q[0], q[1]); }); ctx.closePath(); if (fill) { ctx.fillStyle = fill; ctx.fill(); } if (stroke) { ctx.strokeStyle = stroke; ctx.lineWidth = 2; ctx.stroke(); } } | |
| 6 | + function f(v) { return (Math.round(v * 100) / 100).toString(); } | |
| 7 | + S.loop(function (dt) { | |
| 8 | + var w = S.W, h = S.H, sm = S.small(), A = a.v, B = b.v, c = Math.sqrt(A * A + B * B); S.clear(); sl.el.hidden = view.v !== 'proof'; | |
| 9 | + mix += ((sl.v ? 1 : 0) - mix) * Math.min(1, dt * 3.5); | |
| 10 | + if (view.v === 'sq') { | |
| 11 | + var ext = [A + B + B, A + B + A], u = Math.min((w * (sm ? .92 : .6)) / (A + B + B + .5), (h * .92) / (A + B + A + .5)), ox = (sm ? w * .5 : w * .36) - (A + 2 * B) * u / 2 + B * u, oy = h * .5 + (2 * A + B) * u / 2 - A * u; | |
| 12 | + // triangle: right angle at (ox,oy); a goes right, b goes up | |
| 13 | + var P = [ox, oy], Q = [ox + A * u, oy], R = [ox, oy - B * u]; | |
| 14 | + poly([P, Q, [Q[0], Q[1] + A * u], [P[0], P[1] + A * u]], 'rgba(111,177,230,.3)', C.blue); poly([P, R, [R[0] - B * u, R[1]], [P[0] - B * u, P[1]]], 'rgba(126,203,147,.3)', C.green); | |
| 15 | + var nx = B * u, ny = A * u; poly([Q, R, [R[0] + nx, R[1] - ny], [Q[0] + nx, Q[1] - ny]], 'rgba(213,163,90,.3)', C.acc); | |
| 16 | + poly([P, Q, R], '#2a303b', C.ink); | |
| 17 | + S.txt('a² = ' + f(A * A), ox + A * u / 2, oy + A * u / 2, C.blue, sm ? 13 : 16, 'center', 700); S.txt('b² = ' + f(B * B), ox - B * u / 2, oy - B * u / 2, C.green, sm ? 13 : 16, 'center', 700); S.txt('c² = ' + f(A * A + B * B), (Q[0] + R[0]) / 2 + nx / 2, (Q[1] + R[1]) / 2 - ny / 2, C.acc, sm ? 13 : 16, 'center', 700); | |
| 18 | + if (!sm) { var tx = w * .68; S.txt(f(A * A) + ' + ' + f(B * B) + ' = ' + f(A * A + B * B), tx, h * .3, C.ink, 26, 'left', 700); S.txt('a² + b² = c²', tx, h * .3 + 36, C.mut, 15); S.txt('Longest side c = ' + c.toFixed(3), tx, h * .3 + 76, C.acc, 16, 'left', 700); } | |
| 19 | + S.say('The two smaller squares together cover <b>exactly</b> the same area as the big one: ' + f(A * A) + ' + ' + f(B * B) + ' = ' + f(A * A + B * B) + '. So the longest side is ' + c.toFixed(3) + '. This works for every right triangle, and only for right triangles.'); | |
| 20 | + } else { | |
| 21 | + var s = A + B, U = Math.min(w * (sm ? .9 : .5), h * .9) / s, x0 = (sm ? w * .5 : w * .36) - s * U / 2, y0 = h * .5 - s * U / 2, e = mix * mix * (3 - 2 * mix); | |
| 22 | + var T1 = [[[0, 0], [A, 0], [0, B]], [[s, 0], [s, A], [A, 0]], [[s, s], [B, s], [s, A]], [[0, s], [0, B], [B, s]]], T2 = [[[A, A], [A, 0], [s, A]], [[s, 0], [s, A], [A, 0]], [[A, A], [0, A], [A, s]], [[0, s], [A, s], [0, A]]]; | |
| 23 | + function M(q) { return [x0 + q[0] * U, y0 + q[1] * U]; } | |
| 24 | + poly([[0, 0], [s, 0], [s, s], [0, s]].map(M), null, C.dim); | |
| 25 | + if (e < .5) poly([[A, 0], [s, A], [B, s], [0, B]].map(M), 'rgba(213,163,90,' + (.32 * (1 - e * 2)) + ')'); | |
| 26 | + else { var al = .32 * (e * 2 - 1); poly([[0, 0], [A, 0], [A, A], [0, A]].map(M), 'rgba(111,177,230,' + al + ')'); poly([[A, A], [s, A], [s, s], [A, s]].map(M), 'rgba(126,203,147,' + al + ')'); } | |
| 27 | + for (var i = 0; i < 4; i++) poly(T1[i].map(function (q, j) { var r = T2[i][j]; return M([q[0] + (r[0] - q[0]) * e, q[1] + (r[1] - q[1]) * e]); }), '#2a303b', C.ink); | |
| 28 | + if (e < .3) S.txt('c² = ' + f(A * A + B * B), x0 + s * U / 2, y0 + s * U / 2, C.acc, sm ? 14 : 18, 'center', 700); | |
| 29 | + if (e > .7) { S.txt('a² = ' + f(A * A), x0 + A * U / 2, y0 + A * U / 2, C.blue, sm ? 13 : 16, 'center', 700); S.txt('b² = ' + f(B * B), x0 + (A + B / 2) * U, y0 + (A + B / 2) * U, C.green, sm ? 13 : 16, 'center', 700); } | |
| 30 | + if (!sm) { S.txt('Same box. Same four triangles.', w * .66, h * .4, C.ink, 18, 'left', 700); S.txt('So the space left over must be the same too.', w * .66, h * .4 + 28, C.mut, 14); } | |
| 31 | + S.say(sl.v ? 'The four triangles have only moved. They now leave two holes: a square on side a and a square on side b. The leftover space cannot have changed, so <b>a² + b² = c²</b>.' : 'Four copies of the triangle sit in a box, leaving one tilted square whose side is the longest side, c. Now press <b>Slide the triangles</b>.'); | |
| 32 | + } | |
| 33 | + }); | |
| 34 | + }); |
exp/quartz.js added
| 1 | + WE.mount('quartz', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx; | |
| 3 | + var stage = S.slider('Divide by two, this many times', 0, 15, 0, 1, function (v) { return v + (v === 1 ? ' time' : ' times'); }); | |
| 4 | + S.button('Hear this stage', function () { var f = 32768 / Math.pow(2, stage.v); if (f <= 4096) S.tone(f, .9, 'square', .04); }); | |
| 5 | + function dial(x, y, r, ang, title, sub) { | |
| 6 | + S.dot(x, y, r, '#151920'); S.ring(x, y, r, C.dim, 2); | |
| 7 | + for (var i = 0; i < 60; i++) { var a = i * S.TAU / 60, b = i % 5 === 0; S.ln(x + r * (b ? .82 : .9) * Math.sin(a), y - r * (b ? .82 : .9) * Math.cos(a), x + r * .95 * Math.sin(a), y - r * .95 * Math.cos(a), b ? C.ink : C.dim, b ? 2 : 1); } | |
| 8 | + S.ln(x - r * .15 * Math.sin(ang), y + r * .15 * Math.cos(ang), x + r * .86 * Math.sin(ang), y - r * .86 * Math.cos(ang), C.acc, 2.5); S.dot(x, y, 4, C.acc); | |
| 9 | + S.txt(title, x, y + r + 18, C.ink, 14, 'center', 650); S.txt(sub, x, y + r + 36, C.mut, 12.5, 'center'); | |
| 10 | + } | |
| 11 | + S.loop(function (dt, t) { | |
| 12 | + S.clear(); var w = S.W, h = S.H, r = Math.min(w * .14, h * .15), y = h * .2; | |
| 13 | + dial(w * .27, y, r, Math.floor(t * 8) / 8 * S.TAU / 60, 'Mechanical', '8 small steps a second'); | |
| 14 | + dial(w * .73, y, r, Math.floor(t) * S.TAU / 60, 'Quartz', '1 step a second'); | |
| 15 | + // divider chain | |
| 16 | + var n = stage.v, f = 32768 / Math.pow(2, n), x0 = w * .06, x1 = w * .94, by = h * .72, bw = (x1 - x0) / 16; | |
| 17 | + for (var i = 0; i <= 15; i++) { var on = i <= n, hh = h * .13 * (1 - i / 22); S.rr(x0 + i * bw + 2, by - hh, bw - 4, hh, 4, i === n ? C.acc : on ? 'rgba(213,163,90,.35)' : C.grid); if (!S.small() || i % 3 === 0 || i === 15) S.txt(i === 0 ? '32,768' : i === 15 ? '1' : String(32768 / Math.pow(2, i)), x0 + i * bw + bw / 2, by + 13, i === n ? C.ink : C.mut, S.small() ? 9 : 10.5, 'center'); } | |
| 18 | + S.txt('Each box is a tiny circuit that halves the beat', x0, by - h * .13 - 12, C.mut, 12.5); | |
| 19 | + // waveform for this stage (drawn slowed so you can see it) | |
| 20 | + var wy = h * .9, amp = h * .045, vis = Math.max(.6, 12 / Math.pow(1.45, n)); ctx.beginPath(); | |
| 21 | + for (var x = x0; x <= x1; x += 2) { var ph = ((x - x0) / (x1 - x0) * vis * 6 - t * vis * 1.2) % 1; if (ph < 0) ph += 1; ctx.lineTo(x, wy + (ph < .5 ? -amp : amp)); } | |
| 22 | + ctx.strokeStyle = C.blue; ctx.lineWidth = 2; ctx.stroke(); | |
| 23 | + S.say('After <b>' + n + '</b> ' + (n === 1 ? 'halving' : 'halvings') + ' the signal beats <b>' + f.toLocaleString() + ' times a second</b>.' + (n === 15 ? ' Exactly one pulse a second: that pulse moves the hand.' : n === 0 ? ' This is the raw crystal, far too fast to see or hear. Slide to divide it down.' : f > 4096 ? ' Still too high to hear comfortably.' : ' Press Hear this stage.')); | |
| 24 | + }); | |
| 25 | + }); |
exp/refraction.js added
| 1 | + WE.mount('refraction', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, ang = .7; | |
| 3 | + var mat = S.select('Material', [['1.333', 'Water'], ['1.52', 'Glass'], ['2.417', 'Diamond']], '1.333'), inside = S.toggle('Shine from inside', false); | |
| 4 | + S.pointer({ down: set, move: function (x, y, d) { if (d) set(x, y); } }); function set(x, y) { var cx = S.W / 2, cy = S.H / 2, a = Math.atan2(Math.abs(x - cx), Math.abs(y - cy)); ang = Math.max(.02, Math.min(1.54, a)); } | |
| 5 | + S.loop(function () { | |
| 6 | + S.clear(); var w = S.W, h = S.H, cx = w / 2, cy = h / 2, n = +mat.v, L = Math.min(w, h) * .46, n1 = inside.v ? n : 1, n2 = inside.v ? 1 : n, s2 = n1 / n2 * Math.sin(ang), tir = s2 > 1, a2 = tir ? 0 : Math.asin(s2), dir = inside.v ? 1 : -1; | |
| 7 | + ctx.fillStyle = 'rgba(111,177,230,.16)'; ctx.fillRect(0, cy, w, h - cy); S.ln(0, cy, w, cy, 'rgba(111,177,230,.7)', 1.5); ctx.setLineDash([4, 5]); S.ln(cx, cy - L, cx, cy + L, 'rgba(255,255,255,.3)', 1); ctx.setLineDash([]); | |
| 8 | + S.txt('Air', 14, cy - 16, C.mut, 13); S.txt({ '1.333': 'Water', '1.52': 'Glass', '2.417': 'Diamond' }[mat.v], 14, cy + 18, C.blue, 13); | |
| 9 | + var sx = cx - L * Math.sin(ang), sy = cy + dir * L * Math.cos(ang); ctx.shadowColor = C.yellow; ctx.shadowBlur = 10; S.ln(sx, sy, cx, cy, C.yellow, 3); | |
| 10 | + var R0 = Math.pow((n1 - n2) / (n1 + n2), 2), refl = tir ? 1 : R0 + (1 - R0) * Math.pow(1 - Math.cos(ang), 5); | |
| 11 | + ctx.globalAlpha = Math.max(.15, refl); S.ln(cx, cy, cx + L * Math.sin(ang), cy + dir * L * Math.cos(ang), C.yellow, 3); ctx.globalAlpha = 1; | |
| 12 | + if (!tir) { ctx.globalAlpha = Math.max(.2, 1 - refl); S.ln(cx, cy, cx + L * Math.sin(a2), cy - dir * L * Math.cos(a2), C.yellow, 3); ctx.globalAlpha = 1; } | |
| 13 | + ctx.shadowBlur = 0; S.dot(sx, sy, 9, C.yellow); S.ring(sx, sy, 15, 'rgba(240,210,100,.5)', 1.5); | |
| 14 | + var crit = Math.asin(1 / n) * 180 / Math.PI; | |
| 15 | + S.txt('In: ' + (ang * 180 / Math.PI).toFixed(0) + '°', cx + 12, cy + dir * 40, C.ink, 13); if (!tir) S.txt('Out: ' + (a2 * 180 / Math.PI).toFixed(0) + '°', cx + 12, cy - dir * 40, C.ink, 13); | |
| 16 | + S.say(tir ? '<b>Total internal reflection.</b> Past ' + crit.toFixed(0) + '° no light can get out, so the surface acts like a perfect mirror. This is how fiber optic cables carry light, and why diamonds sparkle.' : 'Light slows down in ' + (inside.v ? 'the material and speeds up again in air, so it bends away from the dotted line' : 'the material, so it bends toward the dotted line') + '. <b>Drag the light</b> to change its angle.' + (inside.v ? ' Keep going past ' + crit.toFixed(0) + '°.' : '')); | |
| 17 | + }); | |
| 18 | + }); |
exp/scale.js added
| 1 | + WE.mount('scale', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, O = [ | |
| 3 | + [1.7e-15, 'Proton', C.red], [1.4e-14, 'Gold nucleus', C.yellow], [1.06e-10, 'Hydrogen atom', C.blue], [2.8e-10, 'Water molecule', C.teal], [2e-9, 'DNA strand, across', C.violet], [1e-7, 'Flu virus', C.green], [7.5e-6, 'Red blood cell', C.red], [7.5e-5, 'Human hair, across', C.acc], [5e-4, 'Grain of sand', C.yellow], [2e-6, 'Bacterium', C.teal], [5e-3, 'Ant', C.mut], [.22, 'Soccer ball', C.ink], [1.7, 'Person', C.pink], [12, 'Bus', C.yellow], [30, 'Blue whale', C.blue], [105, 'Soccer field', C.green], [828, 'Tallest building', C.mut], [8849, 'Mount Everest', C.ink], [2.16e4, 'Manhattan island', C.acc], [4e5, 'Earth to the space station', C.teal], [3.475e6, 'The Moon', '#d8d2c2'], [1.2742e7, 'Earth', C.blue], [1.3982e8, 'Jupiter', '#e0b98c'], [1.3927e9, 'The Sun', '#ffd678'], [3.844e8, 'Earth to the Moon', C.mut], [1.496e11, 'Earth to the Sun', C.acc], [9e12, 'Orbit of Neptune', '#6f8df0'], [9.461e15, 'One light year', C.teal], [4.0e16, 'Distance to the nearest star', C.pink], [9.5e20, 'The Milky Way', C.violet], [2.4e22, 'Distance to the Andromeda galaxy', C.green], [8.8e26, 'The observable universe', C.ink]]; | |
| 4 | + var UN = [[1e-15, 'femtometers'], [1e-12, 'picometers'], [1e-9, 'nanometers'], [1e-6, 'micrometers'], [1e-3, 'millimeters'], [1, 'meters'], [1e3, 'kilometers'], [9.461e15, 'light years']]; | |
| 5 | + function fmt(m) { var u = UN[0]; UN.forEach(function (q) { if (m >= q[0]) u = q; }); var n = m / u[0]; return (n >= 1e9 ? (n / 1e9).toFixed(1) + ' billion' : n >= 1e6 ? (n / 1e6).toFixed(1) + ' million' : n >= 100 ? Math.round(n).toLocaleString() : n.toPrecision(2)) + ' ' + u[1]; } | |
| 6 | + var ex = S.slider('Zoom', -15.5, 27.5, 0.6, .05, function (v) { return 'screen is ' + fmt(Math.pow(10, v)) + ' wide'; }), auto = S.toggle('Zoom out by itself', false), cur = .6; | |
| 7 | + S.loop(function (dt) { | |
| 8 | + if (auto.v) { var nv = ex.v + dt * .9; if (nv > 27.5) { nv = 27.5; auto.set(false); } ex.set(nv); } | |
| 9 | + cur += (ex.v - cur) * Math.min(1, dt * 8); | |
| 10 | + S.clear(); var w = S.W, h = S.H, view = Math.pow(10, cur), near = null, nd = 99; | |
| 11 | + O.forEach(function (o) { | |
| 12 | + var px = o[0] / view * w, l = Math.log10(o[0]) - cur; if (px < 1.5 || px > w * 40) return; | |
| 13 | + var al = Math.max(0, Math.min(1, px < 30 ? px / 30 : px > w * 1.5 ? 1 - (px - w * 1.5) / (w * 10) : 1)); ctx.globalAlpha = al; | |
| 14 | + S.ring(w / 2, h / 2, px / 2, o[2], px > 60 ? 2 : 1.5); if (px < 14) S.dot(w / 2, h / 2, px / 2, o[2]); | |
| 15 | + if (px > 26 && px < w * 3) { var yy = h / 2 - Math.min(px / 2, h * .46) - 12; S.txt(o[1], w / 2, Math.max(14, yy), o[2], 13.5, 'center', 650); } | |
| 16 | + ctx.globalAlpha = 1; if (Math.abs(l + .45) < nd) { nd = Math.abs(l + .45); near = o; } | |
| 17 | + }); | |
| 18 | + var bar = Math.pow(10, Math.floor(cur - .5)), bp = bar / view * w; S.ln(16, h - 20, 16 + bp, h - 20, C.ink, 2); S.ln(16, h - 25, 16, h - 15, C.ink, 2); S.ln(16 + bp, h - 25, 16 + bp, h - 15, C.ink, 2); S.txt(fmt(bar), 22 + bp, h - 20, C.mut, 12); | |
| 19 | + S.txt('10', 16, 28, C.mut, 22, 'left', 600); S.txt(String(Math.round(cur)), 42, 18, C.acc, 14, 'left', 700); S.txt('meters wide', 66, 28, C.mut, 13); | |
| 20 | + S.say(near ? '<b>' + near[1] + '</b> is about ' + fmt(near[0]) + ' across. Each step of the slider makes the view ten times wider.' : 'Slide to zoom from the inside of an atom to the edge of the universe we can see.'); | |
| 21 | + }); | |
| 22 | + }); |
exp/seasons.js added
| 1 | + WE.mount('seasons', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], ML = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; | |
| 3 | + function dstr(n) { var m = 0; n = Math.floor(n); while (n >= ML[m]) { n -= ML[m]; m++; } return MON[m] + ' ' + (n + 1); } | |
| 4 | + var day = S.slider('Day of the year', 0, 364, 171, 1, dstr), lat = S.slider('Latitude', -90, 90, 47, 1, function (v) { return Math.abs(v) + '° ' + (v >= 0 ? 'north' : 'south'); }), play = S.toggle('Play the year', false); | |
| 5 | + S.loop(function (dt) { | |
| 6 | + if (play.v) day.set((day.v + dt * 30) % 365); | |
| 7 | + S.clear(); var w = S.W, h = S.H, sm = S.small(), N = day.v, dec = -23.44 * Math.cos(S.TAU * (N + 10) / 365), dr = dec * Math.PI / 180, ph = lat.v * Math.PI / 180; | |
| 8 | + var c = -Math.tan(ph) * Math.tan(dr), hours = c >= 1 ? 0 : c <= -1 ? 24 : 24 / Math.PI * Math.acos(c), noon = 90 - Math.abs(lat.v - dec); | |
| 9 | + // orbit view | |
| 10 | + var ox = sm ? w / 2 : w * .24, oy = sm ? h * .22 : h * .5, a = sm ? w * .36 : w * .16, b = sm ? h * .13 : h * .3, th = S.TAU * (N - 171) / 365; | |
| 11 | + ctx.strokeStyle = 'rgba(255,255,255,.15)'; ctx.lineWidth = 1; ctx.beginPath(); ctx.ellipse(ox, oy, a, b, 0, 0, S.TAU); ctx.stroke(); S.dot(ox, oy, 12, '#ffd678'); | |
| 12 | + [['Jun', 0], ['Sep', .25], ['Dec', .5], ['Mar', .75]].forEach(function (q) { var t = q[1] * S.TAU; S.txt(q[0], ox - (a + 18) * Math.cos(t), oy + (b + 14) * Math.sin(t), C.mut, 11.5, 'center'); }); | |
| 13 | + var ex = ox - a * Math.cos(th), ey = oy + b * Math.sin(th); S.dot(ex, ey, 9, C.blue); S.ln(ex - 7, ey + 16, ex + 7, ey - 16, C.ink, 1.5); S.txt('N', ex + 12, ey - 20, C.mut, 10); | |
| 14 | + // close view: sunlight from the left, axis leans toward the Sun by the declination | |
| 15 | + var gx = sm ? w / 2 : w * .76, gy = sm ? h * .66 : h * .5, R = sm ? Math.min(w * .26, h * .2) : Math.min(w * .17, h * .34); | |
| 16 | + for (var i = -2; i <= 2; i++) S.arrow(gx - R * 1.75, gy + i * R * .45, gx - R * 1.2, gy + i * R * .45, 'rgba(240,210,100,.7)', 1.5); | |
| 17 | + S.dot(gx, gy, R, C.blue); ctx.beginPath(); ctx.arc(gx, gy, R, -Math.PI / 2, Math.PI / 2); ctx.fillStyle = '#0f1a2c'; ctx.fill(); | |
| 18 | + ctx.save(); ctx.translate(gx, gy); ctx.rotate(-dr); S.ln(0, -R * 1.25, 0, R * 1.25, C.ink, 1.5); S.ln(-R, 0, R, 0, 'rgba(255,255,255,.35)', 1); | |
| 19 | + var ly = -R * Math.sin(ph), lx = R * Math.cos(ph); S.ln(-lx, ly, lx, ly, C.acc, 3); S.dot(-lx, ly, 4, C.acc); ctx.restore(); | |
| 20 | + S.txt('Day', gx - R * .5, gy + R + 16, C.mut, 12, 'center'); S.txt('Night', gx + R * .5, gy + R + 16, C.mut, 12, 'center'); | |
| 21 | + var tx = sm ? 14 : gx - R, ty = sm ? h * .93 : gy - R - 44; S.txt(hours.toFixed(1) + ' hours of daylight', tx, ty, C.ink, sm ? 16 : 20, 'left', 700); | |
| 22 | + var season = Math.abs(dec) < 8 ? (N < 180 ? ['spring', 'fall'] : ['fall', 'spring']) : dec > 0 ? ['summer', 'winter'] : ['winter', 'summer']; | |
| 23 | + S.say(dstr(N) + ' at ' + Math.abs(lat.v) + '° ' + (lat.v >= 0 ? 'north' : 'south') + ': <b>' + (lat.v >= 0 ? season[0] : season[1]) + '</b>. ' + (hours >= 24 ? 'The Sun never sets.' : hours <= 0 ? 'The Sun never rises.' : 'At noon the Sun stands ' + Math.max(0, noon).toFixed(0) + '° above the horizon.') + ' The gold line is your latitude: the more of it in daylight, the longer your day.'); | |
| 24 | + }); | |
| 25 | + }); |
exp/sieve.js added
| 1 | + WE.mount('sieve', function (S) { | |
| 2 | + var C = S.C, ctx = S.ctx, N, cols, st, p, m, done, run = false, acc = 0, found, hover = 0, G = {}; | |
| 3 | + var PAL = [C.red, C.blue, C.green, C.violet, C.teal, C.pink, C.yellow, '#e09a5a']; | |
| 4 | + var size = S.select('Numbers', [['100', '1 to 100'], ['400', '1 to 400'], ['900', '1 to 900']], '100', reset), spd = S.slider('Speed', 1, 100, 20, 1); | |
| 5 | + var play = S.toggle('Run', true); S.button('One step', function () { play.set(false); step(); }); S.button('Start over', reset); | |
| 6 | + function reset() { N = +size.v; cols = Math.round(Math.sqrt(N)); st = new Int16Array(N + 1); p = 2; m = 0; done = false; found = 0; st[1] = -2; } | |
| 7 | + function step() { if (done) return; if (m === 0) { st[p] = -1; found++; if (p * p > N) { for (var i = p + 1; i <= N; i++) if (st[i] === 0) { st[i] = -1; found++; } done = true; return; } m = p * p; return; } if (st[m] === 0) st[m] = p; m += p; if (m > N) { m = 0; do { p++; } while (p <= N && st[p] !== 0); } } | |
| 8 | + reset(); | |
| 9 | + S.pointer({ scroll: true, move: function (x, y) { var c = Math.floor((x - G.x0) / G.cs), r = Math.floor((y - G.y0) / G.cs); hover = c >= 0 && c < cols && r >= 0 && r * cols + c < N ? r * cols + c + 1 : 0; }, down: function (x, y) { var c = Math.floor((x - G.x0) / G.cs), r = Math.floor((y - G.y0) / G.cs); hover = c >= 0 && c < cols && r >= 0 && r * cols + c < N ? r * cols + c + 1 : 0; } }); | |
| 10 | + function factors(v) { var o = [], d = 2; while (v > 1 && d * d <= v) { while (v % d === 0) { o.push(d); v /= d; } d++; } if (v > 1) o.push(v); return o; } | |
| 11 | + S.loop(function (dt) { | |
| 12 | + if (play.v && !done) { acc += dt * spd.v * (N / 100) * 1.2; while (acc >= 1) { acc--; step(); } } | |
| 13 | + var w = S.W, h = S.H, sm = S.small(), rws = Math.ceil(N / cols), top = 34, cs = Math.min((w - 20) / cols, (h - top - 8) / rws); G.cs = cs; G.x0 = (w - cs * cols) / 2; G.y0 = top; | |
| 14 | + S.clear(); var pi = {}, cnt = 0; | |
| 15 | + for (var i = 1; i <= N; i++) { var c = (i - 1) % cols, r = Math.floor((i - 1) / cols), x = G.x0 + c * cs, y = G.y0 + r * cs, s = st[i], fill = s === -1 ? C.acc : s === -2 ? '#15181e' : s > 0 ? null : '#1e232c'; | |
| 16 | + if (s > 0) { if (pi[s] === undefined) pi[s] = cnt++ ; } | |
| 17 | + if (fill) S.rr(x + 1, y + 1, cs - 2, cs - 2, Math.min(5, cs * .2), fill); else { ctx.globalAlpha = .28; S.rr(x + 1, y + 1, cs - 2, cs - 2, Math.min(5, cs * .2), PAL[[2, 3, 5, 7, 11, 13, 17, 19, 23, 29].indexOf(s) % 8]); ctx.globalAlpha = 1; } | |
| 18 | + if (i === m && !done) S.rr(x + 1, y + 1, cs - 2, cs - 2, Math.min(5, cs * .2), null, C.ink); | |
| 19 | + if (cs >= 17) S.txt(i, x + cs / 2, y + cs / 2 + .5, s === -1 ? '#1a1206' : s > 0 || s === -2 ? C.dim : C.ink, Math.min(13, cs * .38), 'center', s === -1 ? 700 : 500); | |
| 20 | + } | |
| 21 | + S.txt(found + ' primes found', 14, 17, C.acc, 14, 'left', 700); if (!done) S.txt(m ? 'Crossing out every multiple of ' + p : 'Next prime: ' + p, w - 54, 17, C.mut, 12.5, 'right'); | |
| 22 | + var tip = ''; if (hover) { var f = factors(hover); tip = hover === 1 ? ' <b>1</b> is not counted as a prime.' : f.length === 1 ? ' <b>' + hover + '</b> is prime. Nothing divides it but 1 and itself.' : ' <b>' + hover + '</b> = ' + f.join(' × ') + '.'; } | |
| 23 | + S.say((done ? 'Done. Every gold number is a <b>prime</b>: ' + found + ' of them up to ' + N + '. We only had to cross out multiples of the primes up to ' + Math.floor(Math.sqrt(N)) + '.' : 'Start at 2. Keep it, and cross out every multiple of it. Move to the next number still standing, and repeat. Whatever survives is <b>prime</b>.') + (tip || (sm ? '' : ' Point at any number to see what it is made of.'))); | |
| 24 | + }); | |
| 25 | + }); |
164 more files changed.