css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              canvas.stage
.menu
  label.scale 
    .name Scale
    input(type="range", min=-1, max=1, step=0.00001)
    input.readout(type="text", value="0.00")
    
  label.a 
    .name A
    input(type="range", min=-3142, max=3142, step=0.0001)
    input.readout(type="text", value="0.00")
   
  label.b
    .name B
    input(type="range", min=-3142, max=3142, step=0.0001)
    input.readout(type="text", value="0.00")
    
  label.c
    .name C
    input(type="range", min=-3142, max=3142, step=0.0001)
    input.readout(type="text", value="0.00")
    
  label.d
    .name D
    input(type="range", min=-3142, max=3142, step=0.0001)
    input.readout(type="text", value="0.00")
    
    
  label.e
    .name E
    input(type="range", min=-3142, max=3142, step=0.0001)
    input.readout(type="text", value="0.00")
    
    
  label.f
    .name F
    input(type="range", min=-3142, max=3142, step=0.0001)
    input.readout(type="text", value="0.00")
  
  .buttons
    button.randomize Randomize
    button.save Save
    br
    button.play Play
    button.stop Stop
            
          
!
            
              html
  font-size: 1px
  color: #888

canvas.stage
  background: #000
  position: absolute
  top: 0
  left: 0
  width: 100vw
  height: 100vh
  
.menu
  font-family: monospace
  font-size: 0px
  position: absolute
  z-index: 1
  top: 0
  left: 0
  width: 300rem
  padding: 10rem
  background: rgba(0,0,0,0.2)
  .buttons
    margin-top: 10rem
    text-align: center
  label
    display: block
    vertical-align: middle
    position: relative
    &.scale
      height: 50rem
      .name
        vertical-align: top
      input[type=range], input
        position: absolute
        bottom: 0
    .name
      display: inline-block
      font-size: 16rem
      width: 10%
      margin: 0
      vertical-align: middle
    input[type=range]
      display: inline-block
      width: 65%
      margin: 10rem 0
      vertical-align: middle
    .readout  
      font-family: monospace
      color: #888
      font-size: 12rem
      background: transparent
      border: none
      display: inline-block
      width: 25%
      margin: 10rem 0
      padding: 0
      text-align: right 
      right: 0
      vertical-align: middle
            
          
!
            
              //inigo kiles


// Polyfills
NodeList.prototype.forEach = NodeList.prototype.forEach || function(fn) {
  return Array.prototype.forEach.call(this, fn);
}

function $(selector) {
  return document.querySelectorAll(selector);
}

// VARS
var numParticles = 60000;
var valueScale = 0.5;
var animationRates = [
  0, -10.0001, -10.0001,
  10.0001,
  10.0001,
  10.0001, -10.0001
];

// Setup Stage
var pixelRatio = window.devicePixelRatio;
var WIDTH = window.innerWidth * pixelRatio;
var HEIGHT = window.innerHeight * pixelRatio;
var HALF_WIDTH = WIDTH >> 1;
var HALF_HEIGHT = HEIGHT >> 1;

var stageCanvas = $("canvas.stage")[0];
var ctx = stageCanvas.getContext("2d");
var stageImgData = ctx.createImageData(WIDTH, HEIGHT);
ctx.globalCompositeOperation = "screen";

// Setup Menu
var sliders = $('input[type=range]');
sliders.forEach(function(s) {
  s.addEventListener('input', onSliderInput);
})

function onSliderInput(e) {
  updateText(e.target);
  drawAll(numParticles, getVals());
}

var textFields = $('input[type=text]');

textFields.forEach(function(f) {
  f.addEventListener('change', onChangeText);
})

function onChangeText(e) {
  updateSlider(e.target);
  drawAll(numParticles, getVals());
}

$('button.randomize')[0].addEventListener('click', function() {
  randomize();
  drawAll(numParticles, getVals());
});
$('button.save')[0].addEventListener('click', save);
$('button.play')[0].addEventListener('click', play);
$('button.stop')[0].addEventListener('click', stop);

// Menu IO
function save(e) {
  var a = document.createElement('a');
  a.download = "CompositeWaveFractal-" + Date.now();
  a.href = stageCanvas.toDataURL('image/png');

  var e2 = document.createEvent("HTMLEvents");
  e2.initEvent('click', true, true);
  return !a.dispatchEvent(e2);
}

function randomize() {
  sliders.forEach(function(s,i) {
    // i=0 is the scale slider
    s.value = i ? ((Math.random() * 4) - 2) * 1000 : ((Math.random() * 2) - 1);
    updateText(s);
  });
}

var vals = [];

function getVals() {
  vals = Array.prototype.map.call(sliders, function(s) {
    return s.value / 30;
  })

  valueScale = vals.shift();
  vals = vals.map(function(v) {
    return v * valueScale;
  })
  return vals;
}

function updateText(slider) {
  slider.parentNode.querySelector('.readout').value = slider.value;

}

function updateSlider(textField) {
  textField.parentNode.querySelector('input[type=range]').value = parseFloat(textField.value);

}

// DRAW!!
var newImageData;

function drawAll(n, vals) {
  newImageData = ctx.createImageData(WIDTH, HEIGHT);
  var xs = 0,
    ys = 0,
    zs = 0;

  for (var i = n; i >= 0; i--) {
    var res = drawPoint(xs, ys, zs, vals)
    xs = res[0];
    ys = res[1];
    zs = res[2];
  }
  ctx.putImageData(newImageData, 0, 0);
}

function drawPoint(xs, ys, zs, vals) {
  var new_x = Math.sin(vals[0] * xs) + Math.sin(vals[1] * ys) - Math.cos(vals[2] * zs);
  var new_y = Math.sin(vals[3] * xs) + Math.sin(vals[4] * ys) - Math.cos(vals[5] * zs);
  xs = new_x;
  ys = new_y;
  zs = zs + 0.1;

  addPixel(
    newImageData,
    ((xs * WIDTH) >> 3) + HALF_WIDTH,
    ((ys * HEIGHT) >> 3) + HALF_HEIGHT,
    64, 255, 210, 0.4
  );

  return [xs, ys, zs]
}

document.addEventListener("DOMContentLoaded", ready);
window.addEventListener('resize', onResize);

function ready() {
  randomize();
  onResize();
}

function onResize() {
  pixelRatio = window.devicePixelRatio;
  WIDTH = window.innerWidth * pixelRatio;
  HEIGHT = window.innerHeight * pixelRatio;
  HALF_WIDTH = WIDTH >> 1;
  HALF_HEIGHT = HEIGHT >> 1;

  stageCanvas.width = WIDTH;
  stageCanvas.height = HEIGHT;
  stageImgData = ctx.createImageData(WIDTH, HEIGHT);

  drawAll(numParticles, getVals());
}

function addPixel(imageData, x, y, r, g, b, a) {
  var d = imageData.data;
  var i = (x << 2) + (y * imageData.width << 2);
  d[i] += r * a;
  d[i + 1] += g * a;
  d[i + 2] += b * a;
  d[i + 3] += 255 * a;
}

var rAF;

function play() {
  if (rAF) return;
  loop();
}

function stop() {
  cancelAnimationFrame(rAF);
  rAF = null;
}

function loop() {
  rAF = requestAnimationFrame(loop);
  sliders.forEach(function(s, i) {
    s.value = parseFloat(s.value) + animationRates[i];
    if (s.value >= parseFloat(s.max) || s.value <= parseFloat(s.min)) {
      animationRates[i] *= -1
    }
    updateText(s);
  })

  drawAll(numParticles, getVals());
}
            
          
!
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