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

              
                <footer class="footer v-dark">
 Made with ☕ by <a class="footer-anchor" target="_blank" href="https://twitter.com/zadvorsky">Szenia</a>
</footer>

<div id="three-container"></div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto');

$black: #343436;
$white: #fff;
$yellow: #fcd000;

*, *:before, *:after {
 margin: 0;
 padding: 0;
 box-sizing: border-box;
}

html, body {
 width: 100%;
 height: 100%;
 overflow: hidden;
 cursor: pointer;
}

.footer {
 position: fixed;
 right: 0;
 bottom: 0;
 left: 0;
 padding: 10px 10px;
 text-align: right;
 font-family: 'Roboto', sans-serif;
 font-size: 12px;
 
 &.v-dark {
  background-color: $black;
  color: $white;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
 }
 &.v-light {
  background-color: $white;
  color: $black;
 }
}

.footer-anchor {
 display: inline-block;
 margin-left: 5px;
 padding: 2px 4px;
 color: $black;
 text-decoration: none;
 background-color: $yellow;
 border-radius: 4px;
 opacity: 1;
 transition: opacity 0.2s;
 
 &:hover {
  opacity: 0.6;
 }
}
              
            
!

JS

              
                // code is a mess! :(

// scene stuff

const root = new THREERoot({
  createCameraControls: true,
  zNear: 0.01,
  zFar: 1000,
  antialias: true
});

root.renderer.setClearColor(0xf1f1f1);
// root.controls.autoRotate = true;
// root.controls.autoRotateSpeed = -6;
root.camera.position.set(0, 0, 30);
root.scene.fog = new THREE.FogExp2(0xf1f1f1, 0.04);

const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(0, 0, 1);
root.add(light);

const light2 = new THREE.DirectionalLight(0xffffff, 1);
light2.position.set(0, 1, 0);
root.add(light2);

root.add(new THREE.AmbientLight(0xaaaaaa));
//
// feather stuff

const featherTexture = new THREE.TextureLoader().load('https://s3-us-west-2.amazonaws.com/s.cdpn.io/304639/feather_texture.png');

const pillowBoxSize = new THREE.Vector3(8, 4, 1);
const zero = new THREE.Vector3();
const pillowBox = new THREE.Box3().setFromCenterAndSize(zero, pillowBoxSize);

// create pillow geometry

// taken from three.js examples
const pillowShape = new THREE.Shape();
(function roundedRect( ctx, x, y, width, height, radius) {
  ctx.moveTo( x, y + radius );
  ctx.lineTo( x, y + height - radius );
  ctx.quadraticCurveTo( x, y + height, x + radius, y + height );
  ctx.lineTo( x + width - radius, y + height );
  ctx.quadraticCurveTo( x + width, y + height, x + width, y + height - radius );
  ctx.lineTo( x + width, y + radius );
  ctx.quadraticCurveTo( x + width, y, x + width - radius, y );
  ctx.lineTo( x + radius, y );
  ctx.quadraticCurveTo( x, y, x, y + radius );
})(pillowShape, 0, 0, pillowBoxSize.x, pillowBoxSize.y, 0.25);

const extrudeSettings = {
  steps: 1,
  amount: 0,
  bevelEnabled: true,
  bevelThickness: pillowBoxSize.z,
  bevelSize: 1,
  bevelSegments: 16
};

const pillowGeometry = new THREE.ExtrudeGeometry(pillowShape, extrudeSettings);
pillowGeometry.center();

pillowBox.expandByScalar(-0.5);

// happy fun time

let currentPillow;
let currentPillowTL;

const tick = () => {
  currentPillow = spawnPillow();

  currentPillowTL = new TimelineMax({onComplete: () => {
    root.remove(currentPillow);
    tick();
  }});

  const startX = THREE.Math.randFloat(10, 20) * (Math.random() > 0.5 ? 1 : -1);
  const endX = -startX;
  const bottomY = -16;
  const topY = THREE.Math.randFloat(8, 12);

  currentPillowTL.fromTo(currentPillow.position, 2, {x: startX}, {x: endX, ease: Power0.easeOut}, 0);
  currentPillowTL.fromTo(currentPillow.position, 1, {y: bottomY}, {y: topY, ease: Power2.easeOut}, 0);
  currentPillowTL.to(currentPillow.position, 1, {y: bottomY, ease: Power2.easeIn}, 1);
  currentPillowTL.to(currentPillow.rotation, 2, {
    x: THREE.Math.randFloatSpread(2) * Math.PI * 4,
    y: THREE.Math.randFloatSpread(2) * Math.PI * 4,
    // z: THREE.Math.randFloatSpread(2) * Math.PI * 4,
    ease: Power0.easeOut,
  }, 0);

  // explodePillow(p);
};

