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.

            
              <audio id="player" src="https://cywarr.github.io/small-shop/ChrisKeyaTotentanz.mp3">
  Your browser does not support the
  <code>audio</code> element.
</audio>

<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>

<script src="https://threejs.org/examples/js/postprocessing/EffectComposer.js"></script>
<script src="https://threejs.org/examples/js/postprocessing/RenderPass.js"></script>
<script src="https://threejs.org/examples/js/postprocessing/ShaderPass.js"></script>
<script src="https://threejs.org/examples/js/shaders/CopyShader.js"></script>
<script src="https://threejs.org/examples/js/shaders/LuminosityHighPassShader.js"></script>
<script src="https://threejs.org/examples/js/postprocessing/UnrealBloomPass.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/tween.js/17.4.0/Tween.min.js"></script>

<script type="x-shader/x-vertex" id="vertexshader">
  varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }
</script>

<script type="x-shader/x-fragment" id="fragmentshader">
  uniform sampler2D baseTexture; uniform sampler2D bloomTexture; varying vec2 vUv; vec4 getTexture( sampler2D texture ) { return mapTexelToLinear( texture2D( texture , vUv ) ); } void main() { gl_FragColor = ( getTexture( baseTexture ) + vec4( 1.0 ) * getTexture(
  bloomTexture ) ); }
</script>
<script>
  function Web(radius, radialSegments, circleSegments, linkingLevel, lastCircle, circleInaccuracy, angleInaccuracy, color) {
    // points
    let vertices = [];
    let indices = [];
    let uv = [];
    let colors = [];
    let c = color;
    let lux = [];
    let interpolation = [];

    function rC() {
      return c[THREE.Math.randInt(0, c.length - 1)];
    }
    vertices.push(new THREE.Vector3());
    uv.push(0.5, 0.5);
    let randColor = rC();
    colors.push(randColor.r, randColor.g, randColor.b);
    lux.push(0);
    interpolation.push(0);
    let base = new THREE.Vector3(1, 0, 0);
    let axis = new THREE.Vector3(0, 0, 1);
    let radiusStep = radius / circleSegments;
    let angleStep = Math.PI * 2 / radialSegments;
    let startIndex = 1;
    let circleInaccuracyValue = radiusStep * 0.5;
    let angleInaccuracyValue = angleStep * 0.33;
    let angleInaccuracies = [];
    for (let z = 0; z < radialSegments; z++) {
      angleInaccuracies.push(THREE.Math.randFloat(-1, 1) * angleInaccuracyValue * angleInaccuracy);
    }
    for (let i = 1; i <= circleSegments; i++) {
      for (let j = 0; j < radialSegments; j++) {
        let rI = radiusStep * i + (THREE.Math.randFloat(-1, 1) * circleInaccuracyValue * circleInaccuracy);
        let aI = angleStep * j + angleInaccuracies[j];
        let v = new THREE.Vector3().copy(base).multiplyScalar(rI).applyAxisAngle(axis, aI);
        vertices.push(v);
        randColor = rC();
        colors.push(randColor.r, randColor.g, randColor.b);
        lux.push(Math.random() < 0.5 ? 0 : 1);
        let uvX = (v.x - (-radius)) / (radius * 2);
        let uvY = (v.y - (-radius)) / (radius * 2);
        uv.push(uvX, uvY);
        let interp = v.length() / radius;
        interpolation.push(interp);
        let idx = j + startIndex;
        // link circles
        indices.push(idx, i === 1 ? 0 : idx - radialSegments);
        // link radialSegments
        if (!lastCircle && i === circleSegments) continue;
        if (Math.random() <= linkingLevel) {
          indices.push(idx, j === radialSegments - 1 ? startIndex : idx + 1);
        }
      }
      startIndex += radialSegments;
    }
    let g = new THREE.BufferGeometry().setFromPoints(vertices);
    //g.addAttribute("uv", new THREE.Float32BufferAttribute(uv, 2));
    //g.addAttribute("interpolation", new THREE.Float32BufferAttribute(interpolation, 1));
    g.addAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
    g.addAttribute("lux", new THREE.Float32BufferAttribute(lux, 1));
    g.attributes.lux.setDynamic(true);
    g.setIndex(indices);
    //console.log(g)
    return g;
  }
