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

Auto Save

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

              
                <head>
  <script src='https://kit.fontawesome.com/a076d05399.js'></script>
  <style>
    * {
      user-select: none;
    }

    body {
      background: #333;
      color: snow;
      width: 100vw;
      height: 100vh;
      margin: 0;
      font-family: avenir, arial, monospace;
      text-align: center;
    }

    #main {
      background: #5e4f40;
      align-content: center;
      border-radius: 1em;
    }

    #sound-icon {
      color: #335;
      font-size: 10em;
      position: fixed;
      left: calc(50% - 0.5em);
      top: calc(50% - 0.4em);
    }

    footer {
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
      padding-bottom: 1em;
    }

    a {
      color: snow;
    }

    a:hover {
      color: lime;
    }
  </style>
</head>

<body id="2d-area">
  <!-- or: <body onload="_2DNote.setAs2DArea(this);"> -->
  <div id="main" role="main">
    <h1 id="audio-reminder" aria-hidden="true">Make sure audio is on</h1>
    <p id="instruction" aria-live="polite"></p>
  </div>
  <i id="sound-icon" class='fas fa-music'></i>
  <footer><a href="https://codepen.io/hchiam/full/eYYdVeX" 
             target="_blank"
             onclick="stopNotes();event.stopPropagation();">View full-screen</a>
    <p class="small-text">Potential use: 2D games that people can play together, regardless of vision capabilities? <a href="https://github.com/hchiam/note-generator" target="_blank">More info on GitHub.</a></p>
  </footer>

  <!-- INCLUDE _2DNote! -->
  <script src="https://cdn.jsdelivr.net/gh/hchiam/_2DNote@1.13.0/_2DNote.js"></script>

  <!-- USE _2DNote! -->
  <script>
    _2DNote.setAs2DArea(document.getElementById('2d-area'), colourSoundIcon);

    setTimeout(function() {
      document.getElementById('instruction').innerHTML = '<span style="color: lime;">Click</span> and <span style="color: lime;">drag</span> anywhere inside this screen.';
    }, 1000);

    // UI instruction display:
    document.body.addEventListener('mousedown', playAndInstruct);
    document.body.addEventListener('mouseup', stopAndInstruct);
    document.body.addEventListener('mousemove', updateAndInstruct);
    document.body.addEventListener('mouseleave', exitedView);
    document.body.addEventListener('touchstart', playAndInstruct);
    document.body.addEventListener('touchend', stopAndInstruct);
    document.body.addEventListener('touchmove', updateAndInstruct);
    document.body.addEventListener('touchcancel', exitedView);

    let on = false;

    function playAndInstruct(e) {
      on = true;
      hideAudioReminder();
      instructToMoveMouse();
      toggleSoundIcon();
      // _2DNote.play(e);
    }

    function stopAndInstruct() {
      on = false;
      // _2DNote.stop();
      instructToClickToStart();
      toggleSoundIcon();
    }

    function updateAndInstruct(e) {
      // _2DNote.update(e, colourSoundIcon);
      instructToClickToStop();
    }

    function exitedView() {
      on = false;
      // _2DNote.stop();
      instructToClickToStart();
    }

    function instructToMoveMouse() {
      document.getElementById('instruction').innerHTML = '<span style="color: lime;">↕</span> = volume, <span style="color: lime;">↔️</span> = pitch';
    }

    function hideAudioReminder() {
      document.getElementById('audio-reminder').style.display = 'none';
    }

    function instructToClickToStart() {
      document.getElementById('instruction').innerHTML = '<span style="color: lime;">Click</span> screen and <span style="color: lime;">drag</span>';
    }

    function instructToClickToStop() {
      if (on) {
        document.getElementById('instruction').innerHTML = '<span style="color: lime;">↕</span> = volume, <span style="color: lime;">↔️</span> = pitch <br/><span style="color: lime;">Let go to stop</span>';
      }
    }

    function toggleSoundIcon() {
      if (on) {
        document.getElementById('sound-icon').style.visibility = 'visible';
      } else {
        document.getElementById('sound-icon').style.visibility = 'hidden';
      }
    }

    function colourSoundIcon(volume, frequency) {
      const comfyFrequencyRange = [150, 400];
      const hueRange = [0, 359];
      let hue = _2DNote.normalize(frequency, comfyFrequencyRange, hueRange);
      hue = Math.round(hue);
      const comfyVolumeRange = [0, 0.5];
      const saturationRange = [0, 100];
      let saturation = _2DNote.normalize(volume, comfyVolumeRange, saturationRange);
      saturation = Math.round(saturation);
      const hsl = 'hsl(' + String(hue) + ',' + String(saturation) + '%, 50%)';
      document.getElementById('sound-icon').style.color = hsl;
    }
  </script>
</body>

              
            
!

CSS

              
                
              
            
!

JS

              
                setTimeout(function(){
  _showRedirectLinkAsNeeded('eYYdVeX');
}, 100);

              
            
!
999px

Console