window.addEventListener('click', (e) => {
  currentPillow.updateMatrix();
  explodePillow(currentPillow);

  currentPillowTL.kill();

  tick();
});

tick();

function spawnPillow() {
  const m = new THREE.Mesh(pillowGeometry, new THREE.MeshStandardMaterial({
    // color: 0xf1f1f1,
    roughness: 1.0,
    transparent: true,
    fog: false,
    depthWrite: false,
  }));

  root.add(m);

  return m;
}

function explodePillow(pillow) {
  const feather = new THREE.SphereGeometry(0.9, 6, 6, 0, Math.PI * 0.2, Math.PI * 0.3, Math.PI * 0.4);
  const count = 800;

  const geometry = new BAS.PrefabBufferGeometry(feather, count);
  const v = new THREE.Vector3();
  const vv = new THREE.Vector3();
  const vvv = new THREE.Vector3();
  const q = new THREE.Quaternion();

  const startPosition = geometry.createAttribute('startPosition', 3);
  const controlPosition = geometry.createAttribute('controlPosition', 3);
  const endPosition = geometry.createAttribute('endPosition', 3);
  const data = [];

  for (let i = 0; i < count; i++) {
    // start position
    BAS.Utils.randomInBox(pillowBox, v);
    v.applyMatrix4(pillow.matrix);
    v.toArray(data);

    geometry.setPrefabData(startPosition, i, data);

    // control
    vv.subVectors(v, pillow.position);
    vv.multiplyScalar(THREE.Math.randFloat(4, 12));
    vv.toArray(data);

    geometry.setPrefabData(controlPosition, i, data);

    // end position
    vvv.copy(v);
    vvv.y = THREE.Math.randFloat(-20, -10);
    vvv.x = THREE.Math.randFloatSpread(40);
    vvv.z = THREE.Math.randFloatSpread(40);
    vvv.toArray(data);

    geometry.setPrefabData(endPosition, i, data);
  }

  geometry.createAttribute('baseRotation', 4, (data) => {
    BAS.Utils.randomAxis(v);
    q.setFromAxisAngle(v, Math.random() * Math.PI * 2);
    q.toArray(data);
  });

  geometry.createAttribute('spin', 1, (data) => {
    data[0] = THREE.Math.randFloat(Math.PI * 4, Math.PI * 8);
  });

  geometry.bufferUvs();


  const material = new BAS.BasicAnimationMaterial({
    side: THREE.DoubleSide,
    transparent: true,
    fog: true,
    depthWrite: false,
    uniforms: {
      time: {value: 0}
    },
    uniformValues: {
      map: featherTexture,
    },
    vertexParameters: `
      uniform float time;
    
      attribute vec3 startPosition;
      attribute vec3 controlPosition;
      attribute vec3 endPosition;
      attribute vec4 baseRotation;
      attribute float spin;
      
      vec3 UP = vec3(0.0, 1.0, 0.0);
    `,
    vertexFunctions: [
      BAS.ShaderChunk.ease_circ_out,
      BAS.ShaderChunk.quaternion_rotation,
      `
        vec3 quadBezier(vec3 p0, vec3 c0, vec3 p1, float t) {
          float nt = 1.0 - t;
          
          return nt * nt * p0 + 2.0 * nt * t * c0 + t * t * p1;
        }
      `
    ],
    vertexPosition: `
      float progress = easeCircOut(time);
      
      transformed = rotateVector(baseRotation, transformed);
      
      vec4 q = quatFromAxisAngle(UP, spin * time);      
      
      transformed = rotateVector(q, transformed);

      transformed += quadBezier(startPosition, controlPosition, endPosition, progress);
    `
  });

  const feathers = new THREE.Mesh(geometry, material);

  root.add(feathers);

  const tl = new TimelineMax({});
  tl.to(pillow.material, 0.2, {opacity: 0, ease: Expo.easeOut}, 0);
  tl.to(pillow.scale, 0.2, {x: 1.6, y: 1.6, z: 1.6, ease: Expo.easeOut}, 0);
  tl.add(() => {
    root.remove(pillow);
  });

  tl.to(material.uniforms.time, 20, {value: 1}, 0);
  tl.add(() => {
    root.remove(feathers);
    feathers.geometry.dispose();
    feathers.material.dispose();
  });

  // tl.timeScale(0.25);
}

              
            
!
999px

Console