cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <!-- 
 Click and hold! :)
-->

<div class="background"></div>
<div class="progress"></div>
<canvas></canvas>

<footer>
 Made by <a href="https://twitter.com/cvaneenige" target="_blank">Colin</a> & <a class="footer-anchor" target="_blank" href="https://twitter.com/jorisvanr">Joris</a>
</footer>
            
          
!
            
              html,
body {
 width: 100%;
 height: 100%;
 margin: 0;
 overflow: hidden;
}

canvas {
 image-rendering: pixelated;
 position: relative;
 width: 100%;
 height: 100%;
 cursor: pointer
}

.background {
 background: linear-gradient(black, #1e88e5);
 height: 400vh;
 position: fixed;
 width: 100%;
 height: 800%;
 top: 0;
 left: 0;
 transform: translate3d(0, -75%, 0);
}

.progress {
 width: 100%;
 position: fixed;
 bottom: 0;
 left: 0;
 height: 2px;
 background: #99ccff;
 transform: translate3d(-100%, 0, 0);
}

* {
 user-select: none;
 -webkit-tap-highlight-color: transparent;
}

footer {
 position: fixed;
 right: 0;
 bottom: 0;
 left: 0;
 padding: 10px 10px;
 text-align: right;
 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
 font-size: 14px;
 
  color: #FFF;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
 display: inline-block;
 margin-left: 2px;
 padding: 2px 4px;
 color: rgba(52, 52, 54, 1.0);
 text-decoration: none;
 background-color: #fcd000;
 border-radius: 4px;
 opacity: 1;
 transition: opacity 0.2s;
 
 &:hover {
  opacity: 0.6;
 }
}

            
          
!
            
              const json = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/304639/rocket.json";

const canvas = document.querySelector("canvas");
const background = document.querySelector(".background");
const bar = document.querySelector(".progress");

const initialize = vertices => {
 const geometry = createGeometry(0.002);
 const multiplier = vertices.length / 3;
 const attributes = [
  {
   name: "aPositionStart",
   data: i => [vertices[i].x, vertices[i].y, vertices[i].z + 0.1]
  },
  {
   name: "aControlPointOne",
   data: i => [vertices[i].x, vertices[i].y - 2, vertices[i].z]
  },
  {
   name: "aControlPointTwo",
   data: i => [vertices[i].x, vertices[i].y + 6, vertices[i].z]
  },
  {
   name: "aPositionEnd",
   data: () => [getRandom(3), getRandom(3), getRandom(2)]
  }
 ];

 const uniforms = [
  {
   name: "uProgress",
   type: "float",
   value: 0.0
  }
 ];

 const vertexShader = `
    attribute vec3 position;
    attribute vec3 aPositionStart;
    attribute vec3 aControlPointOne;
    attribute vec3 aControlPointTwo;
    attribute vec3 aPositionEnd;

    uniform float uProgress;
    uniform mat4 uMVP;

    vec3 bezier4(vec3 a, vec3 b, vec3 c, vec3 d, float t) {
      return mix(mix(mix(a, b, t), mix(b, c, t), t), mix(mix(b, c, t), mix(c, d, t), t), t);
    }

    float easeInOutQuint(float t){
      return t < 0.5 ? 16.0 * t * t * t * t * t : 1.0 + 16.0 * (--t) * t * t * t * t;
    }

    void main () {
      vec3 newPosition = bezier4(aPositionStart, aControlPointOne, aControlPointTwo, aPositionEnd, easeInOutQuint(uProgress));
      gl_Position = uMVP * vec4(newPosition + position, 1.0);
    }
  `;

 const fragmentShader = `
    precision mediump float;

    void main() {
      gl_FragColor = vec4(0.6, 0.8, 1.0, 1.0);
    }
  `;

 const baseRotation = 0.05;
 let rotation = baseRotation;

 const hold = new Hold({
  element: canvas,
  duration: 3,
  onProgress: progress => {
   uniforms[0].value = progress;
   if (progress < 0.6) {
    rotation = baseRotation + progress * 0.4;
   } else {
    rotation = 0.01;
   }
   background.style.transform = `translate3d(0, -${75 - 75 * progress}%, 0)`;
   bar.style.transform = `translate3d(${-100 + 100 * progress}%, 0, 0)`;
  }
 });

 const onRepeat = () => {
  rotateY(uniforms[uniforms.length - 1].value, rotation);
 };

 starlings(
  canvas,
  geometry,
  multiplier,
  attributes,
  uniforms,
  vertexShader,
  fragmentShader,
  () => {},
  onRepeat
 );
};

const getRandom = value => Math.random() * value - value / 2;

const loadJSON = callback => {
 const xhr = new XMLHttpRequest();
 xhr.overrideMimeType("application/json");
 xhr.open("GET", json, true);
 xhr.onreadystatechange = () => {
  if (xhr.readyState == 4 && xhr.status == "200") {
   callback(xhr.responseText);
  }
 };
 xhr.send(null);
};

const rotateY = (matrix, angle) => {
 const sin = Math.sin(angle);
 const cos = Math.cos(angle);
 const clone = JSON.parse(JSON.stringify(matrix));

 matrix[0] = clone[0] * cos - clone[8] * sin;
 matrix[1] = clone[1] * cos - clone[9] * sin;
 matrix[2] = clone[2] * cos - clone[10] * sin;
 matrix[3] = clone[3] * cos - clone[11] * sin;
 matrix[8] = clone[0] * sin + clone[8] * cos;
 matrix[9] = clone[1] * sin + clone[9] * cos;
 matrix[10] = clone[2] * sin + clone[10] * cos;
 matrix[11] = clone[3] * sin + clone[11] * cos;
};

const createGeometry = size => [
 { x: -size, y: -size, z: size },
 { x: size, y: size, z: size },
 { x: -size, y: size, z: -size },
 { x: size, y: -size, z: -size },
 { x: -size, y: size, z: -size },
 { x: size, y: size, z: size },
 { x: size, y: -size, z: -size },
 { x: size, y: size, z: size },
 { x: -size, y: -size, z: size },
 { x: size, y: -size, z: -size },
 { x: -size, y: -size, z: size },
 { x: -size, y: size, z: -size }
];

class Hold {
 constructor(props) {
  this.element = props.element || window;
  this.begin = props.begin || 0;
  this.end = props.end || 1;
  this.duration = props.duration || 1;
  this.intervalDuration = props.intervalDuration || 8;
  this.loop = props.loop || false;
  this.reset = props.reset || false;
  this.onProgress = props.onProgress || false;
  this.onComplete = props.onComplete || false;

  this.step =
   (this.end - this.begin) / (this.duration * 1000 / this.intervalDuration);
  this.current = this.begin;
  this.state = "hold";

  this.element.addEventListener("mousedown", this.onHold.bind(this), false);
  this.element.addEventListener("touchstart", this.onHold.bind(this), false);
  this.element.addEventListener("mouseup", this.onRelease.bind(this), false);
  this.element.addEventListener("touchend", this.onRelease.bind(this), false);
 }

 onHold() {
  this.state = "hold";
  if (this.interval) clearInterval(this.interval);
  this.interval = setInterval(this.onStep.bind(this), this.intervalDuration);
 }

 onStep() {
  this.current += this.state === "hold" ? this.step : -this.step;

  if (this.current < this.begin) {
   this.current = this.begin;
   clearInterval(this.interval);
   this.onProgress(this.current);
   return;
  }

  if (this.current > this.end) {
   if (this.loop) {
    this.current = this.begin;
   } else {
    this.current = this.end;
   }
   if (this.onComplete !== false) {
    clearInterval(this.interval);
    this.onProgress(this.current);
    this.onComplete();
    return;
   }
  }
  this.onProgress(this.current);
 }

 onRelease() {
  if (this.reset) {
   this.current = this.begin;
   clearInterval(this.interval);
   this.onProgress(this.current);
   return;
  }
  this.state = "release";
 }
}

loadJSON(vertices => {
 initialize(JSON.parse(vertices));
});

            
          
!
999px
Loading ..................

Console