</script>
<script>
  class Spider extends THREE.Object3D {
    constructor() {
      super();
      this.legs = [];
      let headChestGeom = new THREE.SphereBufferGeometry(0.3, 8, 4);
      headChestGeom.rotateX(-Math.PI * 0.5);
      headChestGeom.translate(0, 0, 0.2);
      headChestGeom.scale(1, 0.75, 1);
      let headChestMat = this.createMaterial(0x010101, null, 0);
      let headChest = new THREE.Mesh(headChestGeom, headChestMat);
      this.add(headChest);
      let bumGeom = new THREE.SphereBufferGeometry(0.5, 8, 4);
      bumGeom.rotateY(-Math.PI * 0.5);
      bumGeom.rotateX(-Math.PI * 0.5);
      bumGeom.translate(0, 0, -0.45);
      bumGeom.scale(1, 0.5, 1);
      let c = document.createElement("canvas");
      c.width = 128;
      c.height = 128;
      let ctx = c.getContext("2d");
      ctx.fillStyle = "black";
      ctx.fillRect(0, 0, 128, 128);
      ctx.strokeStyle = "darkorange";
      ctx.lineWidth = 3;
      ctx.beginPath();
      ctx.moveTo(63, 43);
      ctx.lineTo(63, 83);
      ctx.stroke();
      ctx.lineWidth = 5;
      ctx.beginPath();
      ctx.moveTo(53, 63);
      ctx.lineTo(73, 63);
      ctx.stroke();
      let tex = new THREE.CanvasTexture(c);
      let bumMat = this.createMaterial(0xffffff, tex, 1);
      let bum = new THREE.Mesh(bumGeom, bumMat);
      this.add(bum);
      // fangs
      let fangGeom = new THREE.SphereBufferGeometry(0.0625, 16, 8);
      fangGeom.scale(1, 3, 1);
      fangGeom.rotateX(THREE.Math.degToRad(-15));
      let fangMat = this.createMaterial(0xFF8C00, null, 1);
      let fangRight = new THREE.Mesh(fangGeom, fangMat);
      fangRight.position.set(-0.075, 0, 0.4);
      this.add(fangRight);
      let fangLeft = new THREE.Mesh(fangGeom, fangMat);
      fangLeft.position.set(0.075, 0, 0.4);
      this.add(fangLeft);
      //legs
      let legsParams = [
        {
          siz: 0.0625,
          pos: new THREE.Vector3(-0.25, 0, 0.05),
          rot: new THREE.Euler(0, THREE.Math.degToRad(-30), 0),
          phRot: THREE.Math.degToRad(60)
        },
        {
          siz: 0.0625 * 1.1,
          pos: new THREE.Vector3(-0.3, 0, 0),
          rot: new THREE.Euler(0, THREE.Math.degToRad(-70), 0),
          phRot: THREE.Math.degToRad(60)
        },
        {
          siz: 0.0625 * 1.1,
          pos: new THREE.Vector3(-0.3, 0, 0),
          rot: new THREE.Euler(0, THREE.Math.degToRad(-110), 0),
          phRot: THREE.Math.degToRad(60)
        },
        {
          siz: 0.0625,
          pos: new THREE.Vector3(-0.3, 0, 0),
          rot: new THREE.Euler(0, THREE.Math.degToRad(-150), 0),
          phRot: THREE.Math.degToRad(60)
        }
      ];
      legsParams.forEach( par => {
        let legR = this.createLeg(par.siz);
        legR.rotation.copy(par.rot);
        legR.position.copy(par.pos);
        this.legs.push(legR);
        this.add(legR);
        legR.phalanxes.forEach((ph, ndx) => {
          let idx = ndx == 0 ? -1 : 1;
          let idxRatio = ndx == 0 ? 0.6 : 1;
          ph.rotation.x = idx * par.phRot * idxRatio;
        });
        
        let legL = this.createLeg(par.siz);
        legL.rotation.set(par.rot.x, -par.rot.y, par.rot.z);
        legL.position.set(-par.pos.x, par.pos.y, par.pos.z);
        this.legs.push(legL);
        this.add(legL);
        legL.phalanxes.forEach((ph, ndx) => {
          let idx = ndx == 0 ? -1 : 1;
          let idxRatio = ndx == 0 ? 0.6 : 1;
          ph.rotation.x = idx * par.phRot * idxRatio;
        });
      })
      
      this.animations = {
        jump: () => {
          this.position.set(0, 0.25, 0);
          new TWEEN.Tween(this.position).to({y: 0.275}, 125).yoyo(true).repeat(1).start();
        }
      }
    }
    createLeg(size) {
      let leg = new THREE.Group();
      leg.onAction = false;
      leg.phalanxes = [];
      let firstPhalanx = this.createPhalanx(size, false);
      leg.add(firstPhalanx);
      leg.phalanxes.push(firstPhalanx);
      let secondPhalanx = this.createPhalanx(size * 0.9, false);
      secondPhalanx.position.z = size * 6;
      firstPhalanx.add(secondPhalanx);
      leg.phalanxes.push(secondPhalanx);
      let thirdPhalanx = this.createPhalanx(size * 0.9, true);
      thirdPhalanx.position.z = size * 0.9 * 6;
      secondPhalanx.add(thirdPhalanx);
      leg.phalanxes.push(thirdPhalanx);
      leg.animations = {
        upDown: (angle) => {
          if (leg.onAction) return;
          let currentAngle = {value: leg.phalanxes[1].rotation.x}
          new TWEEN.Tween(currentAngle)
            .to({value: angle}, 250)
            .onStart(() => {leg.onAction = true;})
            .onUpdate(value => {
                leg.phalanxes[1].rotation.x = value.value;
            })
            .onComplete(() => {leg.onAction = false;})
            .start();
          }
      };
      return leg;
    }
    createPhalanx(size, isLast) {
      let jointGeom = new THREE.SphereBufferGeometry(size, 8, 4);
      let jointMat = this.createMaterial(0xff8800, null, 1);
      let joint = new THREE.Mesh(jointGeom, jointMat);
      let phalanxGeom = new THREE.CylinderBufferGeometry(isLast ? 0 : size * 0.75, size * 0.75, size * 6, 5, 1, true);
      phalanxGeom.rotateX(Math.PI * 0.5);
      phalanxGeom.translate(0, 0, size * 3);
      let phalanxMat = this.createMaterial(0x222222, null, 0);
      let phalanx = new THREE.Mesh(phalanxGeom, phalanxMat);
      joint.add(phalanx);
      return joint;
    }
    createMaterial(color, texture, hasBloom) {
      let material = new THREE.MeshLambertMaterial({
        color: color,
        map: texture
      });
      material.onBeforeCompile = shader => {
        shader.uniforms.globalDarkening = globalDarkening;
        shader.uniforms.hasBloom = {
          value: hasBloom
        };
        shader.fragmentShader = `
        uniform float globalDarkening;
        uniform float hasBloom;
      ` + shader.fragmentShader;
        shader.fragmentShader = shader.fragmentShader.replace(
          `void main() {`,
          `void main() {
          if (globalDarkening < 0.5 || hasBloom > 0.5){
        `
        );
        shader.fragmentShader = shader.fragmentShader.replace(
          `#include <dithering_fragment>`,
          `#include <dithering_fragment>

          } else {
            gl_FragColor = vec4(vec3(0), 1.0);
          }`
        );
      }
      return material;
    }
  }
