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.

            
              <a id="staakLogo" class="link" href="https://www.staak.co.uk/?ref=codepen&id=QYbLXY" target="_blank" rel="noreferrer noopener">
  <svg class="link" xmlns="http://www.w3.org/2000/svg" viewBox="17 348.4 630.7 145.5">
    <path class="link" d="M255.4 450.9c-2.1 6.7-2.9 12.1-2.9 16.4 0 15.2 15 22.7 26 22.7v1.2h-59.9l.1-1.3c9.6 0 17.3-8.5 24-22.6l28.5-59.9.6 1.9c-7.1 15.4-12.3 27.9-15.4 37.8M381 490v1.2h-75V490c9.6 0 18.1-6.2 12.9-17l-39.3-82.7 19-42.5h2.1l61.5 131.4c3.8 8.1 8.6 10.8 18.8 10.8z"
          />
    <path class="link" d="M386 450.2c-2.1 6.7-2.9 12.1-2.9 16.4 0 15.2 15 22.7 26 22.7v1.2h-59.9v-.8c9.6 0 17.5-8.9 24.1-23.1l28.5-59.9.6 1.9c-7.1 15.4-12.3 27.9-15.4 37.8M511.1 490v1.2h-75V490c9.6 0 18.1-6.2 12.9-17l-39.3-82.7 19.1-42.5h2.1l61.5 131.4c3.7 8.1 8.5 10.8 18.7 10.8z"
          />
    <path class="link" d="M559.7 490v1.2h-66.3V490c12.5 0 15.6-5 15.6-10.6V362c0-5.6-3.1-10.8-15.6-10.8v-1.3h66.3v1.2c-12.3 0-15.4 5.2-15.4 10.8v117.5c0 5.6 3.2 10.6 15.4 10.6zm88.4 0v1.2h-68.2V490c6.4 0 11-3.1 11-7.3 0-4.4-1.2-6.7-2.9-9.1l-32.6-49.9c32.2-32.4 38.3-51.6 38.3-60.9 0-8.1-8.1-11.6-13.9-11.6v-1.3h61.1v1.2c-8.9 0-13.9 4.2-20.4 10.4L580.2 400l52.2 79.6c4 6.3 8 10.4 15.7 10.4zM19.1 442.6h-1.7v50.7h1.7l6.9-10.2c10.8 6.7 23.9 9.8 40.3 10.2v-1.2c-25.6-8.6-40.4-26-47.2-49.5zM48 368.2c0-11.4 8.7-17.5 18.3-19.1v-1.3C38.6 349.7 18.4 364 18.4 389c0 42.2 79.4 45.5 79.4 81.9 0 12.5-11.2 19.1-22.7 21.2v1.2c32.2-1.2 52.2-15.8 52.2-42.6.1-42.2-79.3-46.1-79.3-82.5zM204.9 479V349.9h-35.3V479c0 5.6-3.1 11-15.6 11v1.2h66.5V490c-12.5 0-15.6-5.4-15.6-11zM215.3 349.9v1.2c16 4 28.5 22.5 33.7 44.9h1.7v-46.1h-35.4zM159.2 349.9h-39.1l-7.5 8.9c-9.6-6.8-21.8-10.4-37.4-11v1.2c21.3 4.3 45.1 29.5 47.2 55.8l.2 4.1c6.2-34.7 20.2-53 36.6-57.8v-1.2z"
          /></svg>
</a>
            
          
!
            
              body, html {
  margin: 0;
  padding: 0;
  display: flex;
  background: black;
}

#staakLogo {
  width: 4vw;
  max-width: 100px;
  min-width: 80px;
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 20;
  padding: 10px;
}

