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

              
                <!-- Please like <3 and share if you enjoyed! -->

<div class="container">
  <div class="float-container">
    <div class="float-icon">
      ❔❔❔
    </div>
    
  </div>
  <div class="info-container">
    <div class="generate-button">
      <button id="generate-button" onclick="createAndPlay()"> Discover secret</button></div>
    <div class="instructions">Click the button above to generate a random 'secret discovered' melody <br/> (think Zelda puzzle complete)
    </div></div>
</div>
              
            
!

CSS

              
                // Please like <3 and share if you enjoyed!

html, body{
  height:100%;
  width:100%;
  padding:0;
  margin:0;
background-image: linear-gradient(45deg, #4a4949 35.71%, #7cafcf 35.71%, #7cafcf 50%, #4a4949 50%, #4a4949 85.71%, #7cafcf 85.71%, #7cafcf 100%);
background-size: 98.99px 98.99px;
}

.container{
  display:flex;
  justify-content:center;
  align-items:center;
  align-content:center;
   flex-direction:column;
  height:100%;
  
  .float-container{
    height:40%;
    .float-icon{
      z-index:-5;
      font-size:2rem;
      opacity:0;
      transition: all 700ms;
       padding-top: 100%;
      pointer-events:none;
    
      &.active{
        opacity:1;
        padding-top:0;
         font-size:3rem;
        transition: all 0;
      }
    }
  }
  
  .info-container
  {
    flex-direction:column;
    display:flex;
  justify-content:center;
  align-items:center;
  align-content:center;
    background-color:#292828;
    padding:20px;
    .generate-button button {
      font-family: 'Lilita One', cursive;
      font-size:3rem;
      background-color:#7cafcf;
      border:none;
      padding:10px;
      cursor:pointer;
      transition: opacity 1s linear;
      transition: padding 0.5s ease-in-out;
      color:#191818;
      &:hover {
        background-color:darken(#7cafcf,5%);
      }
        &:active {
        background-color:darken(#7cafcf,10%);
          padding:20px;
      }
      &:disabled {
        opacity:0.5;
      }
    }
    .instructions{
      margin-top:1rem;
      text-align:center;
      max-width:800px;
      color:white;
      font-family: 'Roboto Mono', monospace;
      font-size:1rem;
      letter-spacing:1px;
    }
  }
}
              
            
!

JS

              
                // Please like <3 and share if you enjoyed!
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();

let masterVolume = audioCtx.createGain();
masterVolume.gain.setValueAtTime(0.05, audioCtx.currentTime);
masterVolume.connect(audioCtx.destination);

let waveTypes = ["sine","sawtooth", "square", "sawtooth", "triangle"];
let notes = [
  { freq: 1000, dur: 0.5 },
  { freq: 3000, dur: 1 },
  { freq: 2500, dur: 0.7 }
];

let icon = document.querySelector(".float-icon");
let hideIconTime = null;
let totalDuration = 0;

let generateButton = document.getElementById("generate-button");

let emojis = [
  "❔",
  "❓",
  "🧐",
  "⚗️",
  "🗝️",
  "👽",
  "🤔",
  "🤖",
  "👾",
  "💭",
  "📜",
  "🤫"
];

function playNote(freq, dur, type) {
  if (!freq) freq = 1000;
  if (!dur) dur = 1;
  if (!type) type = "square";
  return new Promise(res => {
    let oscillator = audioCtx.createOscillator();
    oscillator.type = type;
    oscillator.frequency.setValueAtTime(freq, audioCtx.currentTime); // value in hertz
    oscillator.connect(masterVolume);
    oscillator.start();
    oscillator.stop(audioCtx.currentTime + dur);
    oscillator.onended = res;
  });
}

function createNote(freq, dur, type) {
  return { freq, dur, type };
}

function createAndPlay() {
  generateJingle();
  playJingle();
  showIcon();
}

function getNextFreq(freq, lastNote) {
  let modifier = lastNote ? 0 : -300;
  freq += modifier + Math.random() * 1000;
  return freq;
}

function getDur(baseDir, lastNote) {
  if (lastNote) return baseDir + Math.random() / 5;
  return baseDir - 0.1 + Math.random() / 10;
}

//@todo add type
function generateJingle() {
  notes = [];
  totalDuration = 0;
  let amount = 3 + Math.floor(Math.random() * 8);
  let currentFreq = 100 + Math.random() * 2000;
  let baseDur = 0.1 + Math.random() / 4;
  let type = waveTypes[Math.floor(Math.random() * waveTypes.length)];
  for (let i = 0; i <= amount; i++) {
    let dur = getDur(baseDur, i == amount);
    currentFreq = getNextFreq(currentFreq, i == amount);
    notes.push(createNote(currentFreq, dur, type));
    totalDuration += dur;
  }
}

function playJingle(noteIndex) {
  if (!noteIndex) noteIndex = 0;
  if (noteIndex < notes.length) {
    let note = notes[noteIndex];
    playNote(note.freq, note.dur, note.type).then(() => {
      playJingle(noteIndex + 1);
    });
  }
}
function getEmoji() {
  return emojis[Math.floor(Math.random() * emojis.length)];
}

function showIcon() {
  generateButton.disabled = true;
  icon.classList.add("active");
  icon.innerHTML = `${getEmoji()}-${getEmoji()}-${getEmoji()}`;
  setTimeout(hideIcon, totalDuration * 1000);
}

function hideIcon() {
  icon.classList.remove("active");
  if (hideIconTime) clearTimeout(hideIconTime);
  generateButton.disabled = false;
}

              
            
!
999px

Console