</script>
<script>
  function setFront(){
    
      // name - Totentanz
      let sceneTitle = [
        [1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1],
        [0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1],
        [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1],
        [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0],
        [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0],
        [0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0],
        [0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0],
        [0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1]
      ];
      let pixels = [];
      
      let n = document.createElement("div");
      n.id = "title";
      n.title = "Musik: Chris Keya - Totentanz";
      n.style.width = (sceneTitle[0].length) + "vh";
      n.style.height = (sceneTitle.length) + "vh";
      for (let i = 0; i < sceneTitle.length; i++){
        for (let j = 0; j < sceneTitle[0].length; j++){
          if (sceneTitle[i][j] == 0) continue;
          let pixel = document.createElement("div");
          pixel.setAttribute("class", "pixel");
          let randX = THREE.Math.randInt(-27, 71);
          let randY = THREE.Math.randInt(-87, 11);
          //pixel.style.transform = `translate(${randX}vh, ${randY}vh)`;
          n.appendChild(pixel);
          pixels.push(
              new TWEEN.Tween({x:randX, y: randY})
                .to({x:j, y: i}, THREE.Math.randFloat(1, 9) * 1000)
                .easing(TWEEN.Easing.Quintic.In)
                .onUpdate( (value) => {
                  pixel.style.transform = `translate(${value.x}vh, ${value.y}vh)`;
                })
         )
        }
      }
      document.body.appendChild(n);
      console.log(n);
      
      // start screen
      let d = document.createElement("div");
      d.id = "front";
      let b = document.createElement("button");
      b.id = "start";
      b.innerText = "Tanze!";
      b.addEventListener("click", event => {
        
        d.style.display = "none";

        startTanzen(); // start sequence
        pixels.forEach(pix => {pix.start()}); // gather the title
        player.play(); // start player
        
        renderer.setAnimationLoop(render);
        
      });
      d.appendChild(b);
      document.body.appendChild(d);

  }
 
