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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!-- customized version of https://codepen.io/zadvorsky/pen/VaXqRW -->

<div class="container" id="container"></div>

<script type="x-shader/x-vertex" id="vertexShader">
      uniform float amplitude;

      attribute vec3 vertexColor;

      varying vec4 varColor;

      void main()
      {
      varColor = vec4(vertexColor, 1.0);

      vec4 pos = vec4(position, 1.0);
      pos.z *= amplitude;

      vec4 mvPosition = modelViewMatrix * pos;

      gl_PointSize = 1.0;
      gl_Position = projectionMatrix * mvPosition;
      }
    </script>

    <script type="x-shader/x-fragment" id="fragmentShader">
      varying vec4 varColor;

      void main()
      {
      gl_FragColor = varColor;
      }
    </script>
              
            
!

CSS

              
                body {
  overflow: hidden;
  margin: 0;
  height: 100vh
}

.container {
  display:block;
}
              
            
!

JS

              
                    var container;
    let camera, scene, renderer;
    var controls;

    var shaderUniforms, shaderAttributes;

    var particles = [];
    var particleSystem;

    var imageWidth;
    var imageHeight;
    var imageData = null;

    var imageIndex = 0;

    var animationTime = 0;
    var animationDelta = 0.01;

    init();
    function init() {
      createScene();
      createControls();
      createPixelData();


      window.addEventListener('resize', onWindowResize, false);
    }

    function createScene() {

      container = document.getElementById('container');

      scene = new THREE.Scene();

      camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);

      camera.position.z = 1000;
      camera.lookAt(scene.position)


      renderer = new THREE.WebGLRenderer({
        antialias: true
      });
      renderer.setSize(window.innerWidth, window.innerHeight);
      renderer.setClearColor(0x111111, 1);

      container.appendChild(renderer.domElement);
    }

    function createControls() {
      controls = new THREE.TrackballControls(camera);

      controls.rotateSpeed = 1.0;

      controls.noZoom = true;
      controls.noPan = true;

      controls.staticMoving = true;
      controls.dynamicDampingFactor = 0.3;
    }

    function createPixelData() {
      var image = document.createElement("img");
      var imgArray = new Array();

      imgArray[0] = new Image();
      imgArray[0].src = 'https://i.vimeocdn.com/video/703876203_640.jpg';

      imgArray[1] = new Image();
      imgArray[1].src = 'https://opidesign.net/wp-content/uploads/landscape-architecture-fun-facts-outside-productions-blog-980x551.jpg';

      imgArray[2] = new Image();
      imgArray[2].src = 'https://cdn.davemorrowphotography.com/wp-content/uploads/2018/01/the-Landscape-Photography-Journals.jpg';



      var canvas = document.createElement("canvas");
      var context = canvas.getContext("2d");



      image.crossOrigin = "Anonymous";
      image.onload = function() {
        image.width = canvas.width = image.naturalWidth;
        image.height = canvas.height = image.naturalHeight;
        console.log(image.naturalWidth,image.naturalHeight)

        context.fillStyle = context.createPattern(image, 'no-repeat');
        context.fillRect(0, 0, image.naturalWidth, image.naturalHeight);
        //context.drawImage(image, 0, 0, imageWidth, imageHeight);

        imageData = context.getImageData(0, 0, image.naturalWidth, image.naturalHeight).data;
        imageWidth = image.naturalWidth;
        imageHeight = image.naturalHeight;
        createParticles();
        tick();
      };

      image.src = imgArray[imageIndex].src;
    }

    function createParticles() {
      var colors = [];
      var weights = [0.2126, 0.7152, 0.0722];
      var c = 0;

      var geometry, material;
      var x, y;
      var zRange = 300;

      geometry = new THREE.Geometry();
      geometry.dynamic = false;

      x = imageWidth * -0.5;
      y = imageHeight * 0.5;

      shaderAttributes = {
        vertexColor: {
          type: "c",
          value: []
        }
      };

      shaderUniforms = {
        amplitude: {
          type: "f",
        }
      };

      var shaderMaterial = new THREE.ShaderMaterial({
        attributes: shaderAttributes,
        uniforms: shaderUniforms,
        vertexShader: document.getElementById("vertexShader").textContent,
        fragmentShader: document.getElementById("fragmentShader").textContent
      })

      for (var i = 0; i < imageHeight; i++) {
        for (var j = 0; j < imageWidth; j++) {
          var color = new THREE.Color();

          color.setRGB(imageData[c] / 255, imageData[c + 1] / 255, imageData[c + 2] / 255);
          shaderAttributes.vertexColor.value.push(color);

          var weight = color.r * weights[0] +
            color.g * weights[1] +
            color.b * weights[2];

          var vertex = new THREE.Vector3();

          vertex.x = x;
          vertex.y = y;
          vertex.z = (zRange * -0.5) + (zRange * weight);

          geometry.vertices.push(vertex);

          c += 4;
          x++;
        }

        x = imageWidth * -0.5;
        y--;
      }
      console.log(geometry.vertices.length)
      particleSystem = new THREE.ParticleSystem(geometry, shaderMaterial);

      scene.add(particleSystem);
    }

    function tick() {
      requestAnimationFrame(tick);

      update();
      render();
    }

    function update() {
      shaderUniforms.amplitude.value = Math.tan(animationTime);

      animationTime += animationDelta;

      console.log(Math.round(shaderUniforms.amplitude.value));

      if (shaderUniforms.amplitude.value > Math.tan(animationTime)) {
        imageIndex++;
        console.log('next image',imageIndex)
      }
      controls.update();
    }

    function render() {
      renderer.render(scene, camera);
    }

    function onWindowResize() {
      camera.aspect = window.innerWidth / window.innerHeight;
      camera.updateProjectionMatrix();

      renderer.setSize(window.innerWidth, window.innerHeight);
    }

              
            
!
999px

Console