Percent slope → degrees

HTML for this example

Select the code and use your copy shortcut. Changes in this preview are temporary.

<!doctype html><html lang="en-US"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Percent slope → degrees</title><style>*{box-sizing:border-box}html{color-scheme:light}body{margin:0;background:var(--bg,#eef1f4);color:var(--ink,#233449);font:16px/1.5 system-ui,-apple-system,Segoe UI,sans-serif}main{max-width:1040px;margin:auto;padding:26px 28px 44px}header{margin-bottom:20px}h1{font-size:clamp(26px,4vw,36px);letter-spacing:-.035em;line-height:1.15;margin:5px 0 10px}h2{font-size:21px;line-height:1.3;margin:0 0 15px}h3{font-size:17px;margin:0 0 9px}p{margin:8px 0 16px}.kicker{font-size:12px;text-transform:uppercase;letter-spacing:.12em;font-weight:750;color:var(--accent,#315b87)}.muted,small{color:#556473}.panel{margin:20px 0;padding:24px;border:1px solid var(--line,#ccd5df);border-radius:10px;background:#fff}.hero{padding:24px;background:var(--hero,#183b5c);color:#fff;border-radius:12px;margin:18px 0}.hero .kicker,.hero small{color:#d9e5ef}.big{font-size:clamp(32px,5vw,52px);line-height:1.15;font-weight:750;letter-spacing:-.035em;overflow-wrap:anywhere;margin:10px 0 15px}.row{display:flex;flex-wrap:wrap;gap:15px;align-items:end}.row>label{flex:1;min-width:140px}.grid{display:grid;grid-template-columns:1fr 1fr;gap:20px}.thirds{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:15px}label{display:block;font-size:14px;font-weight:650}input,select,textarea{font:inherit;font-size:16px;color:inherit;display:block;width:100%;margin-top:6px;padding:11px 12px;border:1px solid #a9b4c1;border-radius:6px;background:white;min-width:0}input[type=checkbox]{display:inline;width:auto;margin:0 8px 0 0;accent-color:var(--accent,#315b87)}textarea{min-height:100px;resize:vertical}button{font:inherit;font-weight:650;min-height:44px;border:1px solid var(--accent,#315b87);border-radius:6px;background:var(--accent,#315b87);color:white;padding:10px 16px;cursor:pointer}button.secondary{background:white;color:var(--accent,#315b87)}button:disabled{opacity:.5;cursor:default}button[aria-pressed=true]{box-shadow:0 0 0 3px #eab655}button:hover:not(:disabled){filter:brightness(.94)}:focus-visible{outline:3px solid #e5a72f;outline-offset:3px}.actions{display:flex;flex-wrap:wrap;gap:10px;margin:18px 0 0}[hidden]{display:none!important}.error{color:#a3232a;font-weight:650}.error:not(:empty){padding:12px;background:#fff0ed;border-left:4px solid #ab3439;margin:14px 0}.note{padding:14px;background:#edf2f6;border-radius:6px;margin:14px 0}.mono,pre{font-family:ui-monospace,Consolas,monospace;font-variant-numeric:tabular-nums}pre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px;line-height:1.7;margin:0}.mono{overflow-wrap:anywhere}table{width:100%;border-collapse:collapse;table-layout:fixed;font-size:14px}th,td{text-align:left;vertical-align:top;overflow-wrap:anywhere;padding:11px 8px;border-bottom:1px solid #d4dce4}th{font-size:12px;text-transform:uppercase;letter-spacing:.035em;color:#536372}th:first-child,td:first-child{padding-left:0}.tag{display:inline-block;padding:4px 8px;border:1px solid currentColor;border-radius:4px;font-size:12px;font-weight:750}.rule{border-top:1px solid #cbd4dd;padding-top:18px}.line{height:30px;border-bottom:1px solid #aab5bf}.stat{font-size:34px;line-height:1.15;font-weight:750}.stat small{font:14px system-ui;display:block;margin-top:8px}details{margin:20px 0;border-top:1px solid #cbd4dd;padding:18px 0}summary{font-weight:700;cursor:pointer}details p{margin-top:15px}a{color:var(--accent,#315b87)}footer{font-size:13px;color:#556473;margin-top:25px}fieldset{min-width:0;border:1px solid #c8d2db;border-radius:7px;padding:18px;margin:15px 0}legend{font-weight:750;padding:0 6px}@media(max-width:720px){main{padding:20px}.panel,.hero{padding:20px}.thirds{gap:10px}}@media(max-width:540px){main{padding:16px}.grid,.thirds{grid-template-columns:1fr}.panel,.hero{padding:18px}.row{gap:12px}.row>label{min-width:100px}h1{font-size:27px}th,td{padding:10px 5px;font-size:13px}.big{font-size:37px}}.surface{background:white;border:1px solid #ccd5df;border-radius:10px;padding:24px;margin:18px 0}.metrics{display:flex;gap:34px;flex-wrap:wrap}.metric b{font-size:clamp(32px,5vw,52px);line-height:1.1;display:block;letter-spacing:-.04em}.metric span{display:block;margin-top:8px;font-size:14px}.strip{display:grid;grid-template-columns:repeat(10,minmax(0,1fr));gap:7px;margin:22px 0}.unit{padding:10px 3px;text-align:center;background:#e5f0eb;border-bottom:4px solid #327660;font-size:13px;font-weight:700}.unit.rework{background:#fff0d5;border-color:#aa701d}.unit.fail{background:#f9e2e0;border-color:#ab3d35}.ledger-row{display:grid;grid-template-columns:100px 1fr 140px;gap:18px;padding:18px 0;border-bottom:1px solid #d2dbe3;align-items:start}.ledger-row p{margin:5px 0}.amount{text-align:right;font-size:22px;font-weight:750}.pill{display:inline-block;border-radius:20px;background:#e7edf2;padding:5px 10px;font-size:12px;font-weight:700}.timeline{border-left:3px solid #c7d4de;padding:0 0 0 22px;margin:16px 0}.timeline article{padding:10px 0 18px}.timeline h3{margin-bottom:5px}.timeline p{margin:5px 0}.artifact{font-family:Georgia,serif}.warning{background:#fff3db;border-left:4px solid #a66d18;padding:15px}.empty{color:#5d6771;font-style:italic}.check{color:#22694f}.bad{color:#9a332e}button.linklike{padding:8px 12px;min-height:40px;background:white;color:var(--accent,#315b87)}@media(max-width:540px){.surface{padding:18px}.ledger-row{grid-template-columns:65px 1fr;gap:12px}.ledger-row .amount{grid-column:2;text-align:left}.strip{gap:3px}.unit{font-size:11px;padding:8px 0}.metrics{gap:22px}.metric b{font-size:38px}}.slope-result{border-top:6px solid #4f7b87}.slope-result figure{margin:0}.slope-result svg{width:100%;height:auto;max-height:250px}.slope-result figcaption{font-size:13px;color:#546673}.slope-result .big{font-family:Georgia,serif;font-size:clamp(32px,5vw,48px)}</style></head><body style="--bg:#eff3f5;--accent:#386a7b"><main><header><div class="kicker">Classroom ratio inspector</div><h1>Percent slope → degrees</h1><p class="muted">Use the horizontal run as the denominator, then take the inverse tangent.</p></header><section id="result" class="surface slope-result" aria-live="polite"><div class="grid"><div><div class="kicker" id="basis"></div><div class="big" id="angle"></div><p id="ratio"></p><p id="inverse"></p></div><figure><svg viewBox="0 0 340 240" role="img" aria-label="Schematic right triangle; horizontal run, vertical rise and slanted segment separately labeled"><path id="triangle" fill="#e4f0f2" stroke="#386a7b" stroke-width="3"/><text x="155" y="228" text-anchor="middle" font-size="14">Horizontal run: 100 units</text><text id="riseLabel" x="315" y="30" text-anchor="end" font-size="13"></text><text x="30" y="20" font-size="13">Slanted segment ≠ run</text></svg><figcaption id="diagramNote"></figcaption></figure></div></section><p id="error" class="error" role="alert"></p><form id="form" class="panel" novalidate><div class="row"><label for="mode">Conversion direction<select id="mode"><option value="forward">Percent slope → degrees</option><option value="inverse">Degrees → percent slope</option></select></label><label for="value"><span id="valueLabel">Percent slope (P ≥ 0)</span><input id="value" value="12" inputmode="decimal" autocomplete="off"></label></div><div class="actions"><button>Calculate slope</button><button type="button" id="equal" class="secondary">Try 100%</button><button type="button" id="steep" class="secondary">Try 200%</button><button type="button" id="reset" class="secondary">Reset</button></div></form><section class="panel"><h2>Calculation record</h2><pre id="trace"></pre></section><details><summary>Scope and precision</summary><p>The schematic fixes horizontal run at 100 units; rise uses the same unit. Both legs are scaled together to fit. A very steep or shallow triangle can make one leg smaller than a screen pixel; the actual numbers remain authoritative.</p><p>Unsigned finite percent values, including those above 100%, are accepted. Inverse angles must be at least 0 and below 90°. Plain dot decimals or scientific notation are accepted; signs for negative inputs, blanks, nonfinite values, overflow, and ratios that collapse to exactly 90° at numeric precision are rejected. Results use JavaScript numeric precision; display is rounded to nine places, and inverse checks use the unrounded angle.</p><p>Original classroom schematic, not measured terrain or a construction, access, legal-grade, ramp, or hiking recommendation.</p></details><footer>Local session only · No network or saved progress. Keep maintained source records authoritative.</footer></main><script>const $=id=>document.getElementById(id);const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));

function parse(s){const t=s.trim();if(!t||! /^(?:[0-9]+(?:[.][0-9]*)?|[.][0-9]+)(?:[eE][+-]?[0-9]+)?$/.test(t))throw Error('Enter a nonnegative finite number; blank is missing.');const n=Number(t);if(n===0&&/[1-9]/.test(t.split(/[eE]/)[0]))throw Error('Input is too small to represent at numeric precision.');if(!Number.isFinite(n))throw Error('Value must be finite.');return n}function calculate(mode,raw){const n=parse(raw);let p,theta;if(mode==='forward'){p=n;theta=Math.atan(p/100)*180/Math.PI;if(theta>=90)throw Error('This ratio is too large to resolve below 90° at numeric precision.')}else if(mode==='inverse'){theta=n;if(theta>=90)throw Error('Inverse angle must be below 90°; 90° has no finite slope percent.');p=Math.tan(theta*Math.PI/180)*100;if(theta>0&&p===0)throw Error('Angle is too small to represent a nonzero slope at numeric precision.');}else throw Error('Choose a conversion direction.');if(p>0&&p/100===0)throw Error('Slope ratio is too small to represent at numeric precision.');const rise=p,ratio=p/100,check=Math.tan(theta*Math.PI/180)*100;if(!Number.isFinite(rise)||!Number.isFinite(check))throw Error('Result exceeds finite numeric range.');return {p,theta,ratio,rise,check}}
function degreeDisplay(theta){const rounded=theta.toFixed(9);if(theta>0&&Number(rounded)===0)return '<0.000000001°';if(theta<90&&Number(rounded)===90)return '<90° · within 0.000000001°';return rounded+'°'}
function clear(){$('result').hidden=true;$('trace').textContent='';$('error').textContent=''}function run(){try{const r=calculate($('mode').value,$('value').value);$('basis').textContent=String(r.p)+'% slope · horizontal run 100';$('angle').textContent=degreeDisplay(r.theta);$('ratio').textContent='Rise / horizontal run = '+r.ratio.toPrecision(10);$('inverse').textContent='Inverse check from unrounded angle: '+r.check.toPrecision(12)+'%';const scale=190/Math.max(100,r.rise),w=100*scale,h=r.rise*scale;$('triangle').setAttribute('d','M35 205 L'+(35+w)+' 205 L'+(35+w)+' '+(205-h)+' Z');$('riseLabel').textContent='Rise: '+r.rise.toPrecision(8)+' units';$('diagramNote').textContent='Original schematic · legs share scale '+scale.toPrecision(4)+' drawing units per length unit.';$('trace').textContent='Input: '+$('value').value+' ('+$('mode').value+')\nHorizontal run: 100 length units, positive\nImplied rise: '+r.rise+' same length units\nRatio P/100: '+r.ratio+'\nUnrounded degree angle: '+r.theta+'\natan(P/100) × 180/π\nInverse: tan(unrounded angle × π/180) × 100 = '+r.check+'%';$('result').hidden=false;$('error').textContent=''}catch(e){clear();$('error').textContent=e.message}}function sample(n){$('valueLabel').textContent='Percent slope (P ≥ 0)';$('mode').value='forward';$('value').value=String(n);$('value').setAttribute('aria-label','Percent slope P, nonnegative');run()}$('form').addEventListener('submit',e=>{e.preventDefault();run()});$('value').addEventListener('input',clear);$('mode').addEventListener('change',()=>{clear();$('value').value='';$('value').setAttribute('aria-label',$('mode').value==='forward'?'Percent slope P, nonnegative':'Angle in degrees, zero to less than ninety');$('valueLabel').textContent=$('mode').value==='forward'?'Percent slope (P ≥ 0)':'Angle (0° ≤ θ < 90°)'});$('equal').onclick=()=>sample(100);$('steep').onclick=()=>sample(200);$('reset').onclick=()=>{$('mode').value='forward';$('value').value='';$('valueLabel').textContent='Percent slope (P ≥ 0)';$('value').setAttribute('aria-label','Percent slope P, nonnegative');clear()};run();</script>
<script>
// Local calculation controls: no native form submission or sandbox permissions required.
(()=>{const form=document.getElementById('form');if(!form)throw Error('Calculation form missing');const dispatch=()=>form.dispatchEvent(new Event('submit',{bubbles:true,cancelable:true}));const buttons=[...form.querySelectorAll('button')].filter(button=>button.type==='submit');if(buttons.length!==1)throw Error('Expected one calculation control');for(const button of buttons){button.type='button';button.addEventListener('click',dispatch);}form.addEventListener('keydown',event=>{if(event.key==='Enter'&&!event.isComposing&&['INPUT','SELECT'].includes(event.target.tagName)){event.preventDefault();dispatch();}});})();
</script>
</body></html>