cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <!--The prettiest HTML you ever did see-->
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">
<audio id="audio" autoplay loop>
  <source src="https://picturelements.github.io/images/nggyu.mp3" type="audio/mpeg"></source>
  Fuck, you can't play audio.
</audio>
<div class="circle" id="sun"></div>
<div class="circle" id="moon"></div>
<div id="perc">10%</div>
            
          
!
            
              body {
  margin: 0;
  height: 100vh;
  background: hsl(194, 66%, 49%);
  overflow: hidden;
  font-family: Inconsolata,sans-serif;
  font-size: 20px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.circle {
  position: absolute;
  width: 150px;
  height: 150px;
  margin: -75px;
  background: red;
  top: 50%;
  left: 50%;
  border-radius: 50%;
}

#sun {
  background: #ffff77;
  box-shadow: 0 0 50px #ffff77;
}

#moon {
  background: #222;
  left: 50%;
}

#perc {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 50%;
  margin-top: 110px;
  color: white;
  pointer-events: none;
}
            
          
!
            
              //Another contribution to the great Eclipse/Volume circlejerk

var moon=document.getElementById("moon"),
    parc=document.getElementById("perc"),
    audio=document.getElementById("audio"),
    dragging=false,
    radius=75,
    area=Math.PI*radius*radius,
    offs=[0,0];

function init(){
  moon.addEventListener("mousedown",selectMoon);
  moon.addEventListener("touchstart",selectMoon);
  document.body.addEventListener("mousemove",moveMoon);
  document.body.addEventListener("touchmove",moveMoon);
  document.body.addEventListener("mouseup",dropMoon);
  document.body.addEventListener("touchend",dropMoon);
  setMoonData(window.innerWidth/2+radius*2.5,window.innerHeight/2);
  audio.play();
}

function selectMoon(evt){
  dragging=true;
  var coords=getCoords(evt),
      bcr=moon.getBoundingClientRect();
  offs=[coords[0]-bcr.left-radius,coords[1]-bcr.top-radius];
}

function moveMoon(evt){
  if (!dragging)
    return;
  var coords=getCoords(evt);
  setMoonData(coords[0]-offs[0],coords[1]-offs[1]);
}

function setMoonData(x,y){
  moon.style.left=x/window.innerWidth*100+"%";
  moon.style.top=y/window.innerHeight*100+"%";
  
  var offset=Math.hypot(x-window.innerWidth/2,y-window.innerHeight/2),
      sector=Math.acos((offset/2)/radius)/Math.PI,
      triangle=Math.sqrt(radius*radius-offset*offset/4)*(offset/2),
      overlap=(area*sector-triangle)*2/area || 0,
      opacity=Math.max(400-offset,0)/1000,
      expOverlap=Math.pow(overlap,4);
  
  //Bling bling
  moon.style.boxShadow="inset "+(x-window.innerWidth/2)/10+"px "+(y-window.innerHeight/2)/10+"px 50px rgba(255, 255, 119, "+opacity+")";
  moon.style.background="hsl(194, 56%, "+(1-expOverlap)*60+"%)";
  perc.innerHTML="Volume: "+(overlap*100).toPrecision(4)+"%";
  document.body.style.background="hsl("+(194+Math.floor(166*expOverlap))+", 66%, "+(1-expOverlap)*50+"%)";
  
  //Oh yeah, set the volume, I guess.
  audio.volume=overlap;
}

function dropMoon(){
  dragging=false;
}

function getCoords(evt){
  return [(evt.touches || [evt])[0].clientX,(evt.touches || [evt])[0].clientY];
}

Math.hypot=function(a,b){
  return Math.sqrt(a*a+b*b);
};

init();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console