Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <main>
  <section>
  
    <div id="n" class="r n" v-bind:data-label="'Numerator: ' + reduced_n">
      <div>
        <span></span>
      </div>
    </div>

    <div id="o" class="o" v-bind:data-label="'Formula: ' + reduced_n + ' / ' + reduced_d">
      <svg viewbox="0 0 2000 2000">
        <line class="h" x1="0" x2="2000" y1="" y2="" stroke-dasharray="10,10" />
        <line class="v" x1="" x2="" y1="0" y2="2000" stroke-dasharray="10,10" />
        <polyline points="" />
        <circle cx="0" cy="0" r="10" />
      </svg>
    </div>

    <div class="f">
      <div>
        <h1>{{n}} / {{d}} <small>@ {{t}} sec</small></h1>
        <input type="range" class="a" v-model="n" min="1" max="30" placeholder="numerator" /> /
        <input type="range" class="a" v-model="d" min="1" max="30" placeholder="denominator" /> @
        <input type="range" class="b" v-model="t" min="3" max="15" placeholder="timelapse" />
        <h2>
          <label><input type="checkbox" v-model="c" /><span class="button">do it</span></label>
          <span class="button" v-if="r && !c" v-on:click="clear">&times;</span>
        </h2>
      </div>
    </div>

    <div id="d" class="r d" v-bind:data-label="'Denominator: ' + reduced_d">
      <div>
        <span></span>
      </div>
    </div>

  </section>

  <aside>
    <code>&lt;svg viewbox="0 0 2000 2000"&gt;

  &lt;polyline 
    points="{{code}}" /&gt;

&lt;/svg&gt;
    </code>
  </aside>
</main>

              
            
!

CSS

              
                :root {
  --i: 0;
  --r: 0;
  --a: 5000;
  --clr: 0;
}

@keyframes roll {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  overflow: hidden;
  font-family: sans-serif;
  background: #2e2e30;
  color: #d1c4ab;
}
main {
  flex: 1;
  display: flex;
  @media (orientation: portrait) {
    flex-direction: column;
  }
}
section {
  flex: none;
  width: 100vmin;
  height: 100vmin;
  display: flex;
  flex-flow: row wrap;
  overflow: hidden;
  // box-shadow: 1px 1px 0 0 #4b4545;
  > div {
    position: relative;
    flex: 0 0 50vmin;
    display: flex;
    align-items: center;
    justify-content: center;
    // box-shadow: 1px 1px 0 0 #4b4545;
    &::after {
      content: attr(data-label);
      position: absolute;
      font-size: 2vmin;
      top: 2em;
      left: 2em;
      line-height: 1.6;
    }
  }
}

.n::after {
  border-bottom: 1px solid;
}
.d::after {
  border-top: 1px solid;
}

aside {
  flex: 1;
  display: flex;
  background: #4b4545;
  overflow: auto;
  padding: 2em;
  -webkit-overflow-scrolling: touch;
  code {
    white-space: pre-wrap;
  }
}
.o {
  transform:  translateZ(0);
  svg {
    position: absolute;
    pointer-events: none;
    width: 50vmin;
    height: 50vmin;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(2);
    border: 1px dashed #4b4545;
    background: #272729;
    border-radius: 100%;
    will-change: transform;
  }
  circle {
    fill: #d4e34a;
    stroke: #fc6f3a;
    stroke-width: 5px;
  }
  polyline {
    fill: transparent;
    stroke: unquote('hsl(var(--clr), 73%, 59%)'); //#d4e34a;
    stroke-width: 3px;
  }
  line {
    stroke: #4b4545;
    stroke-width: 3px;
  }
}
.r {
  z-index: 1;
  > div {
    position: relative;
    width: 25vmin;
    height: 25vmin;
    box-shadow: 0 0 0 2px #36ccbf inset;
    border-radius: 100%;
  }
  span {
    box-shadow: 0 0 0 1px;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    animation: roll calc((var(--a) * 1ms) / var(--i)) linear var(--i);
    transform: rotate(calc(var(--r) * 1deg));
    transform-origin: 0 50%;
    will-change: transform;
    &::before,
    &::after {
      content: '';
      position: absolute;
      top: 50%;
      width: 1em;
      height: 1em;
      border-radius: 100%;
    }
    &::before {
      left: 0;
      transform: translate(-50%, -50%);
      background: currentColor;
    }
    &::after {
      right: 0;
      transform: translate(50%, -50%);
      box-shadow: 0 0 0 1px #d4e34a;
    }
  }
}

