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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <!-- light before ——— dark after -->
<section class="modal">
  <button data-text="Play"></button>
  <input type="range" min="0" max="99" value="0" autocomplete="off" oninput="phase(this.value)" onchange="phase(this.value)">
  <label for="visualiser">Visualise</label>
</section>

<input hidden type="checkbox" name="visualiser" id="visualiser" />

<div class="moon  moon--to-fq" data-value="0"></div>

            
          
!

CSS

            
              ///
/// Remap a number from one range to another
///
/// @param {Number} $number - Initial Value
/// @param {Number} $ranges - 2/4 minimum/maximum values representing the ranges
///
/// @example scss
///   $variable: range-map(2, 4, 100);
///   // $variable: 50;
///
/// @example scss
///   $variable: range-map(68, 30, 160, 0, 100);
///   // $variable: 42.5;
///
/// @return {Number} Number re-mapped in new range
///
@function range-map($number, $ranges...) {
    @if not $number or not $ranges or not (length($ranges) == 2 or length($ranges) == 4) {
        @warn "`range-map()` requires three or five parameters: initial number, (old minimum), old maximum, (new minimum), and new maximum.";
        @return false;
    }

    $old-minimum: if(length($ranges) == 2, 0, nth($ranges, 1));
    $old-maximum: if(length($ranges) == 2, nth($ranges, 1), nth($ranges, 2));
    $new-minimum: if(length($ranges) == 2, 0, nth($ranges, 3));
    $new-maximum: if(length($ranges) == 2, nth($ranges, 2), nth($ranges, 4));

    // @if $old-minimum >= $old-maximum {
    //     @warn "old maximum must be greater than old minimum";
    //     @return false;
    // }
    @if $number < $old-minimum {
        @warn "initial number must be greater than old minimum";
        @return false;
    }
    @if $number > $old-maximum {
        @warn "initial number must be less than old maximum";
        @return false;
    }
    // @if $new-minimum >= $new-maximum {
    //     @warn "new maximum must be greater than new minimum";
    //     @return false;
    // }

    @return ($number - $old-minimum) / ($old-maximum - $old-minimum) * ($new-maximum - $new-minimum) + $new-minimum;
}


$light: snow;
$dark: black;

$light--visual: lightcoral;
$dark--visual: midnightblue;

:root {
  --phase: 0;
  
  --light: #{$light};
  --dark: #{$dark};
  
  --below: 2;
  --above: 3;
}

html {
  box-sizing: border-box;
}

*, *::before, *::after {
  box-sizing: inherit;
}

body {
  background-color: var(--dark);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background-color: gray;
  color: white;
  padding: 1rem;
  display: flex;
  align-items: center;
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  
  button,
  label {
    background-color: white;
    color: black;
    border: 0;
    padding: 0.25em;
    font-size: 1rem;
  }
  
  button {
    margin-right: 2rem;
    font-size: 1.125rem;
    
    &::before {
      content: attr(data-text);
    }
  }
  
  label {
    margin-left: 2rem;
  }
}


.moon {
  background-color: var(--dark);
  width:  65vmin;
  height: 65vmin;
  position: relative;
  overflow: hidden;
  
  &,
  &::before,
  &::after {
    background-clip: padding-box;
    border-radius: 50%;
  }
  
  &::before,
  &::after {
    content: "";
    // opacity: 0.65;
    width:  100%;
    height: 100%;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: center;
  }
  
  &::before {
    background-color: var(--light);
    // background-color: darken($light, 10%);
    clip-path:
      polygon(
        0% 0%,
        50% 0%,
        50% 100%,
        0% 100%
      );
  }
  
  &::after {
    background-color: var(--dark);
    // background-color: lighten($dark, 10%);
    clip-path:
      polygon(
        50% 0%,
        100% 0%,
        100% 100%,
        50% 100%
      );
  }
  
  &.moon--to-fq { // 0–24
    &::before {
      transform: rotateY(180deg);
      z-index: var(--below);
    }
    
    &::after {
      z-index: var(--above);
    }
    
    @for $i from 0 through 24 {
      $rotation: range-map($i, 0, 24, 0, 90);
      
      &[data-value="#{$i}"]::after {
        transform: scale(1.01) translateX(-1px) rotateY($rotation + deg);
      }
    }
  }
  
  &.moon--to-fm { // 25-49
    @for $i from 25 through 49 {
      $rotation: range-map($i, 25, 49, 90, 0);
      
      &[data-value="#{$i}"]::before {
        transform: scale(1.01) translateX(1px) rotateY($rotation + deg);
      }
    }
    
    &::after {
      background-color: var(--light);
    }
  }
  
  &.moon--to-tq { // 50-74    
    @for $i from 50 through 74 {
      $rotation: range-map($i, 50, 74, 180, 90);
      
      &[data-value="#{$i}"]::before {
        transform: scale(1.01) translate(-1px) rotateY($rotation + deg);
      }
    }
    
    &::after {
      background-color: var(--light);
      transform: rotateY(180deg);
      z-index: var(--below);
    }
  }
  
  &.moon--to-nm { // 75-99    
    &::before {
      z-index: var(--below);
    }
    
    &::after {
      z-index: var(--above);
    }
    
    @for $i from 75 through 99 {
      $rotation: range-map($i, 75, 99, 90, 180);
      
      &[data-value="#{$i}"]::after {
        transform: scale(1.01) translate(1px) rotateY($rotation + deg);
      }
    }
  }
}

input {
  font-size: 1.125rem;
}

#visualiser:checked + .moon {
  background-color: darken($dark--visual, 10%);
  
  --light: #{$light--visual};
  --dark: #{$dark--visual};
}

            
          
!

JS

            
              let input = document.querySelector("input");
let button = document.querySelector("button");
let moon = document.querySelector(".moon");

let phase = value => {
  input.value = value;
  moon.dataset.value = value;
  
  console.log(value);
  
  moon.className = "moon";
  if (value < 25) {
    moon.classList.add("moon--to-fq");
  }
  else if (value < 50) {
    moon.classList.add("moon--to-fm");
  }
  else if (value < 75) {
    moon.classList.add("moon--to-tq");
  }
  else { // goes to 99
    moon.classList.add("moon--to-nm");
  }
};

phase(input.value);

button.addEventListener("click", event => {
  toggleAnimation();
});

let interval;

let toggleAnimation = () => {  
  if (button.dataset.text === "Play") {
    button.dataset.text = "Stop";
    
    interval = window.setInterval(incrementPhase, 16);
  }
  else {
    button.dataset.text = "Play";
    
    clearInterval(interval);
  }
};

let incrementPhase = () => {
  let newValue = (moon.dataset.value < 99 ? ++moon.dataset.value : 0);
  phase(newValue);
};

            
          
!
999px

Console