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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <!-- Inspired by @softlandscapes on twitter 🏞-->

<!-- html & body full screen -->
<html style="width:100%;height:100%;">
  <body style="width:100%;height:100%;margin:0;">

    <!-- svg full screen, coordinate system 0-100, don't preserve aspect ratio -->
    <svg id="landscape" height="100%" width="100%" viewBox="33 0 33 100" preserveAspectRatio="none">

        <polygon id="mountain-1" points="0,100 100,100"
          style="fill-rule:evenodd;"  /> 

        <polygon id="mountain-2" points="0,100 100,100"
          style="fill-rule:evenodd;"  /> 

        <polygon id="mountain-3" points="0,100 100,100"
          style="fill-rule:evenodd;"/> 


        <polygon id="mountain-4" points="0,100 100,100"
          style="fill-rule:evenodd;"  /> 



    
    </svg>
  </body>
</html>
            
          
!
            
              
function randomInRange(min, max) {
  return Math.floor(Math.random() * (max - min) + min);
}
function floatInRange(min, max) {
  return Math.random() * (max - min) + min;
}


function randomPeaks(min, max) {
  var numPeaks = randomInRange(7, 16);
  // numPeaks = 3; 
  var interval = (100 / (numPeaks));
  return _.times(numPeaks, (i) => {
    return {
      x: interval * i + interval / 2,
      y: 100 - randomInRange(min, max),
    }
  });
}

function updateMountainRange(svg, polygon, peaks) {
  polygon.points.clear();
  var point;
  point = polygon.points.appendItem(svg.createSVGPoint());
  point.x = 0;
  point.y = 100;
  for (var i=0; i<peaks.length; i++) {
    point = polygon.points.appendItem(svg.createSVGPoint());
    point.x = peaks[i].x;
    point.y = peaks[i].y;
  }
  point = polygon.points.appendItem(svg.createSVGPoint());
  point.x = 100;
  point.y = 100;
}

function slidePeaks(rate, min, max, peaks) {
  let newPeaks = _.map(peaks, (peak) => {
    return {
      x: peak.x + rate, 
      y: peak.y
    }
  });
  let last = peaks.length - 1;
  if (newPeaks[last].x >= 100) {
    newPeaks[last].x = 0;
    newPeaks[last].y = 100 - randomInRange(min, max);
    newPeaks = _.sortBy(newPeaks, 'x');
  }
  return newPeaks;
}

function initialiseRange(rate, min, max) {
  var range = {
    rate: rate,
    min: min,
    max: max
  };
  range.peaks = randomPeaks(min, max);
  return range;
}

var data = {
  kick: initialiseRange(0.01, 1, 95),
  bass: initialiseRange(0.02, 1, 80),
  drums: initialiseRange(0.04, 1, 60),
  lead: initialiseRange(0.2, 1, 50),
}

var polygons = {
  kick: document.getElementById("mountain-1"),
  bass: document.getElementById("mountain-2"),
  drums: document.getElementById("mountain-3"),
  lead: document.getElementById("mountain-4"),
}

function updateInstrument(svg, polygon, data) {
  data.peaks = slidePeaks(
    data.rate, data.min, data.max, 
    data.peaks
  );
  updateMountainRange(svg, polygon, data.peaks);
} 

var hue1 = floatInRange(0, 1);
var hue2 = floatInRange(0, 1);
var sat = 0.9;
var bright = 0.9;
    
function interpColour(h1, h2, amount) {
  var tnuoma = 1.0 - amount;
  var interpolated = {
    h: h1 * amount + h2 * tnuoma,
    s: sat,
    v: bright
  };
  var colour = tinycolor.fromRatio(interpolated).toRgb();
  return `rgba(${colour.r}, ${colour.g}, ${colour.b}, ${amount*0.20+0.70})`;
};

var svg = document.getElementById("landscape");

polygons.kick.style.fill = interpColour(hue1, hue2, 0);
polygons.bass.style.fill = interpColour(hue1, hue2, 0.25);
polygons.drums.style.fill = interpColour(hue1, hue2, 0.75);
polygons.lead.style.fill = interpColour(hue1, hue2, 1);

function update() {
  updateInstrument(svg, polygons.kick, data.kick);
  updateInstrument(svg, polygons.bass, data.bass);
  updateInstrument(svg, polygons.drums, data.drums);
  updateInstrument(svg, polygons.lead, data.lead);
}
update();
setInterval(update, 25);

            
          
!
999px
Loading ..................

Console