Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<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>

              
            
!

CSS

              
                html {
  font-family: monospace;
  font-size: 1.2em;
}

output:not([for=units]) {
  font-weight: bold;
}

i {
  font-style: normal;
}

              
            
!

JS

              
                // 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();

              
            
!
999px

Console