.f {
  position: relative;
  width: 100%;
  h1 {
    color: #d4e34a;
    font-size: 7vmin;
    margin: 0 0 .3em 0;
  }
  h2 {
    margin-bottom: 0;
  }
  small {
    font-size: .35em;
    color: #36ccbf;
  }
}

label input {
  opacity: 0;
  position: absolute;
  &:checked + span {
    background: #fc6f3a
  }
}

.button {
  display: inline-block;
  border: 0;
  font-size: 3vmin;
  line-height: 1;
  padding: .5ch 1ch;
  background: #4b4545;
  font-weight: 200;
  color: #fff;
  border-radius: .4ch;
}

input[type="range"] {
	appearance: none;
	outline: none;
  padding: 0;
  border: 0;
	font-size: 1em;
	width: 9vmin;
  height: 1.2em;
  border-radius: 1em;
  background: rgba(255, 255, 255, .2);
  box-shadow: 0 0 0 1px #d1c4ab;
}
input[type="range"]::-webkit-slider-thumb {
	appearance: none;
	width: 1em;
	height: 1em;
	border: none;
	border-radius: 1em;
	background-image: none;
	transform: scale(0.8);
	transition: .3s ease-out;
  box-shadow: 0 0 1em 0 #000;
}
.a::-webkit-slider-thumb {
	background: #d4e34a;
}
.b::-webkit-slider-thumb {
	background: #36ccbf;
}
input[type="range"]:focus::-webkit-slider-thumb,
input[type="range"]:active::-webkit-slider-thumb {
	appearance: none;
	transform: scale(1.3);
}

              
            
!

JS

              
                let vm = new Vue({
  el: 'main',
  data: {
    n: 4,
    d: 3,
    rn: 3,
    rd: 4,
    c: false,
    t: 5,
    r: false,
    code: '',
    clr: 18
  },
  computed: {
    reduced_n: function() {
      return this.reduce(this.n, this.d).n
    },
    reduced_d: function() {
      return this.reduce(this.n, this.d).d
    }
  },
  methods: {
    clear: function() {
      this.c = false
      this.r = false
      this.code = ''
      _p.setAttribute('points', '');
      draw()
      style.setProperty('--a', this.t * 1000)
    },
    getNumbers: function(target) {
      let rect = {}
      if (target) {
        rect = target.getBoundingClientRect()
        rect.cx = (rect.left + (rect.width / 2))
        rect.cy = (rect.top + (rect.height / 2))
      }
      return rect
    },
    reduce: function(n, d) {
      // from: http://stackoverflow.com/questions/4652468/is-there-a-javascript-function-that-reduces-a-fraction
      let gcd = function(a, b) {
        return b ? gcd(b, a % b) : a
      }
      gcd = gcd(n, d)
      return {n: n/gcd, d: d/gcd}
    }
  }
})

let style = document.documentElement.style
let _n = document.getElementById('n')
let _d = document.getElementById('d')
let _s = document.querySelector('svg')
let _p = _s.querySelector('polyline')
let _c = _s.querySelector('circle')
let _h = _s.querySelector('line.h')
let _v = _s.querySelector('line.v')

let draw = () => {
  let n = vm.getNumbers(_n.querySelector('span'))
  let d = vm.getNumbers(_d.querySelector('span'))
  let x = Math.round(2000 * (d.cx / _n.clientWidth) - 2000)
  let y = Math.round(2000 * (n.cy / _d.clientWidth))
  let p = _s.createSVGPoint()
  vm.clr = vm.clr > 360 ? 0 : vm.clr
  p.x = x
  p.y = y
  _p.points.appendItem(p)
  _h.setAttribute('y1', y)
  _h.setAttribute('y2', y)
  _v.setAttribute('x1', x)
  _v.setAttribute('x2', x)
  _c.setAttribute('cx', x)
  _c.setAttribute('cy', y)
  if(vm.c) {
    style.setProperty('--clr', vm.clr++)
    setTimeout(draw, 25)
  }
}

Vue.nextTick(function() {
  draw()
})

vm.$watch('c', function (c) {
  _n.style.setProperty('--i', (c?vm.reduced_n:0))
  _d.style.setProperty('--i', (c?vm.reduced_d:0))
  if(c) {
    vm.r = true
    style.setProperty('--a', vm.t * 1000)
    style.setProperty('--r', 0)
    draw()
  }
})

vm.$watch('t', vm.clear)

_n.addEventListener('animationend', (e) => {
  vm.c = false
  vm.code = _p.getAttribute('points')
},false)

              
            
!
999px

Console