</script>
            
          
!
            
              html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  position: relative;
  background-color: black;
}

canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -50vh;
  margin-top: -50vh;
}

#front {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: #808;
  opacity: 0.99;
}
#start {
  position: absolute;
  width: 130px;
  height: 50px;
  font-family: Monospace;
  /*font-weight: bold;*/
  font-size: 24px;
  top: 50%;
  left: 50%;
  margin-top: -25px;
  margin-left: -65px;
  color: #fff;
  background-color: #b0b;
  border: 0.5vh solid magenta;
}

#title {
  position: absolute;
  bottom: 2vh;
  left: 50%;
  margin-left: -22vh;
}

.pixel {
  position: absolute;
  width: 0.75vh;
  height: 0.75vh;
  background-color: #f8f;
  box-shadow: 1vh 1vh 0 0 #088;
}

#player {
  position: absolute;
  display: none;
}
            
          
!
            
              var params = {
  exposure: 1,
  bloomStrength: 2.5,
  bloomThreshold: 0,
  bloomRadius: 0
};

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
  60,
  window.innerHeight / window.innerHeight,
  1,
  1000
);
camera.position.set(0.5, 3, 3).setLength(3);
var renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerHeight, window.innerHeight);
renderer.toneMapping = THREE.ReinhardToneMapping;
renderer.toneMappingExposure = Math.pow(params.exposure, 4.0);
renderer.setClearColor(0x332233);
document.body.appendChild(renderer.domElement);

setFront();

var renderScene = new THREE.RenderPass(scene, camera);
var bloomPass = new THREE.UnrealBloomPass(
  new THREE.Vector2(window.innerWidth, window.innerHeight),
  1.5,
  0.4,
  0.85
);
bloomPass.threshold = params.bloomThreshold;
bloomPass.strength = params.bloomStrength;
bloomPass.radius = params.bloomRadius;
var bloomComposer = new THREE.EffectComposer(renderer);
bloomComposer.renderToScreen = false;
bloomComposer.setSize(
  window.innerWidth * window.devicePixelRatio,
  window.innerHeight * window.devicePixelRatio
);
bloomComposer.addPass(renderScene);
bloomComposer.addPass(bloomPass);
var finalPass = new THREE.ShaderPass(
  new THREE.ShaderMaterial({
    uniforms: {
      baseTexture: { value: null },
      bloomTexture: { value: bloomComposer.renderTarget2.texture }
    },
    vertexShader: document.getElementById("vertexshader").textContent,
    fragmentShader: document.getElementById("fragmentshader").textContent,
    defines: {}
  }),
  "baseTexture"
);
finalPass.needsSwap = true;
var finalComposer = new THREE.EffectComposer(renderer);
finalComposer.setSize(
  window.innerWidth * window.devicePixelRatio,
  window.innerHeight * window.devicePixelRatio
);
finalComposer.addPass(renderScene);
finalComposer.addPass(finalPass);

