Download index.html from AK51/Kepler: direct link, hf CLI and curl.
- Browser
- Download file 124 kB
-
https://huggingface.co/spaces/AK51/Kepler/resolve/main/index.html
- Command line
-
hf download hf://spaces/AK51/Kepler/index.html
-
curl -L -o index.html https://huggingface.co/spaces/AK51/Kepler/resolve/main/index.html
124 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="color-scheme" content="dark" />
<link rel="icon" href="data:," />
<title>Kepler Laws</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&family=Spectral:ital,wght@0,500;0,600;0,700;1,500;1,600&family=Unbounded:wght@500;700;900&display=swap" rel="stylesheet" />
<style>
button, [role="button"], select, summary, input:not([type="checkbox"], [type="radio"]) { min-height: 2rem; }
* { box-sizing: border-box; }
:root{
--bg:#05080f; --bg2:#080d18; --panel:#0b1120; --panel2:#0e1729;
--line:#1d2a44; --line2:#27395e;
--ink:#e9edf5; --muted:#a3b1c8; --faint:#6b7a94;
--amber:#f6b73c; --teal:#2fd4c4; --coral:#ff7a59; --blue:#6f9dff; --pink:#ef6a9a;
--good:#43d17c; --bad:#ff6b6b;
--serif:"Spectral", Georgia, serif;
--sans:"IBM Plex Sans", system-ui, sans-serif;
--mono:"IBM Plex Mono", ui-monospace, monospace;
}
html{ scroll-behavior:smooth; }
body{
margin:0; background:var(--bg); color:var(--ink);
font-family:var(--sans); font-size:16.5px; line-height:1.62;
-webkit-font-smoothing:antialiased;
}
body::before{
content:""; position:fixed; inset:0; z-index:-1; pointer-events:none;
background:
radial-gradient(1px 1px at 12% 22%, rgba(255,255,255,.75) 50%, transparent 51%),
radial-gradient(1px 1px at 68% 8%, rgba(255,255,255,.5) 50%, transparent 51%),
radial-gradient(1.5px 1.5px at 84% 34%, rgba(255,255,255,.65) 50%, transparent 51%),
radial-gradient(1px 1px at 33% 58%, rgba(255,255,255,.45) 50%, transparent 51%),
radial-gradient(1px 1px at 52% 78%, rgba(255,255,255,.55) 50%, transparent 51%),
radial-gradient(1.5px 1.5px at 24% 88%, rgba(255,255,255,.4) 50%, transparent 51%),
radial-gradient(1px 1px at 92% 66%, rgba(255,255,255,.5) 50%, transparent 51%),
radial-gradient(1px 1px at 44% 14%, rgba(255,255,255,.6) 50%, transparent 51%),
radial-gradient(1px 1px at 6% 48%, rgba(255,255,255,.4) 50%, transparent 51%),
radial-gradient(1px 1px at 76% 92%, rgba(255,255,255,.45) 50%, transparent 51%),
radial-gradient(ellipse 90% 55% at 50% -10%, #101c33 0%, transparent 60%),
linear-gradient(180deg, var(--bg2), var(--bg) 340px);
}
.wrap{ max-width:1120px; margin:0 auto; padding:0 20px 80px; }
a{ color:var(--teal); }
a:hover{ color:#7ce8dc; }
/* ---------- sticky chapter nav ---------- */
nav.chapters{
position:sticky; top:0; z-index:50;
background:rgba(5,8,15,.88); backdrop-filter:blur(10px);
border-bottom:1px solid var(--line);
}
nav.chapters .inner{
max-width:1120px; margin:0 auto; padding:0 20px;
display:flex; gap:4px; align-items:center; flex-wrap:wrap;
}
nav.chapters a{
color:var(--muted); text-decoration:none; white-space:nowrap;
font-size:13.5px; font-weight:600; letter-spacing:.02em;
padding:12px 10px; min-height:44px; display:flex; align-items:center;
}
nav.chapters a:hover{ color:var(--ink); }
nav.chapters a.hot{ color:var(--teal); }
/* ---------- hero ---------- */
header.hero{ padding:64px 0 30px; }
.hero .kicker{
font-family:var(--mono); font-size:12.5px; letter-spacing:.22em;
text-transform:uppercase; color:var(--amber); margin:0 0 18px;
}
.hero h1{
font-family:var(--serif); font-weight:600; line-height:1.08;
font-size:clamp(34px, 6vw, 58px); margin:0 0 14px; max-width:16em;
}
.hero h1 em{ font-style:italic; color:var(--teal); }
.hero .lede{ color:var(--muted); font-size:18px; max-width:44em; margin:0 0 30px; }
.laws-oneline{
border:1px solid var(--line); background:var(--panel);
border-radius:10px; padding:8px 22px; margin:0 0 26px;
}
.laws-oneline p{
margin:0; padding:13px 0; display:flex; gap:16px; align-items:baseline;
border-bottom:1px solid var(--line); font-size:16.5px;
}
.laws-oneline p:last-child{ border-bottom:none; }
.laws-oneline .n{
font-family:var(--mono); color:var(--amber); font-weight:600; font-size:14px;
flex:0 0 auto;
}
.surprise{
border:1px solid #14524b; background:linear-gradient(180deg, #0a1f1d, #081614);
border-radius:10px; padding:20px 22px; margin:0;
}
.surprise .tag{
font-family:var(--mono); font-size:11.5px; letter-spacing:.2em; text-transform:uppercase;
color:var(--teal); display:block; margin-bottom:8px;
}
.surprise p{ margin:0; font-size:17.5px; }
.surprise strong{ color:var(--teal); }
.hero .method{ color:var(--faint); font-size:13.5px; margin:16px 2px 0; font-family:var(--mono); }
/* ---------- sections ---------- */
section{ padding:56px 0 8px; scroll-margin-top:70px; }
.sec-head{ display:flex; gap:18px; align-items:baseline; margin-bottom:6px; }
.sec-head .chap{
font-family:var(--mono); color:var(--amber); font-size:13px; letter-spacing:.18em;
text-transform:uppercase; white-space:nowrap;
}
.sec-head h2{
font-family:var(--serif); font-weight:600; font-size:clamp(26px, 4vw, 36px);
margin:0; line-height:1.15;
}
section.featured .sec-head .chap{ color:var(--teal); }
.law-statement{
font-family:var(--serif); font-style:italic; font-size:clamp(18px, 2.6vw, 21.5px);
color:#dbe4f2; border-left:3px solid var(--amber);
padding:4px 0 4px 18px; margin:18px 0 20px; max-width:46em;
}
section.featured .law-statement{ border-left-color:var(--teal); }
.prose{ color:var(--muted); max-width:46em; }
.prose strong, .prose b{ color:var(--ink); }
.prose p{ margin:0 0 14px; }
/* ---------- sim panels ---------- */
.sim{
background:var(--panel); border:1px solid var(--line); border-radius:12px;
padding:16px; margin:20px 0;
}
.sim .cap{
display:flex; justify-content:space-between; gap:12px; flex-wrap:wrap;
font-family:var(--mono); font-size:12px; letter-spacing:.14em; text-transform:uppercase;
color:var(--faint); margin:2px 2px 10px;
}
.sim .cap .r{ color:var(--teal); text-transform:none; letter-spacing:.02em; }
canvas.stage{
display:block; width:100%; border-radius:8px;
background:radial-gradient(ellipse 120% 100% at 50% 40%, #0a1322 0%, #060a13 70%);
border:1px solid var(--line);
}
.h-law{ height:clamp(300px, 54vw, 430px); }
.h-hodo{ height:clamp(330px, 48vw, 470px); }
.h-chart{ height:clamp(300px, 50vw, 420px); }
.duo{ display:grid; grid-template-columns:1fr 1fr; gap:16px; }
@media (max-width:760px){ .duo{ grid-template-columns:1fr; } }
.controls{
display:flex; flex-wrap:wrap; gap:10px 18px; align-items:center;
margin-top:14px; padding-top:14px; border-top:1px solid var(--line);
}
.controls .grp{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.controls label.lab, .ctl-lab{
font-size:12.5px; font-weight:600; letter-spacing:.06em; text-transform:uppercase; color:var(--faint);
}
.btn{
appearance:none; border:1px solid var(--line2); background:var(--panel2);
color:var(--ink); border-radius:8px; padding:8px 16px; min-height:38px;
font-family:var(--sans); font-size:14.5px; font-weight:600; cursor:pointer;
}
.btn:hover{ border-color:var(--teal); color:var(--teal); }
.btn.primary{ background:#0d2f2a; border-color:#1d5a50; color:#8ff0e2; }
.btn.primary:hover{ border-color:var(--teal); }
.btn[disabled]{ opacity:.38; cursor:default; }
.btn[disabled]:hover{ border-color:var(--line2); color:var(--ink); }
.seg{ display:inline-flex; border:1px solid var(--line2); border-radius:8px; overflow:hidden; }
.seg button{
appearance:none; border:none; background:transparent; color:var(--muted);
padding:8px 13px; min-height:38px; font-family:var(--sans); font-size:14px; font-weight:600; cursor:pointer;
}
.seg button + button{ border-left:1px solid var(--line2); }
.seg button.on{ background:#123a35; color:#8ff0e2; }
.seg button:hover:not(.on){ color:var(--ink); }
.presets{ display:flex; flex-wrap:wrap; gap:8px; }
.preset{
appearance:none; border:1px solid var(--line2); background:transparent; color:var(--muted);
border-radius:999px; padding:6px 14px; min-height:36px; font-family:var(--sans);
font-size:13.5px; font-weight:600; cursor:pointer;
}
.preset:hover{ color:var(--ink); border-color:var(--faint); }
.preset.on{ color:#0b1120; background:var(--amber); border-color:var(--amber); }
input[type="range"]{
-webkit-appearance:none; appearance:none; height:4px; border-radius:2px;
background:var(--line2); outline:none; cursor:pointer; min-height:32px;
background-clip:content-box; padding:14px 0; margin:-14px 0;
}
input[type="range"]::-webkit-slider-thumb{
-webkit-appearance:none; width:20px; height:20px; border-radius:50%;
background:var(--ink); border:3px solid var(--amber); cursor:pointer;
}
input[type="range"]::-moz-range-thumb{
width:14px; height:14px; border-radius:50%; background:var(--ink); border:3px solid var(--amber); cursor:pointer;
}
.slider-grp{ display:flex; align-items:center; gap:10px; }
.slider-grp input[type="range"]{ width:170px; }
@media (max-width:560px){ .slider-grp input[type="range"]{ width:130px; } }
.slider-grp .val{ font-family:var(--mono); font-size:14px; color:var(--amber); min-width:74px; }
.scrub-wrap{ flex:1 1 220px; display:flex; align-items:center; gap:10px; }
.scrub-wrap input[type="range"]{ flex:1; }
.scrub-wrap input[type="range"]::-webkit-slider-thumb{ border-color:var(--teal); }
.scrub-wrap input[type="range"]::-moz-range-thumb{ border-color:var(--teal); }
label.toggle{
display:inline-flex; align-items:center; gap:9px; cursor:pointer;
padding:7px 4px; min-height:38px; font-size:14px; color:var(--muted); font-weight:500;
}
label.toggle input{ width:18px; height:18px; accent-color:var(--teal); cursor:pointer; flex:0 0 auto; }
label.toggle:hover{ color:var(--ink); }
/* ---------- readouts ---------- */
.stats{
display:grid; grid-template-columns:repeat(auto-fit, minmax(128px, 1fr));
gap:10px; margin-top:14px;
}
.stat{
background:var(--panel2); border:1px solid var(--line); border-radius:8px; padding:9px 12px;
}
.stat .k{ font-size:11px; font-weight:600; letter-spacing:.1em; text-transform:uppercase; color:var(--faint); display:block; margin-bottom:2px; }
.stat .v{ font-family:var(--mono); font-size:16.5px; font-weight:600; color:var(--ink); white-space:nowrap; }
.stat .v small{ font-size:11.5px; color:var(--faint); font-weight:400; }
.stat .v.amber{ color:var(--amber); } .stat .v.teal{ color:var(--teal); }
.stat .v.coral{ color:var(--coral); } .stat .v.good{ color:var(--good); }
.checkline{
margin-top:12px; font-family:var(--mono); font-size:14px; color:var(--muted);
background:#081018; border:1px dashed var(--line2); border-radius:8px; padding:10px 14px;
white-space:normal; overflow-wrap:anywhere; line-height:1.9;
}
.checkline b{ color:var(--ink); } .checkline .ok{ color:var(--good); font-weight:600; }
.callout{
border:1px solid #14524b; background:#081a17; border-radius:10px;
padding:16px 18px; margin:18px 0; color:#c4ded9;
}
.callout strong{ color:var(--teal); }
.callout p{ margin:0 0 8px; } .callout p:last-child{ margin:0; }
/* sector chips */
.chips{ display:flex; flex-wrap:wrap; gap:8px; margin-top:12px; }
.chip{
font-family:var(--mono); font-size:13px; border:1px solid var(--line2);
border-radius:6px; padding:5px 10px; color:var(--faint); background:var(--panel2);
}
.chip.done{ color:var(--ink); border-color:#2c4a44; }
.chip.done b{ color:var(--teal); font-weight:600; }
.chip.now{ color:var(--amber); border-color:var(--amber); }
/* ---------- law 3 table ---------- */
.table-wrap{ margin:20px 0; border:1px solid var(--line); border-radius:12px; overflow:hidden; background:var(--panel); }
table.planets{ width:100%; border-collapse:collapse; font-size:15px; }
table.planets th{
text-align:right; font-size:11.5px; letter-spacing:.09em; text-transform:uppercase;
color:var(--faint); font-weight:600; padding:12px 14px; border-bottom:1px solid var(--line);
background:var(--panel2);
}
table.planets th:first-child, table.planets td:first-child{ text-align:left; }
table.planets td{
padding:11px 14px; text-align:right; font-family:var(--mono); font-size:14.5px;
border-bottom:1px solid var(--line); color:var(--muted);
}
table.planets td:first-child{ font-family:var(--sans); font-weight:600; color:var(--ink); font-size:15px; }
table.planets tbody tr{ cursor:pointer; }
table.planets tbody tr:hover td{ background:#101a2e; color:var(--ink); }
table.planets tbody tr.on td{ background:#0d2f2a; color:var(--ink); }
table.planets tbody tr.on td:first-child{ color:var(--teal); }
table.planets tbody tr:last-child td{ border-bottom:none; }
@media (max-width:640px){
table.planets th:nth-child(4), table.planets td:nth-child(4){ display:none; }
table.planets th{ padding:10px 8px; font-size:10.5px; }
table.planets td{ padding:10px 8px; font-size:12.5px; }
table.planets td:first-child{ font-size:13.5px; }
nav.chapters a{ padding:8px 7px; font-size:12px; min-height:38px; }
section{ scroll-margin-top:88px; }
}
.load-note{ font-family:var(--mono); font-size:13px; color:var(--teal); min-height:20px; margin:8px 2px 0; }
/* ---------- derivation steps ---------- */
.steps{ display:grid; grid-template-columns:repeat(3, 1fr); gap:14px; margin:22px 0; }
@media (max-width:820px){ .steps{ grid-template-columns:1fr; } }
.step{
background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:18px;
}
.step .sn{
font-family:var(--mono); font-size:11.5px; letter-spacing:.18em; text-transform:uppercase;
color:var(--amber); display:block; margin-bottom:8px;
}
.step h3{ font-family:var(--serif); font-size:19px; margin:0 0 8px; font-weight:600; }
.step p{ color:var(--muted); font-size:14.5px; margin:0 0 10px; }
.step p:last-child{ margin:0; }
.eq{
font-family:var(--serif); font-style:italic; font-size:17px; color:var(--ink);
background:#081018; border:1px solid var(--line); border-radius:8px;
padding:10px 12px; margin:10px 0; text-align:center; overflow-x:auto; white-space:nowrap;
}
.eq .rm{ font-style:normal; font-family:var(--mono); font-size:12px; color:var(--faint); }
.note-grid{ display:grid; grid-template-columns:1fr 1fr; gap:14px; margin:14px 0; }
@media (max-width:820px){ .note-grid{ grid-template-columns:1fr; } }
.note{
background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:18px;
}
.note h3{ font-family:var(--serif); font-size:18px; margin:0 0 8px; font-weight:600; }
.note p{ color:var(--muted); font-size:14.5px; margin:0 0 10px; }
.note p:last-child{ margin:0; }
/* ---------- quiz ---------- */
.quiz-q{
background:var(--panel); border:1px solid var(--line); border-radius:10px;
padding:18px; margin:0 0 14px;
}
.quiz-q h3{ font-size:16.5px; margin:0 0 12px; font-weight:600; }
.quiz-q h3 .qn{ font-family:var(--mono); color:var(--amber); margin-right:8px; font-size:14px; }
.opts{ display:grid; gap:8px; }
.opt{
appearance:none; text-align:left; border:1px solid var(--line2); background:var(--panel2);
color:var(--ink); border-radius:8px; padding:11px 14px; min-height:44px;
font-family:var(--sans); font-size:15px; cursor:pointer; width:100%;
}
.opt:hover:not([disabled]){ border-color:var(--faint); }
.opt[disabled]{ cursor:default; opacity:.75; }
.opt.right{ border-color:var(--good); background:rgba(67,209,124,.12); opacity:1; }
.opt.wrong{ border-color:var(--bad); background:rgba(255,107,107,.10); opacity:1; }
.why{ display:none; margin:12px 0 0; color:var(--muted); font-size:14.5px; border-top:1px dashed var(--line2); padding-top:10px; }
.why.show{ display:block; }
.why b{ color:var(--ink); }
.quiz-score{ font-family:var(--mono); font-size:15px; color:var(--amber); margin:4px 0 16px; }
/* ---------- timeline / sources ---------- */
.timeline{ list-style:none; margin:20px 0; padding:0; }
.timeline li{
display:flex; gap:18px; padding:13px 0; border-bottom:1px solid var(--line); align-items:baseline;
}
.timeline li:last-child{ border-bottom:none; }
.timeline .yr{
font-family:var(--mono); font-weight:600; color:var(--amber); font-size:15px;
flex:0 0 64px; text-align:right;
}
.timeline .ev{ color:var(--muted); }
.timeline .ev b{ color:var(--ink); }
.sources{ list-style:none; margin:14px 0; padding:0; }
.sources li{ padding:7px 0; border-bottom:1px solid var(--line); }
.sources li:last-child{ border-bottom:none; }
.sources .sk{ font-family:var(--mono); font-size:11.5px; letter-spacing:.12em; text-transform:uppercase; color:var(--faint); display:block; }
footer{ margin-top:60px; border-top:1px solid var(--line); padding-top:18px; color:var(--faint); font-size:13.5px; }
.build-ui{ display:none; }
.build-ui.show{ display:flex; }
/* ================= CINEMATIC OVERRIDE ================= */
:root{
--bg:#04050e; --bg2:#080a1e;
--panel:rgba(17,21,46,.58); --panel2:rgba(26,32,66,.55);
--line:rgba(124,146,230,.22); --line2:rgba(148,168,240,.40);
--violet:#d873ff; --magenta:#f06bd8; --cyan:#2fe8d8; --gold:#ffb84d;
--disp:"Unbounded", "IBM Plex Sans", system-ui, sans-serif;
}
body{
background:
radial-gradient(1100px 620px at 85% -5%, rgba(88,40,160,.34), transparent 60%),
radial-gradient(900px 700px at -10% 30%, rgba(16,90,110,.30), transparent 60%),
radial-gradient(1000px 800px at 55% 110%, rgba(60,30,130,.28), transparent 62%),
linear-gradient(180deg, #070818, #04050e 420px);
}
body::before{ z-index:-2; opacity:.5; }
#bgStars{ position:fixed; inset:0; width:100%; height:100%; z-index:-1; pointer-events:none; }
::selection{ background:rgba(216,115,255,.4); }
nav.chapters{ background:rgba(6,8,20,.78); border-bottom:1px solid rgba(124,146,230,.25); box-shadow:0 6px 30px rgba(0,0,0,.35); }
nav.chapters a.hot{ color:var(--violet); text-shadow:0 0 12px rgba(216,115,255,.6); }
/* ---------- hero stage ---------- */
header.hero{ padding:26px 0 8px; }
.hero-stage{
position:relative; border-radius:22px; overflow:hidden;
border:1px solid rgba(140,160,255,.28);
box-shadow:0 24px 70px rgba(0,0,0,.55), 0 0 60px rgba(90,60,200,.18), inset 0 0 80px rgba(20,16,60,.35);
background:#05060f;
}
.hero-cv{ position:absolute; inset:0; width:100%; height:100%; display:block; }
.hero-shade{ position:absolute; inset:0; pointer-events:none;
background:linear-gradient(90deg, rgba(4,5,14,.84) 0%, rgba(4,5,14,.55) 46%, rgba(4,5,14,.04) 78%); }
.hero-content{ position:relative; padding:40px 34px 64px; max-width:650px; }
.hero .kicker{ color:var(--gold); text-shadow:0 0 14px rgba(255,184,77,.55); }
.hero h1{
font-family:var(--disp); font-weight:700; letter-spacing:.01em;
font-size:clamp(26px, 4.6vw, 45px); line-height:1.24; max-width:15em;
background:linear-gradient(94deg, #ffffff 8%, #9fdcff 44%, var(--violet) 80%, var(--magenta));
-webkit-background-clip:text; background-clip:text; color:transparent;
}
.hero h1 em{ font-style:normal; color:#8ff5e6; -webkit-text-fill-color:#8ff5e6; }
.hero .lede{ color:#c6d2ea; font-size:17.5px; text-shadow:0 1px 8px rgba(0,0,0,.65); margin-bottom:22px; }
.hero-chips{ display:flex; flex-wrap:wrap; gap:9px; }
.hchip{
display:inline-flex; align-items:center; gap:8px;
font-family:var(--mono); font-size:12.5px; color:#dbe6ff;
background:rgba(14,18,40,.62); border:1px solid rgba(140,170,255,.35);
border-radius:999px; padding:7px 13px; backdrop-filter:blur(8px);
box-shadow:0 0 18px rgba(80,110,255,.18);
}
.hchip i{ width:8px; height:8px; border-radius:50%; background:var(--gold); box-shadow:0 0 10px var(--gold); flex:0 0 auto; }
.hchip b{ color:#ffd98a; font-weight:600; }
.scroll-cue{
position:absolute; left:50%; bottom:13px; transform:translateX(-50%);
display:flex; flex-direction:column; align-items:center; gap:3px;
color:rgba(200,214,240,.75); font-family:var(--mono); font-size:10.5px;
letter-spacing:.28em; text-transform:uppercase; pointer-events:none;
}
.scroll-cue i{
width:10px; height:10px; border-right:2px solid rgba(200,214,240,.85);
border-bottom:2px solid rgba(200,214,240,.85);
transform:rotate(45deg); animation:cueDrop 1.8s ease-in-out infinite;
}
@keyframes cueDrop{ 0%,100%{ transform:rotate(45deg) translate(0,0); opacity:.45; } 50%{ transform:rotate(45deg) translate(4px,4px); opacity:1; } }
/* ---------- law cards ---------- */
.law-cards{ display:grid; grid-template-columns:repeat(3, 1fr); gap:14px; margin:22px 0 26px; }
@media (max-width:820px){ .law-cards{ grid-template-columns:1fr; } }
.law-card{
background:linear-gradient(165deg, rgba(26,32,66,.72), rgba(10,12,30,.82));
border:1px solid rgba(124,146,230,.28); border-radius:16px;
padding:14px 16px 16px; backdrop-filter:blur(12px);
box-shadow:0 16px 40px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.07);
transition:transform .35s ease, box-shadow .35s ease, border-color .35s ease;
}
.law-card:hover{ transform:translateY(-5px); border-color:rgba(160,190,255,.55); box-shadow:0 24px 50px rgba(0,0,0,.5), 0 0 34px rgba(90,110,255,.22); }
.law-card .mini-cv{ display:block; width:100%; height:78px; margin-bottom:10px; }
.law-card p{ margin:0; display:flex; gap:12px; align-items:baseline; font-size:15.5px; }
.law-card .n{ font-family:var(--mono); color:var(--amber); font-weight:600; font-size:13px; flex:0 0 auto; text-shadow:0 0 10px rgba(246,183,60,.5); }
.law-card strong{ color:#fff; }
.surprise{
border:1px solid rgba(216,115,255,.4); border-radius:16px; position:relative; overflow:hidden;
background:linear-gradient(160deg, rgba(46,20,80,.5), rgba(8,20,26,.65));
box-shadow:0 0 44px rgba(150,70,255,.16), inset 0 1px 0 rgba(255,255,255,.06);
}
.surprise::before{ content:"\201C"; position:absolute; right:12px; top:-34px; font-family:var(--serif); font-size:120px; color:rgba(216,115,255,.16); pointer-events:none; }
.surprise .tag{ color:var(--violet); text-shadow:0 0 12px rgba(216,115,255,.55); }
.surprise strong{ color:#f3c6ff; }
/* ---------- section heads ---------- */
.sec-head{ align-items:center; }
.bignum{
font-family:var(--disp); font-weight:900; line-height:1; flex:0 0 auto;
font-size:clamp(38px, 6.4vw, 62px); color:transparent;
-webkit-text-stroke:1.5px rgba(140,170,255,.42);
}
section.featured .bignum{ -webkit-text-stroke-color:rgba(216,115,255,.6); }
.sec-head h2{
font-family:var(--disp); font-weight:700; line-height:1.32;
font-size:clamp(20px, 3.2vw, 30px);
background:linear-gradient(92deg, #ffffff 5%, #a8d8ff 55%, #cfa2ff);
-webkit-background-clip:text; background-clip:text; color:transparent;
}
section.featured .sec-head .chap{ color:var(--violet); }
.law-statement{
font-size:clamp(19px, 2.8vw, 23px); color:#eef3ff;
border-left:3px solid; border-image:linear-gradient(180deg, var(--gold), var(--coral)) 1;
}
section.featured .law-statement{ border-image:linear-gradient(180deg, var(--violet), var(--teal)) 1; }
/* ---------- glass panels ---------- */
.sim, .step, .note, .quiz-q, .table-wrap{
background:linear-gradient(165deg, rgba(24,29,60,.66), rgba(9,11,28,.78));
border:1px solid rgba(124,146,230,.26); border-radius:16px;
backdrop-filter:blur(13px);
box-shadow:0 20px 50px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.06);
}
.sim{ padding:18px; }
canvas.stage{
background:radial-gradient(ellipse 120% 100% at 50% 38%, #0c1230 0%, #05060f 72%);
border:1px solid rgba(124,146,230,.3); border-radius:12px;
box-shadow:inset 0 0 60px rgba(10,8,40,.6);
}
.h-hodo{ height:clamp(340px, 50vw, 520px); }
.sim.hodo-panel{
border:1px solid transparent;
background:linear-gradient(165deg, rgba(24,29,60,.85), rgba(9,11,28,.9)) padding-box,
linear-gradient(120deg, rgba(47,232,216,.65), rgba(120,90,255,.65), rgba(216,115,255,.65), rgba(255,184,77,.55)) border-box;
box-shadow:0 24px 60px rgba(0,0,0,.5), 0 0 54px rgba(140,80,255,.20);
}
/* ---------- controls ---------- */
.btn{ border-radius:999px; background:rgba(30,38,74,.6); border:1px solid rgba(148,168,240,.4); transition:border-color .25s ease, color .25s ease, box-shadow .25s ease; }
.btn:hover{ box-shadow:0 0 16px rgba(47,232,216,.3); }
.btn.primary{ background:rgba(10,60,54,.55); border-color:rgba(47,232,216,.55); color:#9ff5ea; box-shadow:0 0 18px rgba(47,232,216,.22); }
#hodograph .btn.primary{ background:rgba(74,26,110,.5); border-color:rgba(216,115,255,.6); color:#f2ccff; box-shadow:0 0 18px rgba(216,115,255,.28); }
#hodograph .btn.primary:hover{ border-color:var(--violet); color:#fff; }
.seg{ border-radius:999px; border-color:rgba(148,168,240,.4); background:rgba(16,20,44,.5); }
.seg button.on{ background:linear-gradient(120deg, rgba(20,90,84,.85), rgba(16,60,80,.85)); color:#9ff5ea; box-shadow:inset 0 0 14px rgba(47,232,216,.25); }
#hodograph .seg button.on{ background:linear-gradient(120deg, rgba(96,36,140,.85), rgba(60,26,110,.85)); color:#f2ccff; box-shadow:inset 0 0 14px rgba(216,115,255,.3); }
.preset{ display:inline-flex; align-items:center; gap:7px; background:rgba(16,20,44,.45); transition:box-shadow .25s ease, color .25s ease, border-color .25s ease, background .25s ease; }
.preset .pdot{ width:8px; height:8px; border-radius:50%; flex:0 0 auto; }
.preset:hover{ box-shadow:0 0 14px rgba(140,170,255,.25); }
.preset.on{ background:linear-gradient(120deg, #ffd98a, var(--amber)); border-color:var(--amber); color:#23160a; box-shadow:0 0 20px rgba(246,183,60,.45); }
input[type="range"]{ background:linear-gradient(90deg, rgba(47,232,216,.55), rgba(120,90,255,.55)); background-clip:content-box; }
input[type="range"]::-webkit-slider-thumb{ background:#0b1120; border:3px solid var(--gold); box-shadow:0 0 12px rgba(255,184,77,.7); }
input[type="range"]::-moz-range-thumb{ background:#0b1120; border:3px solid var(--gold); box-shadow:0 0 12px rgba(255,184,77,.7); }
.scrub-wrap input[type="range"]{ background:linear-gradient(90deg, rgba(216,115,255,.5), rgba(47,232,216,.5)); background-clip:content-box; }
.scrub-wrap input[type="range"]::-webkit-slider-thumb{ border-color:var(--violet); box-shadow:0 0 12px rgba(216,115,255,.7); }
.scrub-wrap input[type="range"]::-moz-range-thumb{ border-color:var(--violet); box-shadow:0 0 12px rgba(216,115,255,.7); }
#hodograph label.toggle input{ accent-color:var(--violet); }
/* ---------- stats & checks ---------- */
.stat{ background:linear-gradient(160deg, rgba(32,40,80,.6), rgba(14,17,38,.65)); border:1px solid rgba(124,146,230,.25); border-radius:12px; box-shadow:inset 0 1px 0 rgba(255,255,255,.05); }
.stat .v{ font-size:17.5px; }
.stat .v.amber{ text-shadow:0 0 14px rgba(246,183,60,.45); }
.stat .v.teal{ text-shadow:0 0 14px rgba(47,232,216,.4); }
#hodograph .stat .v.teal{ color:var(--violet); text-shadow:0 0 14px rgba(216,115,255,.45); }
.stat.big .v{ font-size:30px; text-shadow:0 0 22px rgba(47,232,216,.55); }
.checkline{
background:linear-gradient(120deg, rgba(10,40,36,.55), rgba(10,16,34,.6));
border:1px solid rgba(67,209,124,.45); border-radius:12px;
box-shadow:0 0 24px rgba(67,209,124,.14), inset 0 0 24px rgba(67,209,124,.05);
}
.chip.done{ border-color:rgba(47,232,216,.4); }
.chip.now{ box-shadow:0 0 14px rgba(246,183,60,.35); }
table.planets tbody tr{ transition:background .25s ease; }
table.planets tbody tr:hover td{ background:rgba(40,54,110,.45); }
table.planets tbody tr.on td{ background:rgba(16,70,62,.5); }
.pdot-cell{ display:inline-block; width:9px; height:9px; border-radius:50%; margin-right:9px; vertical-align:1px; }
/* ---------- orbit shaper (hodograph) ---------- */
.orbit-shaper{
border:1px solid rgba(216,115,255,.38); border-radius:14px;
background:linear-gradient(150deg, rgba(60,26,110,.34), rgba(12,14,34,.5));
padding:14px 16px 14px; margin-bottom:16px;
box-shadow:0 0 30px rgba(150,80,255,.14), inset 0 1px 0 rgba(255,255,255,.05);
}
.os-head{ display:flex; justify-content:space-between; flex-wrap:wrap; gap:4px 14px; align-items:baseline; }
.os-title{ font-family:var(--disp); font-size:14.5px; font-weight:500; color:#f2ccff; text-shadow:0 0 14px rgba(216,115,255,.35); }
.os-read{ font-family:var(--mono); font-size:12.5px; color:var(--muted); }
.orbit-shaper .controls{ border-top:none; margin-top:8px; padding-top:4px; }
.os-stats{ display:grid; grid-template-columns:repeat(auto-fit, minmax(118px, 1fr)); gap:10px; margin-top:12px; }
/* ---------- speed thermometer & legend ---------- */
.thermo{
margin-top:16px; padding:13px 15px 11px; border-radius:12px;
border:1px solid rgba(216,115,255,.32);
background:linear-gradient(120deg, rgba(40,18,70,.45), rgba(10,14,34,.55));
}
.th-top{ display:flex; justify-content:space-between; align-items:baseline; margin-bottom:9px; }
.th-lab{ font-size:11.5px; font-weight:600; letter-spacing:.14em; text-transform:uppercase; color:#d9b8ff; }
.th-val{ font-family:var(--mono); font-size:17px; font-weight:600; color:#fff; text-shadow:0 0 14px rgba(255,150,80,.6); }
.th-track{ position:relative; height:12px; border-radius:999px;
background:linear-gradient(90deg, #3d7bff, #ffc44d 52%, #ff5a3c);
box-shadow:0 0 16px rgba(255,140,60,.25), inset 0 1px 3px rgba(0,0,0,.5); }
.th-fill{ position:absolute; top:0; bottom:0; left:0; width:0; border-radius:999px; background:rgba(255,255,255,.14); }
.th-marker{
position:absolute; top:50%; left:0; width:20px; height:20px; border-radius:50%;
transform:translate(-50%, -50%); background:#fff; border:3px solid #ff8a5c;
box-shadow:0 0 16px rgba(255,150,80,.85), 0 0 34px rgba(255,120,60,.4);
transition:left .12s linear;
}
.th-ends{ display:flex; justify-content:space-between; gap:10px; margin-top:8px; font-family:var(--mono); font-size:11.5px; color:var(--muted); }
.speed-legend{ display:flex; align-items:center; gap:10px; margin-top:12px; font-family:var(--mono); font-size:11.5px; color:var(--muted); }
.speed-legend .sl-bar{ flex:1 1 60px; height:7px; border-radius:999px; background:linear-gradient(90deg, #3d7bff, #ffc44d 52%, #ff5a3c); opacity:.85; }
/* ---------- derivation / callout ---------- */
.step .sn{ display:inline-block; padding:4px 11px; border-radius:999px; background:rgba(246,183,60,.12); border:1px solid rgba(246,183,60,.4); color:#ffd98a; box-shadow:0 0 14px rgba(246,183,60,.18); }
.step h3{ font-family:var(--disp); font-size:16px; font-weight:500; }
.note h3{ font-family:var(--disp); font-size:15px; font-weight:500; }
.eq{
background:linear-gradient(120deg, rgba(30,16,60,.65), rgba(8,14,30,.7));
border:1px solid rgba(216,115,255,.38); border-radius:12px;
box-shadow:0 0 26px rgba(150,80,255,.16), inset 0 0 26px rgba(120,60,255,.06);
font-size:17.5px; padding:13px 12px;
}
.callout{
border:1px solid rgba(216,115,255,.38); border-radius:14px; color:#e4d9f5;
background:linear-gradient(160deg, rgba(44,20,78,.5), rgba(8,18,24,.6));
box-shadow:0 0 40px rgba(150,70,255,.14);
}
.callout strong{ color:#f0c8ff; }
/* ---------- quiz ---------- */
.qdots{ display:flex; gap:8px; margin:0 0 16px; }
.qdots .qd{ width:11px; height:11px; border-radius:50%; border:2px solid rgba(148,168,240,.5); transition:all .3s ease; }
.qdots .qd.ok{ background:var(--good); border-color:var(--good); box-shadow:0 0 12px rgba(67,209,124,.7); }
.qdots .qd.no{ background:var(--bad); border-color:var(--bad); box-shadow:0 0 12px rgba(255,107,107,.6); }
.opt{ border-radius:12px; transition:border-color .25s ease, box-shadow .25s ease, background .25s ease; }
.opt:hover:not([disabled]){ border-color:rgba(160,190,255,.6); box-shadow:0 0 14px rgba(110,140,255,.2); }
.opt.right{ box-shadow:0 0 18px rgba(67,209,124,.3); }
.opt.wrong{ box-shadow:0 0 18px rgba(255,107,107,.25); }
/* ---------- timeline ---------- */
.timeline{ position:relative; padding-left:24px; }
.timeline::before{
content:""; position:absolute; left:5px; top:8px; bottom:8px; width:2px; border-radius:2px;
background:linear-gradient(180deg, var(--gold), var(--violet), var(--teal));
opacity:.6; box-shadow:0 0 12px rgba(150,110,255,.4);
}
.timeline li{ position:relative; }
.timeline li::before{
content:""; position:absolute; left:-23px; top:50%; margin-top:-4px;
width:8px; height:8px; border-radius:50%; background:#ffd98a;
box-shadow:0 0 10px var(--gold), 0 0 22px rgba(246,183,60,.55);
}
.timeline .yr{ background:rgba(246,183,60,.1); border:1px solid rgba(246,183,60,.35); border-radius:999px; padding:3px 0; text-align:center; align-self:center; }
/* ---------- scroll reveal ---------- */
.reveal{ opacity:.65; transform:translateY(24px); transition:opacity .8s ease, transform .8s cubic-bezier(.2,.7,.2,1); }
.reveal.in{ opacity:1; transform:none; }
@media (prefers-reduced-motion: reduce){
.reveal{ opacity:1; transform:none; transition:none; }
.scroll-cue i{ animation:none; }
.law-card{ transition:none; } .law-card:hover{ transform:none; }
.th-marker{ transition:none; }
}
@media (max-width:640px){
.hero-content{ padding:28px 20px 58px; }
.stat.big .v{ font-size:25px; }
}
</style>
</head>
<body>
<canvas id="bgStars" aria-hidden="true"></canvas>
<nav class="chapters" aria-label="Chapters">
<div class="inner">
<a href="#law1">1 · Ellipse</a>
<a href="#law2">2 · Equal areas</a>
<a href="#law3">3 · Harmonic law</a>
<a href="#hodograph" class="hot">★ The Hodograph</a>
<a href="#why">Why a circle?</a>
<a href="#quiz">Quiz</a>
<a href="#history">History & sources</a>
</div>
</nav>
<div class="wrap">
<header class="hero">
<div class="hero-stage">
<canvas class="hero-cv" id="heroCv" aria-hidden="true"></canvas>
<div class="hero-shade"></div>
<div class="hero-content">
<p class="kicker">Johannes Kepler · 1609–1619</p>
<h1>Three laws of planetary motion — and the <em>perfect circle</em> hiding in every orbit</h1>
<p class="lede">Kepler found the rules by fitting Tycho Brahe's observations of Mars. Each law below is a working simulation you can bend with your own hands — change the orbit, and watch what stays true.</p>
<div class="hero-chips">
<span class="hchip"><i></i>Earth · perihelion <b>30.29 km/s</b></span>
<span class="hchip"><i></i>Earth · aphelion <b>29.29 km/s</b></span>
<span class="hchip"><i></i>Halley · perihelion <b>54.50 km/s</b></span>
</div>
</div>
<div class="scroll-cue" aria-hidden="true"><span>Scroll</span><i></i></div>
</div>
<div class="law-cards">
<article class="law-card">
<canvas class="mini-cv" id="mini1" aria-hidden="true"></canvas>
<p><span class="n">LAW 1</span><span>The orbit of a planet is an <strong>ellipse</strong> with the Sun at one of the two foci.</span></p>
</article>
<article class="law-card">
<canvas class="mini-cv" id="mini2" aria-hidden="true"></canvas>
<p><span class="n">LAW 2</span><span>A line joining a planet and the Sun <strong>sweeps out equal areas</strong> during equal intervals of time.</span></p>
</article>
<article class="law-card">
<canvas class="mini-cv" id="mini3" aria-hidden="true"></canvas>
<p><span class="n">LAW 3</span><span>The square of a planet's orbital period is <strong>proportional to the cube</strong> of its orbit's semi-major axis: T² ∝ a³.</span></p>
</article>
</div>
<div class="surprise">
<span class="tag">The headline surprise</span>
<p>Take the planet's <strong>velocity arrow</strong> at every instant, slide them all so their tails sit on one common origin, and watch where the tip travels. It does not wander, spiral or smear — it draws a <strong>perfect circle</strong>. That circle is called the <strong>hodograph</strong>, and it is the largest chapter on this page.</p>
</div>
<p class="method">Every motion here is a true Kepler solver — mean anomaly M advances uniformly, then Kepler's equation M = E − e·sin E is solved by Newton iteration each frame. No uniform circular shortcuts.</p>
</header>
<!-- ================= LAW 1 ================= -->
<section id="law1">
<div class="sec-head"><span class="bignum" aria-hidden="true">01</span><span class="chap">Law 1 · 1609</span><h2>The ellipse, with the Sun at a focus</h2></div>
<p class="law-statement">“The orbit of every planet is an ellipse with the Sun at one of the two foci.”</p>
<div class="prose">
<p>Not a circle, and the Sun is <strong>not at the centre</strong> — it sits at one focus, F₁. The second focus, F₂, is empty space, yet it is geometrically real: for every point on an ellipse, the distances to the two foci add to the same constant, r₁ + r₂ = 2a. Watch the live check under the simulation — it holds at every instant, for every eccentricity.</p>
<p>Drag <strong>e</strong> toward 0.9 and the orbit stretches into a comet-like sliver; set e = 0 and the two foci merge into the centre of a circle. The shape is set by just two numbers: the semi-major axis <strong>a</strong> and the eccentricity <strong>e</strong>.</p>
</div>
<div class="sim">
<div class="cap"><span>Position space · perifocal frame, x toward perihelion</span><span class="r" id="cap1"></span></div>
<canvas class="stage h-law" id="cv1"></canvas>
<div class="controls">
<div class="grp"><button class="btn" id="play1" type="button">❚❚ Pause</button></div>
<div class="slider-grp"><label class="lab" for="eRange1">Eccentricity e</label><input type="range" id="eRange1" min="0" max="970" value="17" /><span class="val" id="eVal1"></span></div>
<div class="slider-grp"><label class="lab" for="aRange1">Semi-major a</label><input type="range" id="aRange1" min="0" max="1000" value="0" /><span class="val" id="aVal1"></span></div>
<div class="grp"><span class="ctl-lab">Presets</span><span class="presets" id="presets1"></span></div>
</div>
<div class="stats">
<div class="stat"><span class="k">Perihelion r_min = a(1−e)</span><span class="v amber" id="s1_rmin"></span></div>
<div class="stat"><span class="k">Aphelion r_max = a(1+e)</span><span class="v amber" id="s1_rmax"></span></div>
<div class="stat"><span class="k">Semi-minor b = a√(1−e²)</span><span class="v" id="s1_b"></span></div>
<div class="stat"><span class="k">Semi-latus p = a(1−e²)</span><span class="v" id="s1_p"></span></div>
<div class="stat"><span class="k">Focus offset a·e</span><span class="v" id="s1_off"></span></div>
<div class="stat"><span class="k">Period T = a^1.5</span><span class="v" id="s1_T"></span></div>
</div>
<div class="checkline">live check · r₁ (to Sun) <b id="s1_r1"></b> + r₂ (to empty focus) <b id="s1_r2"></b> = <b id="s1_sum"></b> vs 2a = <b id="s1_2a"></b> · difference <span class="ok" id="s1_diff"></span></div>
</div>
</section>
<!-- ================= LAW 2 ================= -->
<section id="law2">
<div class="sec-head"><span class="bignum" aria-hidden="true">02</span><span class="chap">Law 2 · 1609</span><h2>Equal areas in equal times</h2></div>
<p class="law-statement">“A line joining a planet and the Sun sweeps out equal areas during equal intervals of time.”</p>
<div class="prose">
<p>The simulation below slices one orbit into <strong>12 equal time steps</strong> of T/12 each and shades the sector the Sun–planet line sweeps in each step. Near the Sun the sector is short and fat; far away it is long and thin — but every sector's area, computed numerically from the simulated positions, comes out the same. That is why the planet <strong>visibly hurries</strong> near perihelion and dawdles near aphelion: the area rate dA/dt = h/2 never changes, so a shorter radius must be swept faster.</p>
<p>In modern language this is conservation of angular momentum: h = r²·dν/dt is constant because gravity pulls along the radius and exerts no torque.</p>
</div>
<div class="sim">
<div class="cap"><span>Area sweep · 12 sectors of T/12 · same orbit as Law 1</span><span class="r" id="cap2"></span></div>
<canvas class="stage h-law" id="cv2"></canvas>
<div class="controls">
<div class="grp"><button class="btn" id="play2" type="button">❚❚ Pause</button><button class="btn" id="restart2" type="button">↺ Restart sweep</button></div>
<div class="grp"><span class="ctl-lab">Uses the e and a set in Law 1 / the Hodograph</span></div>
</div>
<div class="stats">
<div class="stat"><span class="k">dA/dt = h/2 (constant)</span><span class="v teal" id="s2_dadt"></span></div>
<div class="stat"><span class="k">Distance r now</span><span class="v" id="s2_r"></span></div>
<div class="stat"><span class="k">Speed v now</span><span class="v coral" id="s2_v"></span></div>
<div class="stat"><span class="k" id="s2_sector_k">Sector in progress</span><span class="v" id="s2_sector"></span></div>
<div class="stat"><span class="k">Largest area deviation</span><span class="v good" id="s2_dev"></span></div>
</div>
<div class="speed-legend" aria-hidden="true"><span>slow</span><div class="sl-bar"></div><span>fast</span><span>· trail colour = speed</span></div>
<div class="chips" id="areas2"></div>
</div>
</section>
<!-- ================= LAW 3 ================= -->
<section id="law3">
<div class="sec-head"><span class="bignum" aria-hidden="true">03</span><span class="chap">Law 3 · 1619</span><h2>The harmonic law: T² ∝ a³</h2></div>
<p class="law-statement">“The square of a planet's orbital period is proportional to the cube of the length of the semi-major axis of its orbit.”</p>
<div class="prose">
<p>Kepler published this in <em>Harmonices Mundi</em> (1619), a decade after the first two laws. It is a single rule for the whole system: measure any planet's distance and period, and a³/T² comes out the same — about <strong>7.496 × 10⁻⁶ AU³/day²</strong> — because the constant is set by the Sun's mass alone. <strong>Tap any planet</strong> in the table to load its a and e into all the simulators on this page.</p>
</div>
<div class="table-wrap">
<table class="planets">
<thead><tr><th>Planet</th><th>a (AU)</th><th>T (days)</th><th>T (years)</th><th>e</th><th>a³/T² (10⁻⁶ AU³/day²)</th></tr></thead>
<tbody id="tbody3"></tbody>
</table>
</div>
<p class="load-note" id="loadNote"></p>
<div class="sim">
<div class="cap"><span>Log–log chart · period vs distance</span><span class="r">slope 3/2 — tap a point to load it</span></div>
<canvas class="stage h-chart" id="cv3"></canvas>
<div class="prose" style="margin-top:12px">
<p>On logarithmic axes, T = a^1.5 becomes a straight line of slope 3/2. All eight planets sit on it — Mercury at the fast, close-in end, Neptune taking 165 years at the far end. A slope of 1 would mean T ∝ a; nature chose 3/2, and that exponent is what Newton later traced to the inverse-square law.</p>
</div>
<div class="controls">
<div class="slider-grp"><label class="lab" for="calcA">Try any a</label><input type="range" id="calcA" min="0" max="1000" value="300" /><span class="val" id="calcAval"></span></div>
<div class="grp"><span class="ctl-lab">Period T = a^1.5</span></div>
</div>
<div class="stats">
<div class="stat"><span class="k">Semi-major axis a</span><span class="v amber" id="calc_a"></span></div>
<div class="stat big"><span class="k">Period T</span><span class="v teal" id="calc_T"></span></div>
<div class="stat"><span class="k">Period T</span><span class="v" id="calc_days"></span></div>
<div class="stat"><span class="k">Check a³/T²</span><span class="v good" id="calc_K"></span></div>
</div>
</div>
</section>
<!-- ================= HODOGRAPH ================= -->
<section id="hodograph" class="featured">
<div class="sec-head"><span class="bignum" aria-hidden="true">04</span><span class="chap">Featured · The Hodograph</span><h2>Position is an ellipse. Velocity is a circle.</h2></div>
<div class="prose">
<p>Here is the construction, running live and synchronised. On the <strong>left</strong>, ordinary position space: the planet rides its ellipse, the blue arrow is its position vector <strong>r</strong>, the teal arrow at the planet is its velocity <strong>v</strong>, tangent to the orbit. On the <strong>right</strong>, velocity space: the <em>same</em> velocity arrow, picked up and re-drawn with its tail pinned to a fixed origin O. Only the arrow's tip is free to move — and as the planet completes its ellipse, the tip completes a <strong>circle</strong>.</p>
<p><strong>Read the right panel carefully:</strong> its axes are velocities (km/s), not positions. The circle is <em>not</em> the orbit — the planet never travels around it in space. It is the orbit's shadow in velocity space, and its geometry encodes the whole motion: the circle's radius R = μ/h is set by angular momentum, and its centre is displaced from the origin by exactly e·R. The fading ribbon on the right panel is the <strong>velocity history</strong>: every velocity tip from the last full orbit, each coloured by its own speed, with a dot every T/24 — the dots bunch where the tip lingers and spread out where it rushes. Drag the <strong>eccentricity slider</strong> above the panels to stretch the orbit from a circle into a comet-like ellipse and watch the history redraw itself on the new circle.</p>
</div>
<div class="sim hodo-panel">
<div class="orbit-shaper">
<div class="os-head">
<span class="os-title">Shape the orbit — stretch it into an ellipse</span>
<span class="os-read" id="osRead"></span>
</div>
<div class="controls">
<div class="slider-grp"><label class="lab" for="eRange2">Eccentricity e</label><input type="range" id="eRange2" min="0" max="970" value="17" /><span class="val" id="eVal2"></span></div>
<div class="slider-grp"><label class="lab" for="aRange2">Semi-major a</label><input type="range" id="aRange2" min="0" max="1000" value="0" /><span class="val" id="aVal2"></span></div>
<div class="grp"><span class="ctl-lab">Presets</span><span class="presets" id="presets2"></span></div>
</div>
<div class="os-stats">
<div class="stat"><span class="k">Eccentricity e</span><span class="v amber" id="ho_e"></span></div>
<div class="stat"><span class="k">r_min = a(1−e)</span><span class="v" id="ho_rmin"></span></div>
<div class="stat"><span class="k">r_max = a(1+e)</span><span class="v" id="ho_rmax"></span></div>
<div class="stat"><span class="k">v perihelion = R(1+e)</span><span class="v coral" id="ho_vperi"></span></div>
<div class="stat"><span class="k">v aphelion = R(1−e)</span><span class="v teal" id="ho_vaph"></span></div>
</div>
</div>
<div class="duo">
<div>
<div class="cap"><span>Left · Position space</span><span class="r">orbit = ellipse</span></div>
<canvas class="stage h-hodo" id="cvP"></canvas>
</div>
<div>
<div class="cap"><span>Right · Velocity space</span><span class="r">hodograph = circle</span></div>
<canvas class="stage h-hodo" id="cvV"></canvas>
</div>
</div>
<div class="thermo" aria-hidden="true">
<div class="th-top"><span class="th-lab">Speed now</span><span class="th-val" id="thVal">—</span></div>
<div class="th-track"><div class="th-fill" id="thFill"></div><div class="th-marker" id="thMarker"></div></div>
<div class="th-ends"><span id="thMin"></span><span id="thMax"></span></div>
</div>
<div class="speed-legend" aria-hidden="true"><span>slow</span><div class="sl-bar"></div><span>fast</span><span>· planet & trail colour = speed</span></div>
<div class="controls">
<div class="grp"><button class="btn primary" id="playH" type="button">❚❚ Pause</button></div>
<div class="scrub-wrap"><label class="lab" for="scrubH">Time</label><input type="range" id="scrubH" min="0" max="1000" value="0" /></div>
<div class="grp"><span class="ctl-lab">Speed</span>
<span class="seg" id="speedSeg">
<button type="button" data-speed="0.25">0.25×</button><button type="button" data-speed="0.5">0.5×</button><button type="button" data-speed="1" class="on">1×</button><button type="button" data-speed="2">2×</button><button type="button" data-speed="4">4×</button>
</span>
</div>
</div>
<div class="controls">
<label class="toggle"><input type="checkbox" id="tgAccel" checked /> Acceleration arrow</label>
<label class="toggle"><input type="checkbox" id="tgCircle" checked /> Hodograph circle</label>
<label class="toggle"><input type="checkbox" id="tgCentre" checked /> Centre + offset e·R</label>
<label class="toggle"><input type="checkbox" id="tgTrail" checked /> Velocity history</label>
<div class="grp"><button class="btn" id="clearHist" type="button">Clear history</button></div>
<div class="grp"><span class="ctl-lab">Sampled arrows</span>
<span class="seg" id="sampSeg">
<button type="button" data-n="0" class="on">Off</button><button type="button" data-n="8">8</button><button type="button" data-n="24">24</button>
</span>
</div>
<div class="grp"><button class="btn" id="buildBtn" type="button">▦ Build the circle, step by step</button></div>
</div>
<div class="controls build-ui" id="buildUI">
<div class="grp"><button class="btn" id="bPrev" type="button">← Prev sample</button><button class="btn primary" id="bNext" type="button">Next sample →</button><button class="btn" id="bExit" type="button">Exit build mode</button></div>
<div class="grp"><span id="bLabel" style="font-family:var(--mono); font-size:14px; color:var(--teal)"></span></div>
</div>
<div class="stats">
<div class="stat"><span class="k">True anomaly ν</span><span class="v" id="hNu"></span></div>
<div class="stat"><span class="k">Distance r</span><span class="v" id="hR"></span></div>
<div class="stat"><span class="k">Speed v</span><span class="v coral" id="hV"></span></div>
<div class="stat"><span class="k">v_x</span><span class="v teal" id="hVx"></span></div>
<div class="stat"><span class="k">v_y</span><span class="v teal" id="hVy"></span></div>
<div class="stat"><span class="k">Hodograph radius R = μ/h</span><span class="v" id="hRad"></span></div>
<div class="stat"><span class="k">Centre offset e·R</span><span class="v" id="hOff"></span></div>
<div class="stat"><span class="k">Circle check |tip→centre| − R</span><span class="v good" id="hCheck"></span></div>
</div>
<div class="checkline">extremes · perihelion speed R(1+e) = <b id="hPeri"></b> · aphelion speed R(1−e) = <b id="hAph"></b> · ratio (1+e)/(1−e) = <b id="hRatio"></b></div>
</div>
<div class="callout">
<p><strong>The one reading to take away:</strong> on the hodograph, distance from the origin <em>is</em> speed. So the tip's <strong>farthest</strong> point from O is <strong>perihelion</strong> — the planet at its fastest — and its <strong>nearest</strong> point is <strong>aphelion</strong>, the slowest. For a near-circular orbit like Earth's, the origin sits almost at the circle's centre and the speed barely changes (30.29 vs 29.29 km/s). Load <strong>Halley's comet</strong> (e = 0.967) and the origin nearly touches the circle: the tip swings from 54.5 km/s at perihelion down to under 1 km/s at aphelion.</p>
<p>And once more, because it is the whole point: <strong>the axes on the right are velocities in km/s, not positions. The circle is not the orbit.</strong> The orbit is the ellipse on the left; the circle is what the velocity vector draws while the planet walks the ellipse.</p>
</div>
</section>
<!-- ================= WHY A CIRCLE ================= -->
<section id="why">
<div class="sec-head"><span class="chap">The Proof</span><h2>Why a circle? Three steps</h2></div>
<div class="prose">
<p>Nothing about an ellipse suggests a circle hiding inside it, yet the proof is short. Work in the perifocal frame: x-axis toward perihelion, y-axis 90° ahead in the direction of motion, ν the true anomaly, μ = GM<sub>☉</sub> and h the (constant) specific angular momentum.</p>
</div>
<div class="steps">
<div class="step">
<span class="sn">Step 1</span>
<h3>Trade time for angle</h3>
<p>Gravity is the only force, and it points at the Sun: <strong>a</strong> = d<strong>v</strong>/dt = −(μ/r²)·<strong>r̂</strong>. By Law 2, h = r²·dν/dt is constant, so the clock can be re-read as an angle: d/dt = (h/r²)·d/dν.</p>
<div class="eq">d<strong>v</strong>/dt = −(μ/r²) <strong>r̂</strong>, h = r² ν̇ = const</div>
</div>
<div class="step">
<span class="sn">Step 2</span>
<h3>Differentiate with respect to ν</h3>
<p>The r² cancels exactly — this cancellation is the inverse-square law doing its one trick. Integrating the rotating unit vector <strong>r̂</strong> = (cos ν, sin ν) then gives <strong>v</strong> as plain sines and cosines, with one constant of integration: the eccentricity e.</p>
<div class="eq">d<strong>v</strong>/dν = −(μ/h) <strong>r̂</strong> ⇒ <strong>v</strong>(ν) = (μ/h)·(−sin ν, e + cos ν)</div>
</div>
<div class="step">
<span class="sn">Step 3</span>
<h3>Read off the circle</h3>
<p>Set R = μ/h. Then v<sub>x</sub> = −R·sin ν and v<sub>y</sub> = eR + R·cos ν, so the tip satisfies a circle equation identically, for every ν: radius R, centre displaced e·R along the v<sub>y</sub> axis. At e = 0 the centre lands on the origin and the speed never changes.</p>
<div class="eq">v<sub>x</sub>² + (v<sub>y</sub> − eR)² = R², R = μ/h</div>
</div>
</div>
<div class="note-grid">
<div class="note">
<h3>The hidden conservation law</h3>
<p>Why doesn't the circle's centre drift as the planet moves? The offset is locked to the <strong>eccentricity vector</strong> — the Laplace–Runge–Lenz vector — a conserved quantity that points toward perihelion and keeps the ellipse from precessing. It exists <em>only</em> for an inverse-square force. Perturb the force law even slightly and the LRL vector slowly rotates: the hodograph stops being an exact circle and the orbit stops closing. The perfect circle is the fingerprint of 1/r².</p>
<p>It is also why the result feels miraculous: energy and angular momentum alone don't fix the orbit's orientation. The LRL vector is an extra, "hidden" symmetry of the Kepler problem — in quantum mechanics the same symmetry explains the degeneracy of the hydrogen spectrum.</p>
</div>
<div class="note">
<h3>Who found it — and what about e ≥ 1?</h3>
<p><strong>William Rowan Hamilton</strong> presented the hodograph to the Royal Irish Academy in 1846 and named it from the Greek <em>hodos</em> (path) and <em>graphein</em> (to write): the "path-writer" of the velocity vector. Möbius arrived at the same construction independently in the same decade, and <strong>Richard Feynman</strong> famously re-derived the circle from scratch in his 1964 lecture on planetary motion — the "lost lecture," reconstructed and published decades later.</p>
<p>Only bound (elliptical) orbits are simulated on this page, but the geometry extends: a <strong>parabolic</strong> orbit (e = 1) still gives a circle — one that passes exactly through the origin, the tip reaching zero velocity at infinity — while a <strong>hyperbolic</strong> orbit (e > 1) traces only an <strong>arc</strong> of its circle, because ν never sweeps the full turn.</p>
</div>
</div>
</section>
<!-- ================= QUIZ ================= -->
<section id="quiz">
<div class="sec-head"><span class="chap">Check Yourself</span><h2>Five questions</h2></div>
<p class="quiz-score" id="quizScore">Answered 0 of 5 · 0 correct</p>
<div class="qdots" id="qDots" aria-hidden="true"></div>
<div id="quizWrap"></div>
</section>
<!-- ================= HISTORY & SOURCES ================= -->
<section id="history">
<div class="sec-head"><span class="chap">History</span><h2>From Brahe's tables to Hamilton's circle</h2></div>
<ul class="timeline">
<li><span class="yr">1609</span><span class="ev"><b>Astronomia Nova.</b> Kepler publishes the first two laws — the elliptical orbit and the equal-area rule — extracted from Tycho Brahe's precise Mars observations, after years of failing to fit Mars with circles.</span></li>
<li><span class="yr">1619</span><span class="ev"><b>Harmonices Mundi.</b> The third law appears: T² ∝ a³, one harmonic rule binding every planet to the same constant.</span></li>
<li><span class="yr">1621</span><span class="ev"><b>Epitome Astronomiae Copernicanae.</b> The laws in near-modern form — and Kepler notes the third law also governs the four bright moons of Jupiter.</span></li>
<li><span class="yr">1687</span><span class="ev"><b>Newton's Principia.</b> All three laws derived from universal gravitation. Newton also saw that the second law follows from any central force; the first and third specifically need the inverse-square law.</span></li>
<li><span class="yr">1846</span><span class="ev"><b>Hamilton's hodograph.</b> W. R. Hamilton shows the Royal Irish Academy that the tip of the velocity vector traces a circle — and names the construction. Möbius had found it independently in the same decade.</span></li>
<li><span class="yr">1964</span><span class="ev"><b>Feynman's lost lecture.</b> Richard Feynman re-derives the circular hodograph in a lecture on planetary motion at Caltech; the recording and notes were lost, then reconstructed and published in the 1990s.</span></li>
</ul>
<div class="sec-head" style="margin-top:34px"><span class="chap">Sources</span><h2>References & constants</h2></div>
<ul class="sources">
<li><span class="sk">Primary reference</span><a href="https://en.wikipedia.org/wiki/Kepler%27s_laws_of_planetary_motion" target="_blank" rel="noopener">Kepler's laws of planetary motion — Wikipedia</a></li>
<li><span class="sk">The hodograph</span><a href="https://en.wikipedia.org/wiki/Hodograph" target="_blank" rel="noopener">Hodograph — Wikipedia</a></li>
<li><span class="sk">The hidden symmetry</span><a href="https://en.wikipedia.org/wiki/Laplace%E2%80%93Runge%E2%80%93Lenz_vector" target="_blank" rel="noopener">Laplace–Runge–Lenz vector — Wikipedia</a></li>
<li><span class="sk">Constants used</span><span style="color:var(--muted)">μ<sub>☉</sub> = 1.32712440018 × 10¹¹ km³/s² · 1 AU = 149,597,870.7 km · T = a^1.5 years. Planet a, T and e are the modern values tabulated in Law 3 (a³/T² ≈ 7.496 × 10⁻⁶ AU³/day² for all eight).</span></li>
</ul>
<footer>Built as an interactive explainer. All simulations solve Kepler's equation M = E − e·sin E by Newton iteration; velocities use the perifocal formulas v<sub>x</sub> = −(μ/h)·sin ν, v<sub>y</sub> = (μ/h)·(e + cos ν), with h = √(μ·a·(1−e²)).</footer>
</section>
</div>
<script>
'use strict';
/* ============================================================
Kepler core — true solver, no uniform-motion shortcuts.
mu_sun in km^3/s^2, AU in km, times in years, a in AU.
Perifocal frame: x toward perihelion, y 90 deg ahead.
============================================================ */
var MU = 1.32712440018e11;
var AU = 149597870.7;
var TAU = Math.PI * 2;
var SEC_PER_YEAR = 365.2564 * 86400;
function periodY(a){ return Math.pow(a, 1.5); }
function solveE(M, e){
M = ((M % TAU) + TAU) % TAU;
var E = (e < 0.8) ? M + e * Math.sin(M) : Math.PI;
for (var i = 0; i < 60; i++){
var d = (E - e * Math.sin(E) - M) / (1 - e * Math.cos(E));
E -= d;
if (Math.abs(d) < 1e-13) break;
}
return E;
}
/* Full state at time t (years since perihelion passage). */
function orbitAt(a, e, t){
var T = periodY(a);
var M = TAU * (t / T);
var E = solveE(M, e);
var nu = 2 * Math.atan2(Math.sqrt(1 + e) * Math.sin(E / 2), Math.sqrt(1 - e) * Math.cos(E / 2));
if (nu < 0) nu += TAU;
var r = a * (1 - e * Math.cos(E));
var h = Math.sqrt(MU * a * AU * (1 - e * e)); /* km^2/s */
var R = MU / h; /* hodograph radius, km/s */
var vx = -R * Math.sin(nu);
var vy = R * (e + Math.cos(nu));
return {
T: T, M: ((M % TAU) + TAU) % TAU, E: E, nu: nu, r: r, h: h, R: R,
vx: vx, vy: vy, v: Math.hypot(vx, vy),
x: r * Math.cos(nu), y: r * Math.sin(nu),
b: a * Math.sqrt(1 - e * e)
};
}
/* ---------- formatting ---------- */
function f(x, d){ return x.toFixed(d); }
function $(id){ return document.getElementById(id); }
/* ---------- palette (mirrors CSS) ---------- */
var COL = {
ink:'#e9edf5', muted:'#a3b1c8', faint:'#6b7a94', line:'#22314f',
amber:'#f6b73c', teal:'#2fd4c4', coral:'#ff7a59', blue:'#6f9dff',
pink:'#ef6a9a', good:'#43d17c', orbit:'#7fe7ff', grid:'#1b2a52',
violet:'#d873ff', magenta:'#f06bd8', gold:'#ffb84d'
};
var PLANET_COL = {
Mercury:'#c9b8a6', Venus:'#f2c879', Earth:'#5db9ff', Mars:'#ff8a5c',
Jupiter:'#e8b07d', Saturn:'#f0d48a', Uranus:'#7fe3d0', Neptune:'#7d9bff',
Halley:'#cfd8ea', Circle:'#2fe8d8', Eccentric:'#ff7a59'
};
function mixc(c1, c2, t){
function p(c){ return [parseInt(c.slice(1, 3), 16), parseInt(c.slice(3, 5), 16), parseInt(c.slice(5, 7), 16)]; }
var A = p(c1), B = p(c2);
return 'rgb(' + Math.round(A[0] + (B[0] - A[0]) * t) + ',' + Math.round(A[1] + (B[1] - A[1]) * t) + ',' + Math.round(A[2] + (B[2] - A[2]) * t) + ')';
}
/* speed colour language: blue (slow) -> gold -> red-orange (fast) */
function speedColor(v, vmin, vmax){
var t = vmax > vmin ? (v - vmin) / (vmax - vmin) : 0;
t = Math.max(0, Math.min(1, t));
return t < 0.5 ? mixc('#3d7bff', '#ffc44d', t * 2) : mixc('#ffc44d', '#ff5a3c', (t - 0.5) * 2);
}
/* ---------- canvas helper: DPR-aware, resize-safe ---------- */
function makeCanvas(id){
var cv = $(id);
var o = { cv: cv, ctx: cv.getContext('2d'), w: 300, h: 300, stars: [] };
function seedStars(){
o.stars = [];
var n = Math.round(o.w * o.h / 16000);
for (var i = 0; i < n; i++) o.stars.push([Math.random() * o.w, Math.random() * o.h, Math.random() * 0.5 + 0.12, Math.random() < 0.12 ? 1.6 : 1]);
}
function resize(){
var r = cv.getBoundingClientRect();
if (r.width < 40) return;
var dpr = Math.min(2, window.devicePixelRatio || 1);
var W = Math.round(r.width), H = Math.round(r.height);
if (W !== o.w || H !== o.h || cv.width !== Math.round(W * dpr)){
o.w = W; o.h = H;
cv.width = Math.round(W * dpr); cv.height = Math.round(H * dpr);
o.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
seedStars();
}
}
if (window.ResizeObserver) new ResizeObserver(resize).observe(cv);
window.addEventListener('resize', resize);
resize();
o.resize = resize;
return o;
}
function drawStars(o){
var ctx = o.ctx;
ctx.save();
for (var i = 0; i < o.stars.length; i++){
ctx.globalAlpha = o.stars[i][2];
ctx.fillStyle = '#cdd8ea';
ctx.fillRect(o.stars[i][0], o.stars[i][1], o.stars[i][3], o.stars[i][3]);
}
ctx.restore();
}
function arrow(ctx, x1, y1, x2, y2, color, w){
var ang = Math.atan2(y2 - y1, x2 - x1);
var hl = Math.max(7, w * 3.4);
ctx.save();
ctx.strokeStyle = color; ctx.fillStyle = color; ctx.lineWidth = w;
ctx.shadowColor = color; ctx.shadowBlur = 6;
ctx.lineCap = 'round';
ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke();
ctx.beginPath();
ctx.moveTo(x2, y2);
ctx.lineTo(x2 - hl * Math.cos(ang - 0.42), y2 - hl * Math.sin(ang - 0.42));
ctx.lineTo(x2 - hl * Math.cos(ang + 0.42), y2 - hl * Math.sin(ang + 0.42));
ctx.closePath(); ctx.fill();
ctx.restore();
}
function label(ctx, text, x, y, color, align, size){
ctx.save();
ctx.font = '600 ' + (size || 11.5) + 'px "IBM Plex Sans", sans-serif';
ctx.fillStyle = color || COL.muted;
ctx.textAlign = align || 'left';
ctx.textBaseline = 'middle';
ctx.fillText(text, x, y);
ctx.restore();
}
function leader(ctx, x1, y1, x2, y2){
ctx.save(); ctx.strokeStyle = 'rgba(163,177,200,.45)'; ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); ctx.restore();
}
/* ============================================================
Shared orbital parameters: one state, many controls.
============================================================ */
var state = { a: 1, e: 0.0167 };
var A_MIN = 0.35, A_MAX = 40;
function aToSlider(a){ return Math.round(1000 * (Math.log(a) - Math.log(A_MIN)) / (Math.log(A_MAX) - Math.log(A_MIN))); }
function sliderToA(v){ return Math.exp(Math.log(A_MIN) + (v / 1000) * (Math.log(A_MAX) - Math.log(A_MIN))); }
var PLANETS = [
{ name:'Mercury', a:0.38710, T:87.9693, e:0.2056 },
{ name:'Venus', a:0.72333, T:224.7008, e:0.0068 },
{ name:'Earth', a:1.00000, T:365.2564, e:0.0167 },
{ name:'Mars', a:1.52366, T:686.9796, e:0.0934 },
{ name:'Jupiter', a:5.20336, T:4332.8201, e:0.0489 },
{ name:'Saturn', a:9.53707, T:10775.599, e:0.0565 },
{ name:'Uranus', a:19.1913, T:30687.153, e:0.0457 },
{ name:'Neptune', a:30.0690, T:60190.03, e:0.0113 }
];
var PRESETS1 = PLANETS.slice(0, 5).concat([{ name:'Halley', a:17.8, T:27163, e:0.967 }]);
var PRESETS2 = [
{ name:'Circle', a:null, e:0, keep:true },
{ name:'Earth', a:1.0, e:0.0167 },
{ name:'Mars', a:1.52366, e:0.0934 },
{ name:'Mercury', a:0.38710, e:0.2056 },
{ name:'Eccentric', a:null, e:0.6, keep:true },
{ name:'Halley', a:17.8, e:0.967 }
];
var activePreset = 'Earth';
var eSliders = [], aSliders = [], eVals = [], aVals = [];
function bindParamUI(){
[['eRange1','eVal1','aRange1','aVal1'], ['eRange2','eVal2','aRange2','aVal2']].forEach(function(ids){
eSliders.push($(ids[0])); eVals.push($(ids[1])); aSliders.push($(ids[2])); aVals.push($(ids[3]));
});
eSliders.forEach(function(s){ s.addEventListener('input', function(){ setParams(state.a, s.value / 1000, 'slider'); }); });
aSliders.forEach(function(s){ s.addEventListener('input', function(){ setParams(sliderToA(+s.value), state.e, 'slider'); }); });
}
function buildPresets(elId, list){
var el = $(elId);
list.forEach(function(p){
var b = document.createElement('button');
b.type = 'button'; b.className = 'preset'; b.dataset.name = p.name;
b.innerHTML = '<span class="pdot" style="background:' + (PLANET_COL[p.name] || '#a3b1c8') + ';box-shadow:0 0 8px ' + (PLANET_COL[p.name] || '#a3b1c8') + '"></span>' + p.name;
b.addEventListener('click', function(){
setParams(p.a == null ? state.a : p.a, p.e, 'preset');
setActivePreset(p.name);
if (!p.keep){ markPlanetRow(p.name); noteLoaded(p.name); }
});
el.appendChild(b);
});
}
function setActivePreset(name){
activePreset = name;
document.querySelectorAll('.preset').forEach(function(b){ b.classList.toggle('on', b.dataset.name === name); });
}
function syncParamUI(){
eSliders.forEach(function(s){ s.value = Math.round(state.e * 1000); });
aSliders.forEach(function(s){ s.value = aToSlider(state.a); });
eVals.forEach(function(v){ v.textContent = 'e = ' + f(state.e, 3); });
aVals.forEach(function(v){ v.textContent = 'a = ' + f(state.a, state.a < 2 ? 3 : 2) + ' AU'; });
var cap = 'a = ' + f(state.a, 3) + ' AU · e = ' + f(state.e, 3) + ' · T = ' + f(periodY(state.a), 2) + ' yr';
$('cap1').textContent = cap; $('cap2').textContent = cap;
/* Law 1 static readouts */
var a = state.a, e = state.e;
$('s1_rmin').innerHTML = f(a * (1 - e), 3) + ' <small>AU</small>';
$('s1_rmax').innerHTML = f(a * (1 + e), 3) + ' <small>AU</small>';
$('s1_b').innerHTML = f(a * Math.sqrt(1 - e * e), 3) + ' <small>AU</small>';
$('s1_p').innerHTML = f(a * (1 - e * e), 3) + ' <small>AU</small>';
$('s1_off').innerHTML = f(a * e, 3) + ' <small>AU</small>';
$('s1_T').innerHTML = f(periodY(a), 3) + ' <small>yr</small>';
/* Hodograph extremes */
var st = orbitAt(a, e, 0);
var R = st.R;
$('hRad').innerHTML = f(R, 2) + ' <small>km/s</small>';
$('hOff').innerHTML = f(e * R, 2) + ' <small>km/s</small>';
$('hPeri').textContent = f(R * (1 + e), 2) + ' km/s';
$('hAph').textContent = f(R * (1 - e), 2) + ' km/s';
$('hRatio').textContent = e >= 0.999 ? '∞' : f((1 + e) / (1 - e), 2) + '×';
if ($('thMin')){
$('thMin').textContent = f(R * (1 - e), 2) + ' km/s · aphelion';
$('thMax').textContent = f(R * (1 + e), 2) + ' km/s · perihelion';
}
/* Orbit-shaper readouts (hodograph chapter) */
if ($('ho_rmin')){
$('ho_e').textContent = f(e, 3);
$('ho_rmin').innerHTML = f(a * (1 - e), 3) + ' <small>AU</small>';
$('ho_rmax').innerHTML = f(a * (1 + e), 3) + ' <small>AU</small>';
$('ho_vperi').innerHTML = f(R * (1 + e), 2) + ' <small>km/s</small>';
$('ho_vaph').innerHTML = f(R * (1 - e), 2) + ' <small>km/s</small>';
$('osRead').textContent = 'period T = ' + f(periodY(a), 2) + ' yr';
}
}
function setParams(a, e, origin){
/* keep the orbital phase (mean anomaly) of the running sims: rescale
their clocks by the period ratio so the planet does not jump */
var oldT = periodY(state.a);
var phH = simH.t / oldT, ph1 = sim1.t / oldT;
state.a = Math.min(A_MAX, Math.max(A_MIN, a));
state.e = Math.min(0.97, Math.max(0, e));
var newT = periodY(state.a);
simH.t = phH * newT; sim1.t = ph1 * newT;
if (origin !== 'preset') setActivePreset('');
syncParamUI();
resetLaw2();
clearHistory();
trail1.length = 0;
trail2.length = 0;
if (build.on) build.idx = 0;
}
function noteLoaded(name){
$('loadNote').textContent = '→ Loaded ' + name + ' (a = ' + f(state.a, 3) + ' AU, e = ' + f(state.e, 4) + ') into the Law 1, Law 2 and Hodograph simulators.';
}
function markPlanetRow(name){
document.querySelectorAll('#tbody3 tr').forEach(function(tr){ tr.classList.toggle('on', tr.dataset.name === name); });
selectedPlanet = name; drawChart();
}
/* ============================================================
Orbit geometry shared by the position-space canvases.
World coords: AU, Sun (focus F1) at origin, perihelion +x.
============================================================ */
function orbitTransform(o, a, e, pad){
var b = a * Math.sqrt(1 - e * e);
var s = Math.min((o.w - 2 * pad) / (2 * a), (o.h - 2 * pad) / (2 * Math.max(b, a * 0.16)));
return { s: s, ox: o.w / 2 + a * e * s, oy: o.h / 2, b: b };
}
function drawOrbitBase(o, tr, a, e, opts){
var ctx = o.ctx;
/* ellipse — gradient stroke, cyan (position) into violet */
ctx.save();
var og = ctx.createLinearGradient(0, 0, o.w, 0);
og.addColorStop(0, '#2fe8d8'); og.addColorStop(0.55, '#57b6ff'); og.addColorStop(1, '#d873ff');
ctx.strokeStyle = og; ctx.lineWidth = 2.2;
ctx.shadowColor = 'rgba(87,182,255,.5)'; ctx.shadowBlur = 9;
ctx.beginPath();
for (var i = 0; i <= 180; i++){
var E = i / 180 * TAU;
var x = tr.ox + (a * Math.cos(E) - a * e) * tr.s;
var y = tr.oy - tr.b * Math.sin(E) * tr.s;
if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
}
ctx.stroke();
/* major axis */
ctx.strokeStyle = 'rgba(143,165,200,.25)'; ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(tr.ox - a * (1 + e) * tr.s, tr.oy);
ctx.lineTo(tr.ox + a * (1 - e) * tr.s, tr.oy);
ctx.stroke();
ctx.restore();
/* empty focus F2 — dim glowing ring + cross */
var f2x = tr.ox - 2 * a * e * tr.s;
ctx.save();
ctx.strokeStyle = 'rgba(163,177,200,.55)'; ctx.lineWidth = 1.3;
ctx.beginPath(); ctx.arc(f2x, tr.oy, 7, 0, TAU); ctx.stroke();
ctx.strokeStyle = COL.faint; ctx.lineWidth = 1.4;
ctx.beginPath();
ctx.moveTo(f2x - 5, tr.oy - 5); ctx.lineTo(f2x + 5, tr.oy + 5);
ctx.moveTo(f2x + 5, tr.oy - 5); ctx.lineTo(f2x - 5, tr.oy + 5);
ctx.stroke(); ctx.restore();
if (opts && opts.focusLabels){
label(ctx, 'F₂ · empty focus', f2x, tr.oy + 20, COL.faint, 'center');
label(ctx, 'Sun · F₁', tr.ox, tr.oy + 22, COL.amber, 'center');
}
/* Sun — glowing disc with corona and a gold focus ring */
ctx.save();
ctx.strokeStyle = 'rgba(255,200,90,.75)'; ctx.lineWidth = 1.4;
ctx.beginPath(); ctx.arc(tr.ox, tr.oy, 10.5, 0, TAU); ctx.stroke();
var g = ctx.createRadialGradient(tr.ox, tr.oy, 1, tr.ox, tr.oy, 34);
g.addColorStop(0, 'rgba(255,224,150,.98)');
g.addColorStop(0.22, 'rgba(246,183,60,.85)');
g.addColorStop(0.5, 'rgba(246,150,50,.32)');
g.addColorStop(1, 'rgba(246,150,50,0)');
ctx.fillStyle = g; ctx.shadowColor = 'rgba(246,183,60,.8)'; ctx.shadowBlur = 22;
ctx.beginPath(); ctx.arc(tr.ox, tr.oy, 34, 0, TAU); ctx.fill();
ctx.shadowBlur = 0;
ctx.fillStyle = '#fff3cf';
ctx.beginPath(); ctx.arc(tr.ox, tr.oy, 6.5, 0, TAU); ctx.fill();
ctx.restore();
return { f2x: f2x };
}
function planetDot(ctx, x, y, color){
color = color || COL.coral;
ctx.save();
ctx.shadowColor = color; ctx.shadowBlur = 17;
var g = ctx.createRadialGradient(x - 2.4, y - 2.4, 0.4, x, y, 6.8);
g.addColorStop(0, '#ffffff'); g.addColorStop(0.38, color); g.addColorStop(1, color);
ctx.fillStyle = g;
ctx.beginPath(); ctx.arc(x, y, 6.2, 0, TAU); ctx.fill();
ctx.shadowBlur = 0;
ctx.strokeStyle = 'rgba(255,255,255,.85)'; ctx.lineWidth = 1.3;
ctx.beginPath(); ctx.arc(x, y, 6.2, 0, TAU); ctx.stroke();
ctx.restore();
}
var trail1 = [], trail2 = [];
/* fading trail in position space, each segment coloured by the speed there */
function drawTrail(ctx, tr, arr, st, e){
if (arr.length < 2) return;
var vmin = st.R * (1 - e), vmax = st.R * (1 + e);
ctx.save();
ctx.lineWidth = 2.4; ctx.lineCap = 'round';
for (var i = 1; i < arr.length; i++){
ctx.strokeStyle = speedColor(arr[i][2], vmin, vmax);
ctx.globalAlpha = 0.10 + 0.78 * (i / arr.length);
ctx.beginPath();
ctx.moveTo(tr.ox + arr[i - 1][0] * tr.s, tr.oy - arr[i - 1][1] * tr.s);
ctx.lineTo(tr.ox + arr[i][0] * tr.s, tr.oy - arr[i][1] * tr.s);
ctx.stroke();
}
ctx.restore();
}
/* ============================================================
LAW 1 — ellipse with live r1 + r2 = 2a check
============================================================ */
var cv1 = makeCanvas('cv1');
var sim1 = { t: 0, playing: true, DUR: 16 };
$('play1').addEventListener('click', function(){
sim1.playing = !sim1.playing;
this.textContent = sim1.playing ? '❚❚ Pause' : '▶ Play';
});
function drawLaw1(dt){
if (sim1.playing) sim1.t += dt * periodY(state.a) / sim1.DUR;
var a = state.a, e = state.e;
var st = orbitAt(a, e, sim1.t);
var o = cv1, ctx = o.ctx;
ctx.clearRect(0, 0, o.w, o.h);
drawStars(o);
var tr = orbitTransform(o, a, e, 46);
var base = drawOrbitBase(o, tr, a, e, { focusLabels: true });
var px = tr.ox + st.x * tr.s, py = tr.oy - st.y * tr.s;
/* r1 and r2 lines — neon, with animated dashes flowing toward the foci */
ctx.save();
var dashOff = -performance.now() / 45;
ctx.strokeStyle = '#57b6ff'; ctx.lineWidth = 2.2;
ctx.shadowColor = 'rgba(87,182,255,.8)'; ctx.shadowBlur = 8;
ctx.setLineDash([7, 5]); ctx.lineDashOffset = dashOff;
ctx.beginPath(); ctx.moveTo(tr.ox, tr.oy); ctx.lineTo(px, py); ctx.stroke();
ctx.shadowBlur = 0;
ctx.strokeStyle = COL.violet; ctx.lineWidth = 1.7;
ctx.setLineDash([4, 4]); ctx.lineDashOffset = -dashOff;
ctx.beginPath(); ctx.moveTo(base.f2x, tr.oy); ctx.lineTo(px, py); ctx.stroke();
ctx.restore();
var lt1 = trail1[trail1.length - 1];
if (!lt1 || Math.hypot(st.x - lt1[0], st.y - lt1[1]) > 0.004 * a) trail1.push([st.x, st.y, st.v]);
if (trail1.length > 110) trail1.shift();
drawTrail(ctx, tr, trail1, st, e);
planetDot(ctx, px, py, speedColor(st.v, st.R * (1 - e), st.R * (1 + e)));
/* perihelion / aphelion tags — tucked inboard above the axis, with leader lines to the apsides */
var periTX = tr.ox + a * (1 - e) * tr.s, aphTX = tr.ox - a * (1 + e) * tr.s;
leader(ctx, periTX, tr.oy - 4, periTX - 10, tr.oy - 20);
label(ctx, 'perihelion', periTX - 13, tr.oy - 24, COL.faint, 'right');
leader(ctx, aphTX, tr.oy - 4, aphTX + 10, tr.oy - 20);
label(ctx, 'aphelion', aphTX + 13, tr.oy - 24, COL.faint, 'left');
/* live check */
var r2 = Math.hypot(st.x + 2 * a * e, st.y);
$('s1_r1').textContent = f(st.r, 4) + ' AU';
$('s1_r2').textContent = f(r2, 4) + ' AU';
$('s1_sum').textContent = f(st.r + r2, 4) + ' AU';
$('s1_2a').textContent = f(2 * a, 4) + ' AU';
$('s1_diff').textContent = Math.abs(st.r + r2 - 2 * a).toExponential(1) + ' AU ✓';
}
/* ============================================================
LAW 2 — equal areas, 12 sectors of T/12
============================================================ */
var cv2 = makeCanvas('cv2');
var sim2 = { t: 0, playing: true, DUR: 26, areas: new Array(12).fill(null), lastAreas: null, cycle: 0, lastK: 0 };
function sectorArea(a, e, t0, t1){
/* Shoelace over the sector boundary, sampled uniformly in eccentric
anomaly E (positions x = a(cosE - e), y = b sinE) so the polygon
hugs the arc even through a sharp perihelion whip. */
var T = periodY(a), b = a * Math.sqrt(1 - e * e), N = 400;
var E0 = solveE(TAU * (t0 / T), e), E1 = solveE(TAU * (t1 / T), e);
var dE = E1 - E0;
while (dE <= 0) dE += TAU;
while (dE > TAU) dE -= TAU;
var sum = 0, prev = null;
for (var i = 0; i <= N; i++){
var E = E0 + dE * i / N;
var x = a * (Math.cos(E) - e), y = b * Math.sin(E);
if (prev) sum += prev[0] * y - x * prev[1];
prev = [x, y];
}
return Math.abs(sum) / 2;
}
function sectorPath(ctx, tr, a, e, t0, t1, steps){
ctx.beginPath();
ctx.moveTo(tr.ox, tr.oy);
for (var i = 0; i <= steps; i++){
var st = orbitAt(a, e, t0 + (t1 - t0) * i / steps);
ctx.lineTo(tr.ox + st.x * tr.s, tr.oy - st.y * tr.s);
}
ctx.closePath();
}
function resetLaw2(){
sim2.t = 0; sim2.cycle = 0; sim2.lastK = 0;
sim2.areas = new Array(12).fill(null); sim2.lastAreas = null;
renderChips();
}
function chipValue(i){
if (sim2.areas[i] != null) return sim2.areas[i];
if (sim2.lastAreas && sim2.lastAreas[i] != null) return sim2.lastAreas[i];
return null;
}
function renderChips(){
var wrap = $('areas2');
wrap.innerHTML = '';
var T = periodY(state.a);
var tmod = ((sim2.t % T) + T) % T;
var k = Math.min(11, Math.floor(tmod / (T / 12)));
var vals = [];
for (var i = 0; i < 12; i++){
var v = chipValue(i);
if (v != null) vals.push(v);
var c = document.createElement('span');
c.className = 'chip' + (v != null ? ' done' : (i === k ? ' now' : ''));
c.innerHTML = v != null ? 'S' + (i + 1) + ' · <b>' + f(v, 4) + ' AU²</b>' : 'S' + (i + 1) + ' · —';
wrap.appendChild(c);
}
if (vals.length > 1){
var mean = vals.reduce(function(s2, x){ return s2 + x; }, 0) / vals.length;
var dev = (Math.max.apply(null, vals) - Math.min.apply(null, vals)) / mean * 100;
$('s2_dev').innerHTML = f(dev, 3) + ' <small>%</small>';
} else $('s2_dev').innerHTML = '—';
}
$('play2').addEventListener('click', function(){
sim2.playing = !sim2.playing;
this.textContent = sim2.playing ? '❚❚ Pause' : '▶ Play';
});
$('restart2').addEventListener('click', resetLaw2);
function drawLaw2(dt){
var a = state.a, e = state.e, T = periodY(a);
if (sim2.playing) sim2.t += dt * T / sim2.DUR;
var cycle = Math.floor(sim2.t / T);
var tmod = sim2.t - cycle * T;
var k = Math.min(11, Math.floor(tmod / (T / 12)));
if (cycle !== sim2.cycle || k !== sim2.lastK){
/* the sector that just ended is (sim2.cycle, sim2.lastK) — measure it */
var t0 = sim2.cycle * T + sim2.lastK * (T / 12);
sim2.areas[sim2.lastK] = sectorArea(a, e, t0, t0 + T / 12);
if (cycle !== sim2.cycle){
sim2.lastAreas = sim2.areas.slice(); /* keep the finished orbit's numbers on the chips */
sim2.areas = new Array(12).fill(null); /* start the new orbit's fills fresh */
}
sim2.cycle = cycle; sim2.lastK = k;
renderChips();
}
var st = orbitAt(a, e, sim2.t);
var o = cv2, ctx = o.ctx;
ctx.clearRect(0, 0, o.w, o.h);
drawStars(o);
var tr = orbitTransform(o, a, e, 46);
var orbitStart = cycle * T;
/* sectors completed in the current orbit — vivid gradient palette */
var SECT = ['61,123,255', '47,212,196', '168,110,255', '240,107,216', '255,170,60', '80,220,140'];
for (var i = 0; i < 12; i++){
if (sim2.areas[i] == null) continue;
ctx.save();
sectorPath(ctx, tr, a, e, orbitStart + i * T / 12, orbitStart + (i + 1) * T / 12, 48);
ctx.fillStyle = 'rgba(' + SECT[i % 6] + ',.30)';
ctx.fill();
ctx.strokeStyle = 'rgba(' + SECT[i % 6] + ',.55)'; ctx.lineWidth = 1;
ctx.stroke();
ctx.restore();
}
/* current sector, swept so far — glowing highlight in the live speed colour */
ctx.save();
sectorPath(ctx, tr, a, e, orbitStart + k * T / 12, sim2.t, 40);
var scNow = speedColor(st.v, st.R * (1 - e), st.R * (1 + e));
ctx.fillStyle = scNow; ctx.globalAlpha = 0.38;
ctx.shadowColor = scNow; ctx.shadowBlur = 14;
ctx.fill();
ctx.globalAlpha = 0.9; ctx.shadowBlur = 0;
ctx.strokeStyle = scNow; ctx.lineWidth = 1.4;
ctx.stroke();
ctx.restore();
drawOrbitBase(o, tr, a, e, { focusLabels: false });
var px = tr.ox + st.x * tr.s, py = tr.oy - st.y * tr.s;
ctx.save();
ctx.strokeStyle = '#57b6ff'; ctx.lineWidth = 2;
ctx.shadowColor = 'rgba(87,182,255,.7)'; ctx.shadowBlur = 7;
ctx.beginPath(); ctx.moveTo(tr.ox, tr.oy); ctx.lineTo(px, py); ctx.stroke();
ctx.restore();
var lt2 = trail2[trail2.length - 1];
if (!lt2 || Math.hypot(st.x - lt2[0], st.y - lt2[1]) > 0.004 * a) trail2.push([st.x, st.y, st.v]);
if (trail2.length > 110) trail2.shift();
drawTrail(ctx, tr, trail2, st, e);
planetDot(ctx, px, py, speedColor(st.v, st.R * (1 - e), st.R * (1 + e)));
/* readouts */
var dAdt = 0.5 * st.h / (AU * AU) * SEC_PER_YEAR;
$('s2_dadt').innerHTML = f(dAdt, 4) + ' <small>AU²/yr</small>';
$('s2_r').innerHTML = f(st.r, 3) + ' <small>AU</small>';
$('s2_v').innerHTML = f(st.v, 2) + ' <small>km/s</small>';
$('s2_sector').textContent = (k + 1) + ' of 12';
$('s2_sector_k').textContent = 'Sector · Δt = T/12 ≈ ' + f(T / 12 * 365.2564, 1) + ' days';
}
/* ============================================================
LAW 3 — table, log-log chart, calculator
============================================================ */
var selectedPlanet = 'Earth';
(function buildTable(){
var tb = $('tbody3');
PLANETS.forEach(function(p){
var tr = document.createElement('tr');
tr.dataset.name = p.name;
if (p.name === 'Earth') tr.className = 'on';
var K = p.a * p.a * p.a / (p.T * p.T) * 1e6;
tr.innerHTML = '<td><span class="pdot-cell" style="background:' + (PLANET_COL[p.name] || '#a3b1c8') + ';box-shadow:0 0 8px ' + (PLANET_COL[p.name] || '#a3b1c8') + '"></span>' + p.name + '</td><td>' + f(p.a, 5) + '</td><td>' + f(p.T, 4) + '</td><td>' + f(p.T / 365.2564, 3) + '</td><td>' + f(p.e, 4) + '</td><td>' + f(K, 3) + '</td>';
tr.addEventListener('click', function(){ setParams(p.a, p.e, 'preset'); setActivePreset(p.name); markPlanetRow(p.name); noteLoaded(p.name); });
tb.appendChild(tr);
});
})();
var cv3 = makeCanvas('cv3');
var chartPts = [];
var chartHover = '';
var chartStart = performance.now();
var chartSeen = false;
function drawChart(){
var o = cv3, ctx = o.ctx;
ctx.clearRect(0, 0, o.w, o.h);
var padL = 52, padR = 16, padT = 18, padB = 40;
var W = o.w - padL - padR, H = o.h - padT - padB;
var xa = Math.log10(0.3), xb = Math.log10(40);
var ya = Math.log10(0.15), yb = Math.log10(260);
function X(a){ return padL + (Math.log10(a) - xa) / (xb - xa) * W; }
function Y(t){ return padT + H - (Math.log10(t) - ya) / (yb - ya) * H; }
ctx.save();
/* gridlines at decades */
ctx.strokeStyle = COL.grid; ctx.lineWidth = 1;
[0.1, 1, 10].forEach(function(v){
if (v < 0.3) return;
ctx.beginPath(); ctx.moveTo(X(v), padT); ctx.lineTo(X(v), padT + H); ctx.stroke();
label(ctx, v + '', X(v), padT + H + 16, COL.faint, 'center');
});
[1, 10, 100].forEach(function(v){
ctx.beginPath(); ctx.moveTo(padL, Y(v)); ctx.lineTo(padL + W, Y(v)); ctx.stroke();
label(ctx, v + '', padL - 8, Y(v), COL.faint, 'right');
});
label(ctx, 'semi-major axis a (AU)', padL + W / 2, padT + H + 32, COL.faint, 'center');
label(ctx, 'T (yr)', padL - 8, padT - 7, COL.faint, 'right');
/* slope 3/2 line — gradient stroke with a draw-in sweep */
var prog = Math.min(1, (performance.now() - chartStart) / 1500);
var lg = ctx.createLinearGradient(padL, 0, padL + W, 0);
lg.addColorStop(0, '#2fe8d8'); lg.addColorStop(1, '#d873ff');
ctx.strokeStyle = lg; ctx.lineWidth = 2.4;
ctx.shadowColor = 'rgba(120,140,255,.55)'; ctx.shadowBlur = 8;
var lx0 = X(0.3), ly0 = Y(Math.pow(0.3, 1.5)), lx1 = X(40), ly1 = Y(Math.pow(40, 1.5));
ctx.beginPath();
ctx.moveTo(lx0, ly0);
ctx.lineTo(lx0 + (lx1 - lx0) * prog, ly0 + (ly1 - ly0) * prog);
ctx.stroke();
ctx.shadowBlur = 0;
label(ctx, 'T = a^1.5', X(9.5), Y(Math.pow(9.5, 1.5)) - 14, COL.teal, 'left', 12.5);
ctx.restore();
/* planets */
chartPts = [];
PLANETS.forEach(function(p){
var tYr = p.T / 365.2564;
var x = X(p.a), y = Y(tYr);
chartPts.push({ x: x, y: y, p: p });
var sel = p.name === selectedPlanet;
var hov = p.name === chartHover;
var pc = PLANET_COL[p.name] || COL.coral;
ctx.save();
ctx.shadowColor = pc; ctx.shadowBlur = sel || hov ? 20 : 12;
ctx.fillStyle = pc;
ctx.beginPath(); ctx.arc(x, y, sel ? 7 : hov ? 6.5 : 5.2, 0, TAU); ctx.fill();
ctx.shadowBlur = 0;
if (sel || hov){ ctx.strokeStyle = '#fff'; ctx.lineWidth = 1.5; ctx.beginPath(); ctx.arc(x, y, sel ? 7 : 6.5, 0, TAU); ctx.stroke(); }
ctx.restore();
var above = (p.name === 'Mercury' || p.name === 'Saturn' || p.name === 'Neptune');
label(ctx, p.name, x, y + (above ? -14 : 15), sel ? '#ffd98a' : hov ? '#ffffff' : COL.muted, 'center', 12);
});
}
cv3.cv.addEventListener('click', function(ev){
var r = cv3.cv.getBoundingClientRect();
var mx = ev.clientX - r.left, my = ev.clientY - r.top;
for (var i = 0; i < chartPts.length; i++){
var q = chartPts[i];
if (Math.hypot(mx - q.x, my - q.y) < 16){
setParams(q.p.a, q.p.e, 'preset'); setActivePreset(q.p.name); markPlanetRow(q.p.name); noteLoaded(q.p.name);
return;
}
}
});
cv3.cv.addEventListener('mousemove', function(ev){
var r = cv3.cv.getBoundingClientRect();
var mx = ev.clientX - r.left, my = ev.clientY - r.top;
var name = '';
for (var i = 0; i < chartPts.length; i++){
if (Math.hypot(mx - chartPts[i].x, my - chartPts[i].y) < 16){ name = chartPts[i].p.name; break; }
}
if (name !== chartHover){ chartHover = name; drawChart(); }
cv3.cv.style.cursor = name ? 'pointer' : '';
});
/* calculator */
function calcUpdate(){
var a = sliderToA(+$('calcA').value);
var T = periodY(a);
$('calcAval').textContent = 'a = ' + f(a, 2) + ' AU';
$('calc_a').innerHTML = f(a, 3) + ' <small>AU</small>';
$('calc_T').innerHTML = f(T, 3) + ' <small>yr</small>';
$('calc_days').innerHTML = Math.round(T * 365.2564).toLocaleString('en-US') + ' <small>days</small>';
$('calc_K').innerHTML = f(a * a * a / Math.pow(T * 365.2564, 2) * 1e6, 3) + ' <small>×10⁻⁶</small>';
}
$('calcA').addEventListener('input', calcUpdate);
/* ============================================================
THE HODOGRAPH — two synchronised canvases, one clock
============================================================ */
var cvP = makeCanvas('cvP');
var cvV = makeCanvas('cvV');
var simH = { t: 0, playing: true, DUR: 14, speed: 1 };
/* ---------- velocity history: phase-bucketed record of past tips ----------
HIST_N buckets per period; each bucket keeps the newest tip recorded at
that phase, stamped with the revolution it was written in, so points
older than one period are replaced by newer ones at the same phase and
the completed ring IS the hodograph circle. */
var HIST_N = 96;
var hist = new Array(HIST_N).fill(null);
var histNewest = null;
var lastHistRev = null;
function clearHistory(){
hist = new Array(HIST_N).fill(null);
histNewest = null;
lastHistRev = null;
}
function writeHistBucket(rev, s){
var ph = ((rev % 1) + 1) % 1;
var bk = Math.min(HIST_N - 1, Math.floor(ph * HIST_N));
hist[bk] = { vx: s.vx, vy: s.vy, v: s.v, rev: rev };
if (histNewest === null || rev > histNewest) histNewest = rev;
}
function recordHistory(st){
var rev = simH.t / st.T;
if (lastHistRev === null || rev < lastHistRev){ writeHistBucket(rev, st); lastHistRev = rev; return; }
/* fill every bucket crossed since the last record, so fast playback
never leaves gaps in the ring */
var step = 1 / HIST_N, r = lastHistRev, guard = 0;
while (r + step <= rev && guard++ < 64){
r += step;
writeHistBucket(r, orbitAt(state.a, state.e, r * st.T));
}
writeHistBucket(rev, st);
lastHistRev = rev;
}
var build = { on: false, idx: 0, N: 24 };
var samplesN = 0;
$('playH').addEventListener('click', function(){
simH.playing = !simH.playing;
this.textContent = simH.playing ? '❚❚ Pause' : '▶ Play';
});
var scrubbingH = false;
$('scrubH').addEventListener('pointerdown', function(){ scrubbingH = true; clearHistory(); });
window.addEventListener('pointerup', function(){ scrubbingH = false; });
$('scrubH').addEventListener('input', function(){
var newT = (+this.value / 1000) * periodY(state.a);
if (!scrubbingH){
/* a jump (track click / big key step) clears; small steps paint */
var dph = Math.abs(((newT - simH.t) / periodY(state.a)) % 1);
if (Math.min(dph, 1 - dph) > 1 / HIST_N) clearHistory();
}
simH.t = newT;
});
$('clearHist').addEventListener('click', function(){ clearHistory(); });
$('speedSeg').addEventListener('click', function(ev){
var b = ev.target.closest('button'); if (!b) return;
simH.speed = +b.dataset.speed;
this.querySelectorAll('button').forEach(function(x){ x.classList.toggle('on', x === b); });
});
$('sampSeg').addEventListener('click', function(ev){
var b = ev.target.closest('button'); if (!b) return;
samplesN = +b.dataset.n;
this.querySelectorAll('button').forEach(function(x){ x.classList.toggle('on', x === b); });
});
$('buildBtn').addEventListener('click', function(){
build.on = true; build.idx = 0;
$('buildUI').classList.add('show');
this.disabled = true;
});
$('bExit').addEventListener('click', function(){
build.on = false;
$('buildUI').classList.remove('show');
$('buildBtn').disabled = false;
});
$('bNext').addEventListener('click', function(){ if (build.idx < build.N - 1) build.idx++; });
$('bPrev').addEventListener('click', function(){ if (build.idx > 0) build.idx--; });
function hodoState(){
if (build.on) return orbitAt(state.a, state.e, build.idx * periodY(state.a) / build.N);
return orbitAt(state.a, state.e, simH.t);
}
function drawHodoPos(st){
var o = cvP, ctx = o.ctx, a = state.a, e = state.e;
ctx.clearRect(0, 0, o.w, o.h);
drawStars(o);
var tr = orbitTransform(o, a, e, 40);
drawOrbitBase(o, tr, a, e, { focusLabels: false });
var px = tr.ox + st.x * tr.s, py = tr.oy - st.y * tr.s;
/* position vector r */
arrow(ctx, tr.ox, tr.oy, px, py, COL.blue, 2);
label(ctx, 'r', (tr.ox + px) / 2 + 8, (tr.oy + py) / 2 - 8, COL.blue, 'left', 13);
/* velocity arrow at planet, scaled so perihelion v = 0.42*a world units */
var vPeri = st.R * (1 + e);
var k = 0.42 * a / vPeri;
var vwx = st.vx * k, vwy = st.vy * k;
var tx = tr.ox + (st.x + vwx) * tr.s, ty = tr.oy - (st.y + vwy) * tr.s;
arrow(ctx, px, py, tx, ty, COL.violet, 3);
label(ctx, 'v', tx + (vwx >= 0 ? 7 : -7), ty - 4, COL.violet, vwx >= 0 ? 'left' : 'right', 13);
/* acceleration arrow toward Sun */
if ($('tgAccel').checked){
var dx = tr.ox - px, dy = tr.oy - py, dl = Math.hypot(dx, dy) || 1;
var alen = 30;
var ax = px + dx / dl * alen, ay = py + dy / dl * alen;
arrow(ctx, px, py, ax, ay, COL.pink, 2);
label(ctx, 'a', ax + dx / dl * 10, ay + dy / dl * 10, COL.pink, 'center', 12.5);
}
planetDot(ctx, px, py, speedColor(st.v, st.R * (1 - e), st.R * (1 + e)));
/* apsides */
var periX = tr.ox + a * (1 - e) * tr.s, aphX = tr.ox - a * (1 + e) * tr.s;
ctx.save(); ctx.fillStyle = COL.faint;
ctx.beginPath(); ctx.arc(periX, tr.oy, 2.4, 0, TAU); ctx.fill();
ctx.beginPath(); ctx.arc(aphX, tr.oy, 2.4, 0, TAU); ctx.fill();
ctx.restore();
label(ctx, 'Sun', tr.ox + 12, tr.oy - 12, COL.amber, 'left');
label(ctx, 'ν = ' + f(st.nu * 180 / Math.PI, 1) + '°', 12, 18, COL.muted, 'left', 12);
}
function drawHodoVel(st){
var o = cvV, ctx = o.ctx, e = state.e;
ctx.clearRect(0, 0, o.w, o.h);
drawStars(o);
var R = st.R, eR = e * R;
var s = Math.min((o.w - 96) / (2 * R), (o.h - 92) / (2 * R));
var ox = o.w / 2, oy = o.h / 2 + eR * s;
function SX(vx){ return ox + vx * s; }
function SY(vy){ return oy - vy * s; }
var cx = SX(0), cy = SY(eR);
/* axes */
ctx.save();
ctx.strokeStyle = 'rgba(163,177,200,.4)'; ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(14, oy); ctx.lineTo(o.w - 30, oy); ctx.stroke();
ctx.beginPath(); ctx.moveTo(ox, o.h - 14); ctx.lineTo(ox, 26); ctx.stroke();
ctx.fillStyle = 'rgba(163,177,200,.4)';
ctx.beginPath(); ctx.moveTo(o.w - 30, oy); ctx.lineTo(o.w - 38, oy - 4); ctx.lineTo(o.w - 38, oy + 4); ctx.closePath(); ctx.fill();
ctx.beginPath(); ctx.moveTo(ox, 26); ctx.lineTo(ox - 4, 34); ctx.lineTo(ox + 4, 34); ctx.closePath(); ctx.fill();
/* ticks: pick a round step */
var steps = [1, 2, 5, 10, 20, 25, 50], step = 10;
for (var i = 0; i < steps.length; i++) if (steps[i] <= R / 2) step = steps[i];
ctx.font = '10.5px "IBM Plex Mono", monospace'; ctx.fillStyle = COL.faint; ctx.textAlign = 'center';
for (var v = -Math.floor(R * 1.3 / step) * step; v <= R * 1.3; v += step){
if (v === 0) continue;
if (Math.abs(v) <= R * 1.02){
ctx.fillRect(SX(v) - 0.5, oy - 3, 1, 6);
ctx.fillText(v + '', SX(v), oy + 15);
}
if (Math.abs(v) <= R * (1 + e) + step){
ctx.fillRect(ox - 3, SY(v) - 0.5, 6, 1);
ctx.fillText(v + '', ox - 16, SY(v) + 3);
}
}
ctx.restore();
label(ctx, 'v_x (km/s)', o.w - 34, oy - 12, COL.faint, 'right', 11.5);
label(ctx, 'v_y (km/s)', ox + 10, 30, COL.faint, 'left', 11.5);
/* origin */
ctx.save();
ctx.strokeStyle = COL.ink; ctx.lineWidth = 1.4;
ctx.beginPath(); ctx.moveTo(ox - 6, oy); ctx.lineTo(ox + 6, oy); ctx.moveTo(ox, oy - 6); ctx.lineTo(ox, oy + 6); ctx.stroke();
ctx.restore();
label(ctx, 'O', ox - 10, oy + 14, COL.ink, 'right', 12.5);
/* velocity history — fading speed-coloured trail of past tips, with a
dot every T/24. Drawn under the circle, arrow, centre and badges. */
if ($('tgTrail').checked){
var vminH = R * (1 - e), vmaxH = R * (1 + e);
ctx.save();
ctx.lineWidth = 3.2; ctx.lineCap = 'round'; ctx.lineJoin = 'round';
for (var hb = 0; hb < HIST_N; hb++){
var hA = hist[hb], hB = hist[(hb + 1) % HIST_N];
if (!hA || !hB) continue;
var ageB = histNewest === null ? 0 : Math.max(0, Math.min(1, histNewest - hB.rev));
ctx.strokeStyle = speedColor(hB.v, vminH, vmaxH);
ctx.globalAlpha = 0.88 - 0.62 * ageB;
ctx.beginPath();
ctx.moveTo(SX(hA.vx), SY(hA.vy));
ctx.lineTo(SX(hB.vx), SY(hB.vy));
ctx.stroke();
}
for (var hd = 0; hd < HIST_N; hd += HIST_N / 24){
var hP = hist[hd];
if (!hP) continue;
var ageP = histNewest === null ? 0 : Math.max(0, Math.min(1, histNewest - hP.rev));
ctx.globalAlpha = 0.95 - 0.5 * ageP;
ctx.fillStyle = speedColor(hP.v, vminH, vmaxH);
ctx.beginPath(); ctx.arc(SX(hP.vx), SY(hP.vy), 3.1, 0, TAU); ctx.fill();
ctx.strokeStyle = 'rgba(255,255,255,.55)'; ctx.lineWidth = 1;
ctx.beginPath(); ctx.arc(SX(hP.vx), SY(hP.vy), 3.1, 0, TAU); ctx.stroke();
}
ctx.restore();
}
/* sampled arrows (equal time steps) */
if (samplesN > 0 && !build.on){
var T = st.T;
ctx.save(); ctx.globalAlpha = 0.5;
for (var k2 = 0; k2 < samplesN; k2++){
var ss = orbitAt(state.a, state.e, k2 * T / samplesN);
arrow(ctx, ox, oy, SX(ss.vx), SY(ss.vy), COL.violet, 1.1);
}
ctx.restore();
}
/* hodograph circle */
var showCircle = $('tgCircle').checked && (!build.on || build.idx >= build.N - 1);
if (showCircle){
ctx.save();
ctx.strokeStyle = COL.violet; ctx.lineWidth = 2.6; ctx.globalAlpha = 0.95;
ctx.shadowColor = COL.violet; ctx.shadowBlur = 16;
ctx.beginPath(); ctx.arc(cx, cy, R * s, 0, TAU); ctx.stroke();
ctx.restore();
}
/* centre + offset */
if ($('tgCentre').checked){
ctx.save();
ctx.strokeStyle = COL.amber; ctx.setLineDash([5, 4]); ctx.lineWidth = 1.4;
ctx.beginPath(); ctx.moveTo(ox, oy); ctx.lineTo(cx, cy); ctx.stroke();
ctx.setLineDash([]);
ctx.fillStyle = COL.amber;
ctx.shadowColor = COL.amber; ctx.shadowBlur = 10;
ctx.beginPath(); ctx.arc(cx, cy, 3.4, 0, TAU); ctx.fill();
ctx.shadowBlur = 0;
ctx.restore();
label(ctx, 'centre C', cx + 9, cy - 8, COL.amber, 'left', 11.5);
if (eR * s > 18) label(ctx, 'e·R', (ox + cx) / 2 + 8, (oy + cy) / 2, COL.amber, 'left', 11.5);
/* dashed radius C -> tip */
ctx.save();
ctx.strokeStyle = 'rgba(233,237,245,.5)'; ctx.setLineDash([3, 4]); ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(cx, cy); ctx.lineTo(SX(st.vx), SY(st.vy)); ctx.stroke();
ctx.restore();
label(ctx, 'R', (cx + SX(st.vx)) / 2 + 6, (cy + SY(st.vy)) / 2 - 6, COL.muted, 'left', 11.5);
}
/* perihelion / aphelion tip markers */
var pPeri = { x: SX(0), y: SY(R * (1 + e)) }, pAph = { x: SX(0), y: SY(-R * (1 - e)) };
ctx.save();
ctx.shadowColor = '#ffb84d'; ctx.shadowBlur = 13;
ctx.fillStyle = '#ffb84d';
ctx.beginPath(); ctx.arc(pPeri.x, pPeri.y, 4.6, 0, TAU); ctx.fill();
ctx.shadowColor = '#57b6ff'; ctx.shadowBlur = 13;
ctx.fillStyle = '#57b6ff';
ctx.beginPath(); ctx.arc(pAph.x, pAph.y, 4.6, 0, TAU); ctx.fill();
ctx.shadowBlur = 0;
ctx.strokeStyle = 'rgba(255,255,255,.85)'; ctx.lineWidth = 1.3;
ctx.beginPath(); ctx.arc(pPeri.x, pPeri.y, 4.6, 0, TAU); ctx.stroke();
ctx.beginPath(); ctx.arc(pAph.x, pAph.y, 4.6, 0, TAU); ctx.stroke();
ctx.restore();
function tipLabel(p, text, dy){
ctx.save();
ctx.font = '600 11px "IBM Plex Sans", sans-serif';
var tw = ctx.measureText(text).width;
ctx.restore();
if (p.x + 30 + tw <= o.w - 6){
leader(ctx, p.x + 5, p.y, p.x + 26, p.y + dy);
label(ctx, text, p.x + 30, p.y + dy, COL.coral, 'left', 11);
} else {
leader(ctx, p.x - 5, p.y, p.x - 26, p.y + dy);
label(ctx, text, p.x - 30, p.y + dy, COL.coral, 'right', 11);
}
}
tipLabel(pPeri, 'perihelion tip — farthest from O · fastest', -2);
tipLabel(pAph, 'aphelion tip — nearest O · slowest', 2);
/* build mode: revealed samples */
if (build.on){
ctx.save();
for (var j = 0; j <= build.idx; j++){
var bs = orbitAt(state.a, state.e, j * periodY(state.a) / build.N);
ctx.fillStyle = COL.violet;
ctx.beginPath(); ctx.arc(SX(bs.vx), SY(bs.vy), 3.4, 0, TAU); ctx.fill();
if (j > 0){
var bp = orbitAt(state.a, state.e, (j - 1) * periodY(state.a) / build.N);
ctx.strokeStyle = 'rgba(216,115,255,.4)'; ctx.lineWidth = 1.2;
ctx.beginPath(); ctx.moveTo(SX(bp.vx), SY(bp.vy)); ctx.lineTo(SX(bs.vx), SY(bs.vy)); ctx.stroke();
}
}
ctx.restore();
}
/* the live velocity arrow + glowing tip sphere in the live speed colour */
arrow(ctx, ox, oy, SX(st.vx), SY(st.vy), COL.violet, 3.4);
planetDot(ctx, SX(st.vx), SY(st.vy), speedColor(st.v, R * (1 - e), R * (1 + e)));
}
function drawHodo(dt){
if (simH.playing && !build.on) simH.t += dt * periodY(state.a) / simH.DUR * simH.speed;
var st = hodoState();
drawHodoPos(st);
drawHodoVel(st);
/* velocity-history bookkeeping */
if (!build.on) recordHistory(st);
/* scrubber follows time */
var scrub = $('scrubH');
if (document.activeElement !== scrub) scrub.value = Math.round(((simH.t / periodY(state.a)) % 1) * 1000);
/* readouts */
$('hNu').innerHTML = f(st.nu * 180 / Math.PI, 1) + '°';
$('hR').innerHTML = f(st.r, 3) + ' <small>AU</small>';
$('hV').innerHTML = f(st.v, 2) + ' <small>km/s</small>';
$('hVx').innerHTML = f(st.vx, 2) + ' <small>km/s</small>';
$('hVy').innerHTML = f(st.vy, 2) + ' <small>km/s</small>';
var distC = Math.hypot(st.vx - 0, st.vy - state.e * st.R);
$('hCheck').textContent = Math.abs(distC - st.R).toExponential(1) + ' km/s ✓';
/* speed thermometer */
var thM = $('thMarker');
if (thM){
var vminT = st.R * (1 - state.e), vmaxT = st.R * (1 + state.e);
var tp = vmaxT > vminT ? (st.v - vminT) / (vmaxT - vminT) : 0.5;
tp = Math.max(0, Math.min(1, tp));
thM.style.left = (tp * 100).toFixed(1) + '%';
$('thFill').style.width = (tp * 100).toFixed(1) + '%';
$('thVal').textContent = f(st.v, 2) + ' km/s';
}
if (build.on){
$('bLabel').textContent = build.idx >= build.N - 1
? 'Sample ' + (build.idx + 1) + ' of ' + build.N + ' — circle complete: every tip lies on it.'
: 'Sample ' + (build.idx + 1) + ' of ' + build.N + ' · ν = ' + f(st.nu * 180 / Math.PI, 0) + '° · v = ' + f(st.v, 2) + ' km/s';
$('bPrev').disabled = build.idx <= 0;
$('bNext').disabled = build.idx >= build.N - 1;
}
}
/* ============================================================
QUIZ
============================================================ */
var QUIZ = [
{ q: 'In Kepler\u2019s first law, where does the Sun sit in a planet\u2019s orbit?',
opts: ['At the centre of the ellipse', 'At one of the two foci', 'At the end of the minor axis', 'Just outside the ellipse'],
ans: 1, why: 'The Sun occupies one focus, F\u2081. The other focus is empty space \u2014 yet the ellipse is defined by both: r\u2081 + r\u2082 = 2a at every point.' },
{ q: 'A planet on an eccentric orbit moves fastest when it is\u2026',
opts: ['At aphelion, farthest from the Sun', 'Halfway between the apsides', 'At perihelion, closest to the Sun', 'Nowhere \u2014 its speed is constant'],
ans: 2, why: 'Equal areas in equal times (Law 2): with a short radius near the Sun, the planet must sweep it quickly. v_peri / v_aph = (1+e)/(1\u2212e).' },
{ q: 'A planet orbits at a = 4 AU. What is its period?',
opts: ['4 years', '8 years', '16 years', '64 years'],
ans: 1, why: 'T = a^1.5 = 4^1.5 = \u221a(4\u00b3) = \u221a64 = 8 years. Doubling a would multiply T by 2^1.5 \u2248 2.83, not by 2.' },
{ q: 'On the hodograph, the tip point nearest the origin corresponds to the planet at\u2026',
opts: ['Perihelion \u2014 its fastest', 'Aphelion \u2014 its slowest', 'The crossing of the minor axis', 'It never approaches the origin'],
ans: 1, why: 'Distance from the hodograph origin is the speed itself. The nearest tip is the minimum speed, R(1\u2212e), reached at aphelion.' },
{ q: 'For a perfectly circular orbit (e = 0), the hodograph is\u2026',
opts: ['A single point', 'An ellipse, like the orbit', 'A circle centred on the origin', 'A circle passing through the origin'],
ans: 2, why: 'The centre offset is e\u00b7R = 0, so the circle is centred at O, and the tip\u2019s distance from O \u2014 the speed \u2014 is the constant R.' }
];
var quizDone = 0, quizRight = 0;
(function buildQuiz(){
var wrap = $('quizWrap');
var qd = $('qDots');
if (qd) QUIZ.forEach(function(){ var d = document.createElement('span'); d.className = 'qd'; qd.appendChild(d); });
QUIZ.forEach(function(item, qi){
var box = document.createElement('div');
box.className = 'quiz-q';
var h = document.createElement('h3');
h.innerHTML = '<span class="qn">Q' + (qi + 1) + '</span>' + item.q;
box.appendChild(h);
var opts = document.createElement('div');
opts.className = 'opts';
item.opts.forEach(function(text, oi){
var b = document.createElement('button');
b.type = 'button'; b.className = 'opt'; b.textContent = text;
b.addEventListener('click', function(){
if (box.dataset.done) return;
box.dataset.done = '1';
quizDone++;
var right = oi === item.ans;
if (right) quizRight++;
var qdot = $('qDots') ? $('qDots').children[qi] : null;
if (qdot) qdot.className = 'qd ' + (right ? 'ok' : 'no');
opts.querySelectorAll('.opt').forEach(function(x, xi){
x.disabled = true;
if (xi === item.ans) x.classList.add('right');
else if (x === b) x.classList.add('wrong');
});
why.classList.add('show');
$('quizScore').textContent = 'Answered ' + quizDone + ' of ' + QUIZ.length + ' · ' + quizRight + ' correct' + (quizDone === QUIZ.length ? (quizRight === QUIZ.length ? ' — perfect score.' : ' — review the chapters above for the misses.') : '');
});
opts.appendChild(b);
});
box.appendChild(opts);
var why = document.createElement('p');
why.className = 'why';
why.innerHTML = '<b>Why:</b> ' + item.why;
box.appendChild(why);
wrap.appendChild(box);
});
})();
/* ============================================================
Main loop — one rAF, offscreen canvases skipped
============================================================ */
function visible(o){
var r = o.cv.getBoundingClientRect();
return r.bottom > -40 && r.top < window.innerHeight + 40 && r.width > 40;
}
var lastTs = 0, uiTick = 0;
function frame(ts){
requestAnimationFrame(frame);
var dt = Math.min(0.05, lastTs ? (ts - lastTs) / 1000 : 0.016);
lastTs = ts;
if (visible(cv1)) drawLaw1(sim1.playing ? dt : 0);
if (visible(cv2)) drawLaw2(sim2.playing ? dt : 0);
if (visible(cvP) || visible(cvV)) drawHodo(simH.playing && !build.on ? dt : 0);
if (visible(cv3)){
if (!chartSeen){ chartSeen = true; chartStart = performance.now(); }
if (uiTick++ % 30 === 0) drawChart();
}
if (visible(heroCv)) drawHero(dt);
if (visible(mini1)) drawMinis(ts);
drawBg(REDUCED ? 0 : ts);
}
/* ============================================================
CINEMATIC LAYER — page starfield, hero stage, law-card minis,
scroll reveal. Visual only: no physics, data or wording changes.
============================================================ */
var REDUCED = !!(window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches);
/* page starfield — twinkling stars behind the nebula gradients */
var bgCv = $('bgStars'), bgCtx = bgCv ? bgCv.getContext('2d') : null, bgStars = [];
function sizeBg(){
if (!bgCv) return;
bgCv.width = window.innerWidth; bgCv.height = window.innerHeight;
bgStars = [];
var n = Math.round(window.innerWidth * window.innerHeight / 8500);
for (var i = 0; i < n; i++) bgStars.push({ x: Math.random() * bgCv.width, y: Math.random() * bgCv.height, r: Math.random() < 0.12 ? 1.7 : 1, ph: Math.random() * TAU, sp: 0.4 + Math.random() * 0.9 });
}
window.addEventListener('resize', sizeBg);
sizeBg();
function drawBg(ts){
if (!bgCtx) return;
bgCtx.clearRect(0, 0, bgCv.width, bgCv.height);
bgCtx.fillStyle = '#dfe8ff';
for (var i = 0; i < bgStars.length; i++){
var s = bgStars[i];
bgCtx.globalAlpha = 0.22 + 0.55 * (0.5 + 0.5 * Math.sin(ts / 1000 * s.sp + s.ph));
bgCtx.fillRect(s.x, s.y, s.r, s.r);
}
bgCtx.globalAlpha = 1;
}
/* hero stage — glowing Sun with corona and rays, planet whipping around an ellipse */
var heroCv = makeCanvas('heroCv');
var hero = { t: 0, trail: [] };
function drawHero(dt){
var a = 2.3, e = 0.55;
hero.t += dt * periodY(a) / 24;
var st = orbitAt(a, e, hero.t);
var o = heroCv, ctx = o.ctx;
ctx.clearRect(0, 0, o.w, o.h);
drawStars(o);
var tr = orbitTransform(o, a, e, 54);
ctx.save();
var og = ctx.createLinearGradient(0, 0, o.w, 0);
og.addColorStop(0, '#2fe8d8'); og.addColorStop(0.55, '#57b6ff'); og.addColorStop(1, '#d873ff');
ctx.strokeStyle = og; ctx.lineWidth = 2.4;
ctx.shadowColor = 'rgba(87,182,255,.55)'; ctx.shadowBlur = 12;
ctx.beginPath();
for (var i = 0; i <= 180; i++){
var E = i / 180 * TAU;
var x = tr.ox + (a * Math.cos(E) - a * e) * tr.s;
var y = tr.oy - tr.b * Math.sin(E) * tr.s;
if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
}
ctx.stroke();
ctx.restore();
var now = performance.now();
ctx.save();
ctx.translate(tr.ox, tr.oy); ctx.rotate(now / 26000);
ctx.fillStyle = 'rgba(246,183,60,.05)';
for (var ri = 0; ri < 12; ri++){
ctx.rotate(TAU / 12);
ctx.beginPath(); ctx.moveTo(0, -3); ctx.lineTo(Math.max(o.w, o.h) * 0.75, 0); ctx.lineTo(0, 3); ctx.closePath(); ctx.fill();
}
ctx.restore();
var g = ctx.createRadialGradient(tr.ox, tr.oy, 1, tr.ox, tr.oy, 120);
g.addColorStop(0, 'rgba(255,226,160,.95)');
g.addColorStop(0.14, 'rgba(246,183,60,.55)');
g.addColorStop(0.4, 'rgba(246,150,50,.16)');
g.addColorStop(1, 'rgba(246,150,50,0)');
ctx.save();
ctx.fillStyle = g;
ctx.beginPath(); ctx.arc(tr.ox, tr.oy, 120, 0, TAU); ctx.fill();
ctx.fillStyle = '#fff3cf'; ctx.shadowColor = 'rgba(246,183,60,.9)'; ctx.shadowBlur = 30;
ctx.beginPath(); ctx.arc(tr.ox, tr.oy, 13, 0, TAU); ctx.fill();
ctx.restore();
var px = tr.ox + st.x * tr.s, py = tr.oy - st.y * tr.s;
var lh = hero.trail[hero.trail.length - 1];
if (!lh || Math.hypot(st.x - lh[0], st.y - lh[1]) > 0.006 * a) hero.trail.push([st.x, st.y, st.v]);
if (hero.trail.length > 130) hero.trail.shift();
drawTrail(ctx, tr, hero.trail, st, e);
planetDot(ctx, px, py, speedColor(st.v, st.R * (1 - e), st.R * (1 + e)));
}
/* law-card mini diagrams */
var mini1 = makeCanvas('mini1'), mini2 = makeCanvas('mini2'), mini3 = makeCanvas('mini3');
function drawMinis(ts){
var t = ts / 1000;
/* mini 1 — ellipse, two foci, orbiting planet */
(function(){
var o = mini1, ctx = o.ctx, a = 1, e = 0.45, b = Math.sqrt(1 - e * e);
ctx.clearRect(0, 0, o.w, o.h);
var s = Math.min((o.w - 36) / (2 * a), (o.h - 18) / (2 * b));
var cx = o.w / 2 + a * e * s, cy = o.h / 2;
ctx.save();
ctx.strokeStyle = 'rgba(87,182,255,.85)'; ctx.lineWidth = 1.6;
ctx.shadowColor = 'rgba(87,182,255,.6)'; ctx.shadowBlur = 7;
ctx.beginPath();
for (var i = 0; i <= 90; i++){ var E = i / 90 * TAU; var x = cx + (a * Math.cos(E) - a * e) * s, y = cy - b * Math.sin(E) * s; if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); }
ctx.stroke(); ctx.restore();
ctx.save(); ctx.fillStyle = '#ffd98a'; ctx.shadowColor = '#f6b73c'; ctx.shadowBlur = 10;
ctx.beginPath(); ctx.arc(cx, cy, 3.6, 0, TAU); ctx.fill(); ctx.restore();
ctx.save(); ctx.strokeStyle = 'rgba(163,177,200,.8)'; ctx.lineWidth = 1.2;
ctx.beginPath(); ctx.arc(cx - 2 * a * e * s, cy, 3.4, 0, TAU); ctx.stroke(); ctx.restore();
var st = orbitAt(a, e, t * periodY(a) / 9);
planetDot(ctx, cx + st.x * s, cy - st.y * s, speedColor(st.v, st.R * (1 - e), st.R * (1 + e)));
})();
/* mini 2 — sector sweeping from the Sun */
(function(){
var o = mini2, ctx = o.ctx, a = 1, e = 0.4, b = Math.sqrt(1 - e * e);
ctx.clearRect(0, 0, o.w, o.h);
var s = Math.min((o.w - 36) / (2 * a), (o.h - 18) / (2 * b));
var ecx = o.w / 2, cy = o.h / 2, sx = ecx + a * e * s;
var Ec = (t * 0.85) % TAU;
ctx.save();
ctx.beginPath();
ctx.moveTo(sx, cy);
for (var i = 0; i <= 40; i++){ var E = Ec - 1.15 + 1.15 * i / 40; ctx.lineTo(ecx + a * Math.cos(E) * s, cy - b * Math.sin(E) * s); }
ctx.closePath();
var gr = ctx.createRadialGradient(sx, cy, 2, sx, cy, a * s * 1.2);
gr.addColorStop(0, 'rgba(255,190,80,.5)'); gr.addColorStop(1, 'rgba(47,212,196,.28)');
ctx.fillStyle = gr; ctx.fill();
ctx.restore();
ctx.save();
ctx.strokeStyle = 'rgba(143,165,200,.6)'; ctx.lineWidth = 1.3;
ctx.beginPath();
for (var j = 0; j <= 90; j++){ var E2 = j / 90 * TAU; var x2 = ecx + a * Math.cos(E2) * s, y2 = cy - b * Math.sin(E2) * s; if (j === 0) ctx.moveTo(x2, y2); else ctx.lineTo(x2, y2); }
ctx.stroke(); ctx.restore();
ctx.save(); ctx.fillStyle = '#ffd98a'; ctx.shadowColor = '#f6b73c'; ctx.shadowBlur = 10;
ctx.beginPath(); ctx.arc(sx, cy, 3.6, 0, TAU); ctx.fill(); ctx.restore();
var px = ecx + a * Math.cos(Ec) * s, py = cy - b * Math.sin(Ec) * s;
ctx.save(); ctx.strokeStyle = '#57b6ff'; ctx.lineWidth = 1.6;
ctx.beginPath(); ctx.moveTo(sx, cy); ctx.lineTo(px, py); ctx.stroke(); ctx.restore();
planetDot(ctx, px, py, '#7fe7ff');
})();
/* mini 3 — a^3 and T^2 bars growing together, always equal */
(function(){
var o = mini3, ctx = o.ctx;
ctx.clearRect(0, 0, o.w, o.h);
var base = o.h - 14, maxH = o.h - 30;
var grow = REDUCED ? 1 : Math.min(1, (ts % 3400) / 1300);
var vals = [1, 8, 27], gw = Math.min(34, (o.w - 60) / 6);
for (var gi = 0; gi < 3; gi++){
var hgt = Math.max(2, maxH * (vals[gi] / 27) * grow);
var bx = o.w / 2 + (gi - 1) * gw * 2.1 - gw;
ctx.save();
ctx.fillStyle = 'rgba(47,232,216,.75)'; ctx.shadowColor = 'rgba(47,232,216,.6)'; ctx.shadowBlur = 7;
ctx.fillRect(bx, base - hgt, gw * 0.72, hgt);
ctx.fillStyle = 'rgba(216,115,255,.75)'; ctx.shadowColor = 'rgba(216,115,255,.6)';
ctx.fillRect(bx + gw * 0.82, base - hgt, gw * 0.72, hgt);
ctx.restore();
}
ctx.save(); ctx.strokeStyle = 'rgba(163,177,200,.4)';
ctx.beginPath(); ctx.moveTo(10, base + 0.5); ctx.lineTo(o.w - 10, base + 0.5); ctx.stroke(); ctx.restore();
label(ctx, 'a³', o.w / 2 - 52, 9, '#2fe8d8', 'center', 11);
label(ctx, 'T²', o.w / 2 + 52, 9, '#d873ff', 'center', 11);
})();
}
/* scroll reveal — sections fade and slide in once */
(function(){
var els = document.querySelectorAll('section');
els.forEach(function(el){ el.classList.add('reveal'); });
if (REDUCED || !('IntersectionObserver' in window)){
els.forEach(function(el){ el.classList.add('in'); });
return;
}
var io = new IntersectionObserver(function(es){
es.forEach(function(en){ if (en.isIntersecting){ en.target.classList.add('in'); io.unobserve(en.target); } });
}, { threshold: 0.06 });
els.forEach(function(el){ io.observe(el); });
})();
/* ---------- init ---------- */
bindParamUI();
buildPresets('presets1', PRESETS1);
buildPresets('presets2', PRESETS2);
setActivePreset('Earth');
syncParamUI();
resetLaw2();
calcUpdate();
drawChart();
if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches){
sim1.playing = sim2.playing = simH.playing = false;
$('play1').textContent = '▶ Play'; $('play2').textContent = '▶ Play'; $('playH').textContent = '▶ Play';
}
requestAnimationFrame(frame);
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="color-scheme" content="dark" />
<link rel="icon" href="data:," />
<title>Kepler Laws</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&family=Spectral:ital,wght@0,500;0,600;0,700;1,500;1,600&family=Unbounded:wght@500;700;900&display=swap" rel="stylesheet" />
<style>
button, [role="button"], select, summary, input:not([type="checkbox"], [type="radio"]) { min-height: 2rem; }
* { box-sizing: border-box; }
:root{
--bg:#05080f; --bg2:#080d18; --panel:#0b1120; --panel2:#0e1729;
--line:#1d2a44; --line2:#27395e;
--ink:#e9edf5; --muted:#a3b1c8; --faint:#6b7a94;
--amber:#f6b73c; --teal:#2fd4c4; --coral:#ff7a59; --blue:#6f9dff; --pink:#ef6a9a;
--good:#43d17c; --bad:#ff6b6b;
--serif:"Spectral", Georgia, serif;
--sans:"IBM Plex Sans", system-ui, sans-serif;
--mono:"IBM Plex Mono", ui-monospace, monospace;
}
html{ scroll-behavior:smooth; }
body{
margin:0; background:var(--bg); color:var(--ink);
font-family:var(--sans); font-size:16.5px; line-height:1.62;
-webkit-font-smoothing:antialiased;
}
body::before{
content:""; position:fixed; inset:0; z-index:-1; pointer-events:none;
background:
radial-gradient(1px 1px at 12% 22%, rgba(255,255,255,.75) 50%, transparent 51%),
radial-gradient(1px 1px at 68% 8%, rgba(255,255,255,.5) 50%, transparent 51%),
radial-gradient(1.5px 1.5px at 84% 34%, rgba(255,255,255,.65) 50%, transparent 51%),
radial-gradient(1px 1px at 33% 58%, rgba(255,255,255,.45) 50%, transparent 51%),
radial-gradient(1px 1px at 52% 78%, rgba(255,255,255,.55) 50%, transparent 51%),
radial-gradient(1.5px 1.5px at 24% 88%, rgba(255,255,255,.4) 50%, transparent 51%),
radial-gradient(1px 1px at 92% 66%, rgba(255,255,255,.5) 50%, transparent 51%),
radial-gradient(1px 1px at 44% 14%, rgba(255,255,255,.6) 50%, transparent 51%),
radial-gradient(1px 1px at 6% 48%, rgba(255,255,255,.4) 50%, transparent 51%),
radial-gradient(1px 1px at 76% 92%, rgba(255,255,255,.45) 50%, transparent 51%),
radial-gradient(ellipse 90% 55% at 50% -10%, #101c33 0%, transparent 60%),
linear-gradient(180deg, var(--bg2), var(--bg) 340px);
}
.wrap{ max-width:1120px; margin:0 auto; padding:0 20px 80px; }
a{ color:var(--teal); }
a:hover{ color:#7ce8dc; }
/* ---------- sticky chapter nav ---------- */
nav.chapters{
position:sticky; top:0; z-index:50;
background:rgba(5,8,15,.88); backdrop-filter:blur(10px);
border-bottom:1px solid var(--line);
}
nav.chapters .inner{
max-width:1120px; margin:0 auto; padding:0 20px;
display:flex; gap:4px; align-items:center; flex-wrap:wrap;
}
nav.chapters a{
color:var(--muted); text-decoration:none; white-space:nowrap;
font-size:13.5px; font-weight:600; letter-spacing:.02em;
padding:12px 10px; min-height:44px; display:flex; align-items:center;
}
nav.chapters a:hover{ color:var(--ink); }
nav.chapters a.hot{ color:var(--teal); }
/* ---------- hero ---------- */
header.hero{ padding:64px 0 30px; }
.hero .kicker{
font-family:var(--mono); font-size:12.5px; letter-spacing:.22em;
text-transform:uppercase; color:var(--amber); margin:0 0 18px;
}
.hero h1{
font-family:var(--serif); font-weight:600; line-height:1.08;
font-size:clamp(34px, 6vw, 58px); margin:0 0 14px; max-width:16em;
}
.hero h1 em{ font-style:italic; color:var(--teal); }
.hero .lede{ color:var(--muted); font-size:18px; max-width:44em; margin:0 0 30px; }
.laws-oneline{
border:1px solid var(--line); background:var(--panel);
border-radius:10px; padding:8px 22px; margin:0 0 26px;
}
.laws-oneline p{
margin:0; padding:13px 0; display:flex; gap:16px; align-items:baseline;
border-bottom:1px solid var(--line); font-size:16.5px;
}
.laws-oneline p:last-child{ border-bottom:none; }
.laws-oneline .n{
font-family:var(--mono); color:var(--amber); font-weight:600; font-size:14px;
flex:0 0 auto;
}
.surprise{
border:1px solid #14524b; background:linear-gradient(180deg, #0a1f1d, #081614);
border-radius:10px; padding:20px 22px; margin:0;
}
.surprise .tag{
font-family:var(--mono); font-size:11.5px; letter-spacing:.2em; text-transform:uppercase;
color:var(--teal); display:block; margin-bottom:8px;