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 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

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.

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

              
                <div class="sliders">
  <div class="slider-wrapper">
    <label class="slider-label">Min px from edge</label>
    <input type="range" data-config-name="min_distance" id="minDistance" class="slider" min="1" max="50" value="7">
    <div class="slider-value">7</div>
  </div>
  <div class="slider-wrapper">
    <label class="slider-label">Max px from edge</label>
    <input type="range" data-config-name="max_distance" id="maxDistance" class="slider" min="1" max="50" value="22">
    <div class="slider-value">22</div>
  </div>
  <div class="slider-wrapper">
    <label class="slider-label">Number Of Lines</label>
    <input type="range" data-config-name="number_of_lines" id="numberOfLines" class="slider" min="25" max="400" value="100">
    <div class="slider-value">100</div>
  </div>
  <div class="slider-wrapper">
    <label class="slider-label">Line Height</label>
    <input type="range"  data-config-name="line_height" id="lineHeight" class="slider" min="20" max="200" value="50">
    <div class="slider-value">50</div>
  </div>
  <div class="slider-wrapper">
    <label class="slider-label">Line Spacing</label>
    <input type="range" data-config-name="line_spacing"  id="lineSpacing" class="slider" min="2" max="10" value="4">
    <div class="slider-value">4</div>
  </div>
  <div class="slider-wrapper">
    <label class="slider-label">Line Width</label>
    <input type="range"  data-config-name="line_width" id="lineWidth" class="slider" min="1" max="10" value="2">
    <div class="slider-value">2</div>
  </div>
  <div class="slider-wrapper">
    <label class="slider-label">Line Color</label>
    <input type="color" id="lineColor" class="slider" value="#000000">
  </div>
</div>

<button onClick="randomSVG()">generate new waveform</button>

<svg id="svg" xmlns="http://www.w3.org/2000/svg"></svg>

              
            
!

CSS

              
                svg{
  width: 100%;
  display: block;
}

button{
  margin: 20px 20px 40px;
  background: #c0c0c0;
  border: 0;
  padding: 10px 20px;
  text-transform: uppercase;
}

.slider-label{
  width: 150px;
  display: inline-block;
  text-align: right;
  padding-right: 10px;
}

.sliders{
  width: 400px;
  margin-top: 40px;
}

.slider-wrapper{
  display: block;
  width: 400px;
  margin-bottom: 10px;
}

.slider{
  display: inline;
  transform: translateY(7px);
}

.slider-value{
  display: inline;
}
              
            
!

JS

              
                window.onload = function() {
  init();
  randomSVG();
};

var config = {
  items: [],
  min_distance: 7,
  max_distance: 22,
  number_of_lines: 100,
  line_height: 50,
  line_spacing: 4,
  line_with: 2,
  line_color: '#000000'
};


function init(){
  let sliders = document.querySelectorAll('input');
  for(var slider of sliders){
    slider.addEventListener('input', function(event) {
      if(event.target.type == "color"){
        config.line_color = event.target.value;
      }
      else{
        let config_name =  event.target.dataset.configName;
        config[config_name] = event.target.value;
        event.target.nextElementSibling.innerHTML = event.target.value.toString();
      }
      
      randomSVG();
    });
  }
  
}


function randomSVG(){
  config.items = Array(config.max_distance - config.min_distance + 1).fill().map((_, idx) => 7 + idx);
  
  document.getElementById('svg').innerHTML = '';
  
  var svgns = "http://www.w3.org/2000/svg";
  for (var i = 1; i < config.number_of_lines; i++) {
      var y1 = config.items[Math.floor(Math.random() * config.items.length)];
      var y2 = config.line_height - y1;
      var line = document.createElementNS(svgns, 'line');
      var x = i * config.line_spacing;

      line.setAttributeNS(null, 'x1', x);
      line.setAttributeNS(null, 'y1', y1);
      line.setAttributeNS(null, 'x2', x);
      line.setAttributeNS(null, 'y2', y2);
      line.setAttributeNS(null, 'stroke-width', config.line_width);
      line.setAttributeNS(null, 'stroke', config.line_color);    

      document.getElementById('svg').appendChild(line);
  }

}
              
            
!
999px

Console