// controls ///////////////////////////////////////////////////////
var controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enablePam = false;
controls.minDistance = 2.5;
controls.maxDistance = 10;
///////////////////////////////////////////////////////////////////

var light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(1, 10, 1);
scene.add(light);
scene.add(new THREE.AmbientLight(0xffffff, 0.5));

var globalDarkening = {value: 1};

// web
let webGeom = Web(5, 19, 19, 0.95, false, 0.25, 0.5, [new THREE.Color(1, 0, 1), new THREE.Color(0, 1, 1)]);
webGeom.rotateX(-Math.PI * 0.5);
let webMat = new THREE.LineBasicMaterial({vertexColors: THREE.VertexColors});
webMat.onBeforeCompile = shader => {
  shader.uniforms.globalDarkening = globalDarkening;
  shader.uniforms.baseColor = {value: new THREE.Color(0.125, 0.125, 0.25)};
  shader.vertexShader = `
    uniform float globalDarkening;
    uniform vec3 baseColor;
    attribute float lux;
  ` + shader.vertexShader;
  shader.vertexShader = shader.vertexShader.replace(
    `#include <color_vertex>`,
    `#include <color_vertex>
    float bloom = step(0.5, globalDarkening);
    vec3 base = mix(baseColor, vec3(0), bloom);
    vColor = mix(base, vColor, lux);
    `
  )
}
let web = new THREE.LineSegments(webGeom, webMat);
scene.add(web);

var spider = new Spider();
spider.position.set(0, 0.25, 0);
scene.add(spider);

function startTanzen(){
  setTimeout(() => {
    controls.autoRotate = true;
    controls.autoRotateSpeed = 1;
    changeRotation();
    tanzen();
    setInterval(tanzen, 632);
  }, 10000);
}

function tanzen(){
  for (let i = 0; i < web.geometry.attributes.lux.count; i++){
    web.geometry.attributes.lux.setX(i, Math.random() < 0.5 ? 0 : 1);
    web.geometry.attributes.lux.needsUpdate = true;
  };
  spider.legs.forEach(leg => {leg.animations.upDown( Math.PI / 3 )});
  for(let i = 0; i < 3; i++){
    let newIndex = THREE.Math.randInt(0, 7);
    let legUp = spider.legs[newIndex];
    legUp.animations.upDown(0);
  }
  spider.animations.jump();
}

function changeRotation() {
  setTimeout(function tick() {
    controls.autoRotateSpeed *= -1;
    setTimeout(tick, THREE.Math.randInt(12, 24) * 632);
  }, THREE.Math.randInt(12, 24) * 632);
}


var time = 0;



window.onresize = function() {
  var width = window.innerHeight;
  var height = window.innerHeight;
  camera.aspect = width / height;
  camera.updateProjectionMatrix();
  renderer.setSize(width, height);
  bloomComposer.setSize(
    width * window.devicePixelRatio,
    height * window.devicePixelRatio
  );
  finalComposer.setSize(
    width * window.devicePixelRatio,
    height * window.devicePixelRatio
  );
};

function render() {
  time = performance.now() / 1000;
  controls.update();
  TWEEN.update();
  //web.rotation.y = time * THREE.Math.degToRad(13);

  //renderer.render(scene, camera);
  // render scene with bloom
  renderBloom();
  // render the entire scene, then render bloom scene on top
  finalComposer.render();

}

function renderBloom() {
  scene.traverse(darkenNonBloomed);
  bloomComposer.render();
  scene.traverse(restoreMaterial);
}
function darkenNonBloomed(obj) { // non-bloomed stuff must be black, including scene background
  globalDarkening.value = 1;
  renderer.setClearColor(0x000000);
}
function restoreMaterial(obj) {
  globalDarkening.value = 0;
  renderer.setClearColor(0x442244);
}

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

Console