HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<p data-field="units">
<label for="units">Units:</label>
<select name="unit" id="units">
<option value="in">in</option>
<option value="mm">mm</option>
</select>
</p>
<h2>Oscillator</h2>
<ul>
<li data-field="beats">
<label for="beats-in">Seconds:</label>
<input id="beats-in" type="number" min="0.25" max="4" value="1" step="0.01">
<i>bps</i>
</li>
<li>
Minutes:
<output id="bpm" for="beats-in">3600</output>
<i>bpm</i>
</li>
<li>
Hours:
<output id="bph" for="beats-in">3600</output>
<i>bph</i>
</li>
</ul>
<ul>
<li>
Pendulum:
~<output id="pendulum-theory-out" for="beats-in">??</output>
<output for="units">in</output>
</li>
<li class="pendulum-safe">
20% Buffer:
~<output id="pendulum-safe-out" for="beats-in">??</output>
<output for="units">in</output>
</li>
</ul>
<h2>Going Train: Gear Ratios</h2>
<p>Escape Arbor:</p>
<ul>
<li data-field="escape-wheel">
<label for="escape-wheel">Escape Wheel:</label>
<input id="escape-wheel" type="number" min="15" max="60" value="30">
<i>teeth</i>
</li>
<li data-field="escape-factor">
<label for="escape-factor">Escape Factor:</label>
<select id="escape-factor">
<option value="1">1</option>
<option value="2" selected>2</option>
</select>
<i>beats per tooth</i>
</li>
<li data-field="third-pinion">
<label for="third-pinion">Third Wheel Pinion:</label>
<input id="third-pinion" type="number" min="7" max="12" value="8">
<i>leaves</i>
</li>
</ul>
<p>Third Wheel Arbor:</p>
<ul>
<li data-field="third-wheel">
<label for="third-wheel">Third Wheel:</label>
<input id="third-wheel" type="number" min="15" max="120" value="60">
<i>teeth</i>
</li>
<li data-field="center-pinion">
<label for="center-pinion">Center Wheel Pinion:</label>
<input id="center-pinion" type="number" min="7" max="12" value="8">
<i>leaves</i>
</li>
</ul>
<p>Center Wheel Arbor</p>
<ul>
<li>
Center Wheel:
<output id="center-wheel" for="beats-in escape-wheel third-pinion third-wheel center-pinion">??</output>
<i>teeth</i>
</li>
</ul>
<p>
Total:
<output id="total-spurs" for="escape-wheel third-pinion third-wheel center-pinion">??</output>
<i>spurs</i>
</p>
<h2>Going Train: Measurements</h2>
<p>Center Wheel & Pinion:</p>
<ul>
<li data-field="center-od">
<label for="center-od">Wheel Outside Diameter:</label>
<input id="center-od" type="number" min="1" value="8" step="0.5">
<output for="units">in</output>
</li>
<li>
Wheel Pitch Diameter:
<output id="center-pd">??</output>
<output for="units">in</output>
</li>
<li>
Spur Width:
<output id="center-w">??</output>
<output for="units">in</output>
</li>
<li>
Pinion Pitch Diameter:
<output id="center-pinion-pd">??</output>
<output for="units">in</output>
</li>
<li>
Arbor Spacing:
<output id="center-set-spacing">??</output>
<output for="units">in</output>
</li>
</ul>
<p>Third Wheel & Pinion:</p>
<ul>
<li data-field="eq-spurs">
<input id="eq-spurs" type="checkbox" checked>
<label for="eq-spurs">Use Center Wheel Spur Width?</label>
</li>
<li data-field="third-od-in" data-hide="eq-spurs" hidden>
<label for="third-od-in">Wheel Outside Diameter:</label>
<input id="third-od-in" type="number" min="1" value="8" step="0.5">
<output for="units">in</output>
</li>
<li data-show="eq-spurs">
Wheel Outside Diameter:
<output id="third-od">??</output>
<output for="units">in</output>
</li>
<li>
Wheel Pitch Diameter:
<output id="third-pd">??</output>
<output for="units">in</output>
</li>
<li>
Spur Width:
<output id="third-w">??</output>
<output for="units">in</output>
</li>
<li>
Pinion Pitch Diameter:
<output id="third-pinion-pd">??</output>
<output for="units">in</output>
</li>
<li>
Arbor Spacing:
<output id="third-set-spacing">??</output>
<output for="units">in</output>
</li>
</ul>
html {
font-family: monospace;
font-size: 1.2em;
}
output:not([for=units]) {
font-weight: bold;
}
i {
font-style: normal;
}
// utils
const r = (n, d = 2) => {
const f = Math.pow(10, d);
return Math.round(n * f) / f;
};
// unit selection
const units = {
in: document.getElementById('units'),
out: document.querySelectorAll('output[for=units]'),
};
const setUnits = () => {
units.out.forEach((el) => {
el.value = units.in.value;
});
}
// pendulum calculations
const beats = {
in: document.getElementById('beats-in'),
bpm: document.getElementById('bpm'),
bph: document.getElementById('bph'),
};
const pendulum = {
theory: document.getElementById('pendulum-theory-out'),
try: document.getElementById('pendulum-safe-out'),
};
const getBpm = () => parseFloat(beats.in.value, 10) * 60;
const getBph = () => getBpm() * 60;
const setBeats = () => {
beats.bpm.value = r(getBpm());
beats.bph.value = r(getBph());
};
const setLength = () => {
const bpm = Math.pow(getBpm(), 2);
let L = 141220 / bpm;
if (units.in.value === 'mm') {
L = (3578.4 / bpm) * 1000;
}
pendulum.theory.value = r(L);
pendulum.try.value = r(L * 0.2);
}
// going train calculations
const going = {
escape: {
wheel: document.getElementById('escape-wheel'),
factor: document.getElementById('escape-factor'),
},
third: {
pinion: document.getElementById('third-pinion'),
wheel: document.getElementById('third-wheel'),
},
center: {
pinion: document.getElementById('center-pinion'),
wheel: document.getElementById('center-wheel'),
},
spurs: document.getElementById('total-spurs'),
};
const setCenter = () => {
const escape = {
wheel: parseInt(going.escape.wheel.value, 10),
factor: parseInt(going.escape.factor.value, 10),
pinion: parseInt(going.third.pinion.value, 10),
};
const third = {
wheel: parseInt(going.third.wheel.value, 10),
pinion: parseInt(going.center.pinion.value, 10),
};
const e = escape.wheel * escape.factor;
const t = third.wheel / escape.pinion;
const p = third.pinion;
const c = getBph() / (e * t) * p;
going.center.wheel.value = r(c, 4);
};
const setSpurs = () => {
const g = {
ew: parseInt(going.escape.wheel.value, 10),
tp: parseInt(going.third.pinion.value, 10),
tw: parseInt(going.third.wheel.value, 10),
cp: parseInt(going.center.pinion.value, 10),
cw: parseInt(going.center.wheel.value, 10),
};
going.spurs.value = Object.values(g).reduce((sub, item) => sub + item, 0);
};
// wheel sizing
const sizes = {
third: {
od: document.getElementById('third-od-in'),
odRead: document.getElementById('third-od'),
pd: document.getElementById('third-pd'),
w: document.getElementById('third-w'),
ppd: document.getElementById('third-pinion-pd'),
set: document.getElementById('third-set-spacing'),
useW: document.getElementById('eq-spurs'),
hide: document.querySelectorAll('[data-hide=eq-spurs]'),
show: document.querySelectorAll('[data-show=eq-spurs]'),
},
center: {
od: document.getElementById('center-od'),
pd: document.getElementById('center-pd'),
w: document.getElementById('center-w'),
ppd: document.getElementById('center-pinion-pd'),
set: document.getElementById('center-set-spacing'),
},
};
const spursDiv = (s) => (s / (s + 2));
const getSizeFromOD = (wheel) => {
const ws = parseInt(going[wheel].wheel.value, 10);
const ps = parseInt(going[wheel].pinion.value, 10);
const wpd = parseFloat(sizes[wheel].od.value) * spursDiv(ws);
const w = wpd * Math.PI / ws;
const ppd = (ps * w) / Math.PI;
const set = (ppd + wpd) / 2;
return { wpd, w, ppd, set, };
}
const getSizeFromW = (wheel, w) => {
const ws = parseInt(going[wheel].wheel.value, 10);
const ps = parseInt(going[wheel].pinion.value, 10);
const wpd = (ws * w) / Math.PI;
const ppd = (ps * w) / Math.PI;
const set = (ppd + wpd) / 2;
const od = wpd / spursDiv(ws);
return { wpd, w, ppd, set, od, };
}
const setGearSizing = (wheel, w) => {
const els = sizes[wheel];
const s = w
? getSizeFromW(wheel, parseFloat(w, 10))
: getSizeFromOD(wheel);
els.pd.value = r(s.wpd);
els.w.value = r(s.w);
els.ppd.value = r(s.ppd);
els.set.value = r(s.set);
if (s.od) {
els.odRead.value = r(s.od);
}
}
// initialize
const calcSizing = () => {
setGearSizing('center');
const hide = (el, hidden) => {
hidden
? el.setAttribute('hidden', '')
: el.removeAttribute('hidden');
}
if (sizes.third.useW.checked) {
sizes.third.hide.forEach((el) => hide(el, true));
sizes.third.show.forEach((el) => hide(el, false));
setGearSizing('third', sizes.center.w.value);
} else {
sizes.third.hide.forEach((el) => hide(el, false));
sizes.third.show.forEach((el) => hide(el, true));
setGearSizing('third');
}
}
const calcTrain = () => {
setCenter();
setSpurs();
calcSizing();
};
const calc = () => {
setUnits();
setBeats();
setLength();
calcTrain();
};
units.in.addEventListener('input', (e) => calc());
beats.in.addEventListener('input', (e) => calc());
going.escape.wheel.addEventListener('input', (e) => calcTrain());
going.escape.factor.addEventListener('input', (e) => calcTrain());
going.third.pinion.addEventListener('input', (e) => calcTrain());
going.third.wheel.addEventListener('input', (e) => calcTrain());
going.center.pinion.addEventListener('input', (e) => calcTrain());
sizes.center.od.addEventListener('input', (e) => calcSizing());
sizes.third.od.addEventListener('input', (e) => calcSizing());
sizes.third.useW.addEventListener('input', (e) => calcSizing());
calc();
Also see: Tab Triggers