#staakLogo svg {
  width: 100%;
  display: block;
}
#staakLogo svg path {
  fill: #FF1EAD;
}
            
          
!
            
              class App {
  
  constructor() {
     
    // canvas size
    this.width = window.innerWidth;
    this.height = window.innerHeight;
    
    // define loader & manager
    let threeLoaderManager = new THREE.LoadingManager();
    this.loader = new THREE.SVGLoader(threeLoaderManager);
    
    // define assets
    let assets = [
      { url: 'https://staakcodepen.s3.amazonaws.com/cpc-pop/Lobster-Neon-V5-01.svg', name: 'lobster1' },
      { url: 'https://staakcodepen.s3.amazonaws.com/cpc-pop/Lobster-Neon-V5-02.svg', name: 'lobster2' }
    ];
    
    // load assets
    for(var i = 0; i < assets.length; i++) {
      this.preload(assets[i]);
    }
  
    // on file load event
    threeLoaderManager.onProgress = (item, loaded, total) => {

        // call preloadeComplete, when files loaded
        if(loaded == total) {
          this.preloadeComplete();
        }
    };
  }
  
  preload(item) {
    
    // load a SVG resource
    this.loader.load(
      // resource URL
      item.url,
      // called when the resource is loaded
      ( paths ) => {
         
        // set data
        this[item.name] = paths;
      }
    );
    
  }
  
  preloadeComplete() {
    
      this.renderer = new THREE.WebGLRenderer({
        antialias: true,
      });

      this.renderer.domElement.id = "scene-canvas";
      this.renderer.setClearColor(0x000000);

      this.renderer.setSize(this.width, this.height);
      this.renderer.setPixelRatio(window.devicePixelRatio);

      document.body.appendChild(this.renderer.domElement);

      this.camera = new THREE.PerspectiveCamera(35, this.width / this.height, 0.1, 10000);
      this.camera.position.set(-974, -505, -2000);
      this.camera.lookAt(new THREE.Vector3(-974, -505, 1750));

      this.camera.aspect = this.width / this.height;
      this.camera.updateProjectionMatrix();

      this.resizeListener = e => this.onResize(e);
	    window.addEventListener( 'resize', this.resizeListener, false );

      this.scene = new THREE.Scene();
    
      // initialise app
      this.init();
  }

  init() {

      // group array
      let groupArray = [
        new THREE.Group(),
        new THREE.Group(),
        new THREE.Group(),
        new THREE.Group(),
        new THREE.Group()
      ];

      // material array
      let materialArray = [
        new THREE.MeshBasicMaterial( {
          color: 0xFFFFFF,
          side: THREE.DoubleSide
        }),
        new THREE.MeshBasicMaterial( {
          color: 0xFF1EAD,
          side: THREE.DoubleSide
        })
      ];

      // assets array
      let svgArray = [
        'lobster1',
        'lobster2'
      ];

      // set color rbg string to look for
      let colorStringCompare = '111';

      // loop through assets
      for (let index = 0, groupKey = 0; index < svgArray.length; index++, groupKey+=2) {
        
        // define item
        var item = svgArray[index];

        // loop though paths
        for (let i = 0; i < this[item].length; i ++) {

          // define paths
          var path = this[item][i];

          let shapeToggle = true;
          var shapes = path.toShapes(shapeToggle);

          // loop through shapes
          for (let j = 0; j < shapes.length; j ++) {

            // change material based on path color definition
            var materialKey = 1;
            var pathColor = `${path.color.r}${path.color.g}${path.color.b}`;
            if(pathColor == colorStringCompare) {
              materialKey = 0;
            }

            // define shape
            var shape = shapes[ j ];

            // set meshes from shapes
            // add to groups
            var geometry = new THREE.ShapeBufferGeometry( shape );
            var mesh = new THREE.Mesh( geometry, materialArray[0] );
            groupArray[groupKey + 0].add( mesh );

            var mesh2 = new THREE.Mesh( geometry, materialArray[materialKey] );
            mesh2.layers.enable(1);
            groupArray[groupKey + 1].add( mesh2 );
          }
        }
      }

      // add groups to scene
      for (let index = 0; index < groupArray.length; index++) {
        let group = groupArray[index];

        if(index == 2 || index == 3) {
          group.visible = false;
        }

        group.rotateZ(THREE.Math.degToRad(180));
        if(index == 1 || index == 3) {
          group.position.z = 5;
        }
        this.scene.add(group);
      }

      // Toggle visibility
      setInterval(() => {
        groupArray[0].visible = !groupArray[0].visible;
        groupArray[1].visible = !groupArray[1].visible;
        groupArray[2].visible = !groupArray[2].visible;
        groupArray[3].visible = !groupArray[3].visible;
      }, 1 * 1000);

      // Set up post processing
      var renderScene = new THREE.RenderPass( this.scene, this.camera );
			var bloomPass = new THREE.UnrealBloomPass( new THREE.Vector2( this.width, this.height ), 1.5, 0.4, 0.85 );
			bloomPass.renderToScreen = true;
			bloomPass.threshold = 0;
			bloomPass.strength = 1.5;
      bloomPass.radius = 0.5;

      let FXAAShaderPass = new THREE.ShaderPass(THREE.FXAAShader);
      FXAAShaderPass.uniforms['resolution'].value.set(
        1 / this.width,
        1 / this.height
      );
      
			this.composer = new THREE.EffectComposer( this.renderer );
			this.composer.setSize( this.width, this.height );
      this.composer.addPass( renderScene );
      this.composer.addPass( FXAAShaderPass );
			this.composer.addPass( bloomPass );

      this.animate();
  }
  
  onResize() {

    // scene & camera update
    this.camera.aspect = window.innerWidth / window.innerHeight;
    this.camera.updateProjectionMatrix();
    this.renderer.setSize( window.innerWidth, window.innerHeight );
  }

  animate() {

      this.renderer.setAnimationLoop(() => {
        this.update();
        this.render();
      });
  }

  update() {
    //
  }

  render() {
    this.renderer.autoClear = false;
    this.renderer.clear();

    this.camera.layers.set(1);
    this.composer.render();

    this.renderer.clearDepth();
    this.camera.layers.set(0);

    this.renderer.render(this.scene, this.camera);
  }
}

let app = new App();
            
          
!
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