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

              
                <h2>Working version <a href="https://zachsaucier.com/my-tunnel/index.html">here</a></h2>
<h1>Zach Saucier</h1>
<!-- three.js container -->
<div id="container"></div>
<div id="inlineDoc">
  <span id="fullscreenDoc"><i>f</i> for fullscreen - </span><i>p</i> for screenshot
</div>
              
            
!

CSS

              
                body { background: #24132E; }
h1,
.redShift {
  font-family: 'Abel', sans-serif;
  font-size: 10vh;
  font-weight: normal;
  white-space: nowrap;
  letter-spacing: 5vh;
  text-transform: uppercase;
  position: absolute;
}

h1 {
  color: white;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.redShift {
  content: attr(data-name);
  left: 0;
  top: 0;
  color: red;
  z-index: -1;
  pointer-events: none;
}


h2 {
  position: absolute;
  width: 100%; 
  text-align: center;
  color: white;
}
              
            
!

JS

              
                var stats, scene, renderer;
var camera, cameraControl;
var texture, mesh;

var header = document.querySelector("h1"),
  redShift;

if (!init()) animate();

// init the scene
function init() {
  createRedShift();

  if (Detector.webgl) {
    renderer = new THREE.WebGLRenderer({
      antialias: true, // to get smoother output
      preserveDrawingBuffer: true // to allow screenshot
    });
    renderer.setClearColor(0x24132E, 1);
    // uncomment if webgl is required
  } else {
    Detector.addGetWebGLMessage();
    return true;
  }
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.autoClear = false;
  document.getElementById('container').appendChild(renderer.domElement);

  // add Stats.js - https://github.com/mrdoob/stats.js
  stats = new Stats();
  stats.domElement.style.position = 'absolute';
  stats.domElement.style.bottom = '0px';
  document.body.appendChild(stats.domElement);

  // create a scene
  scene = new THREE.Scene();
  overlayScene = new THREE.Scene();

  // put a camera in the scene
  camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 0.1, 10000);
  camera.position.set(0, 0, 7);
  camera.lookAt(scene.position)
  scene.add(camera);

  // transparently support window resize
  THREEx.WindowResize.bind(renderer, camera);
  // allow 'p' to make screenshot
  THREEx.Screenshot.bindKey(renderer);
  // allow 'f' to go fullscreen where this feature is supported
  if (THREEx.FullScreen.available()) {
    THREEx.FullScreen.bindKey();
  } else {
    document.getElementById('fullscreenDoc').style.display = "none";
  }

  scene.fog = new THREE.FogExp2(0x24132E, 0.03);

  // Create the line "star" animation
  var geometry = new THREE.CylinderGeometry(1, 1, 100, 32, 1, true);

  // Load our cylinder
  var textureLoader = new THREE.TextureLoader();
  var material;

  textureLoader.load(
    "https://crossorigin.me/https://zachsaucier.com/pen-stuff/lines.jpg",
    function(text) {
      texture = text;

      texture.wrapT = THREE.RepeatWrapping;

      material = new THREE.MeshBasicMaterial({
        color: 0xffffff,
        map: texture
      });
      material.side = THREE.DoubleSide; // new version of mesh.flipSided	= true;
      mesh = new THREE.Mesh(geometry, material);
      mesh.rotation.x = 1.5;
      scene.add(mesh);

      console.log("Texture has loaded");
    }
  );

  // Make a triangle around the middle to fake a mask
  var path = new THREE.Path();

  // The outside of the shape (outside of viewport)
  path.moveTo(-50, 50);
  path.lineTo(50, 50);
  path.lineTo(50, -50);
  path.lineTo(-50, -50);
  path.lineTo(-50, 50);

  // The inside (coutout) section
  var c = 4, // Side length of the triangle
    a = c / 2,
    b = Math.sqrt(c * c - a * a),
    yOffset = -b / 2; // The vertical offset (if 0, triangle is on x axis)
  path.moveTo(0, b + yOffset);
  path.lineTo(-a, 0 + yOffset);
  path.lineTo(a, 0 + yOffset);
  path.lineTo(0, b + yOffset);

  // Draw the cut out triangle using the points from above
  var height = 1;
  var shapes = path.toShapes();
  var solid = new THREE.ExtrudeGeometry(shapes, {
    amount: height,
    bevelEnabled: false
  });
  var maskMaterial = new THREE.MeshBasicMaterial({
    color: 0x24132E,
    side: THREE.FrontSide
  });
  var plane = new THREE.Mesh(solid, maskMaterial);
  // Place it on top of the tunnel
  plane.renderOrder = 1;
  plane.material.depthTest = false;
  scene.add(plane);

  // Draw the red lines surrounding the triangle
  var geo = new THREE.Geometry();
  geo.vertices.push(
    new THREE.Vector3(0, b + yOffset, 0),
    new THREE.Vector3(-a, 0 + yOffset, 0),
    new THREE.Vector3(a, 0 + yOffset, 0),
    new THREE.Vector3(0, b + yOffset, 0)
  );

  var lineMaterial = new THREE.LineBasicMaterial({
    color: 0xff0000,
    linewidth: 1,
    linejoin: "miter"
  });

  plane = new THREE.Line(geo, lineMaterial);
  // Place it on top of the mask
  plane.renderOrder = 2;
  overlayScene.add(plane);
}

// animation loop
function animate() {

  // loop on request animation loop
  // - it has to be at the begining of the function
  // - see details at http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
  requestAnimationFrame(animate);

  // do the render
  render();

  // update stats
  stats.update();
}

// render the scene
function render() {
  // Make sure the texture has loaded because the new way of loading isn't blocking
  if (texture != null) {

    // move the texture to give the illusion of moving thru the tunnel
    texture.offset.y -= 0.01;
    texture.offset.y %= 1;

    // move the camera back and forth
    // var seconds		= Date.now() / 1000;
    // var radius		= 0.70;
    // var angle		= Math.sin(0.75 * seconds * Math.PI) / 4;
    // mesh.rotation.y	= angle;

  } else
    console.log("Texture hasn't loaded yet");

  // actually render the scene
  renderer.clear();
  renderer.render(scene, camera);
  renderer.clearDepth();
  renderer.render(overlayScene, camera);

  // Shift our red text
  scaleText();
}

function createRedShift() {
  redShift = document.createElement("div");
  redShift.innerText = header.innerText;
  redShift.className = "redShift";
  header.appendChild(redShift);
}

function scaleText() {
  var max = 1.02,
    min = 0.95,
    randomDec = Math.random() * (max - min) + min;
  redShift.style.webkitTransform = "scaleX(" + randomDec + ")";
  redShift.style.transform = "scaleX(" + randomDec + ")";
}
              
            
!
999px

Console