Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- Made with THREE.Phenomenon: A small wrapper around threejs built for high-performance WebGL experiences. -->

<a href="https://github.com/vaneenige/three.phenomenon" target="_blank">Made with Phenomenon</a>
              
            
!

CSS

              
                html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;

  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
    Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
  letter-spacing: 0;
  font-style: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

canvas {
  position: fixed;
  width: 100%;
  height: 100%;
}

a, span {
  position: fixed;
  margin: 16px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  border-radius: 0;
  cursor: pointer;
  outline: none;
  padding: 8px 20px;
  color: white;
  z-index: 1;
  font-weight: bold;
}

span {
  text-align: center;
  bottom: 16px;
  border: none;
  width: 100%;
  left: 0;
  margin: 0;
  padding: 0;
  color: black;
}
              
            
!

JS

              
                const { renderer, scene, camera, controls } = base();
const { mesh, uniforms } = instance();

const sphere = new THREE.Mesh(
  new THREE.IcosahedronGeometry(1, 2),
  new THREE.MeshStandardMaterial({
    flatShading: false,
    roughness: 0.1,
    metalness: 0.7
  })
);
scene.add(sphere);

const light = new THREE.PointLight("#EFEFEF", 10, 5, Math.PI * 0.25, 1, 2);
scene.add(light);


let colors = [];
for (let i = 0; i < 4; i += 1) {
  colors.push(
    `#${new THREE.Color().setHSL(0.5 + i / 3 * 0.25, 0.6, 0.7).getHexString()}`
  );
}

document.querySelector(
  "a"
).style.background = `linear-gradient(to right, ${colors.join(", ")})`;

scene.add(mesh);

let progress = 0;

uot((p) => {
  progress = p;
}, 3000, Infinity);

function render() {
  requestAnimationFrame(render);
  controls.update();
  
  const radius = 10;
  angle = progress * Math.PI * 2;
  x = radius * Math.cos(angle);
  y = radius * Math.sin(angle);

  sphere.position.setY(y);
  sphere.position.setX(x);
  
  light.position.setY(y);
  light.position.setX(x);
  
  uniforms.uPosition.value[0] = x;
  uniforms.uPosition.value[1] = y;
  
  let p = progress * 2 - 1;
  p = 1 - p * p;
  
  const newColor = new THREE.Color().setHSL(0.5 + p * 0.25, 0.7, 0.4);
  sphere.material.emissive = newColor;
  light.color = newColor;
  
  renderer.render(scene, camera);
}

render();

// === INSTANCE ===

function instance() {
  const geometry = new THREE.TorusGeometry(2.5, 0.5, 12, 24);

  const material = new THREE.MeshStandardMaterial({
    color: "#EFEFEF",
    emissive: "#212121",
    flatShading: true,
    roughness: 0.1,
    metalness: 0.7
  });

  const castShadow = false;

  const S = 30;
  const positions = [];
  const radius = 10;
  for (let i = -S; i < S; i += 1) {
    angle = i / (S / 2) * Math.PI;
    x = radius * Math.cos(angle);
    y = radius * Math.sin(angle);
    positions.push(x, y);
  }

  const multiplier = positions.length / 4;

  const attributes = [
    {
      name: "aPosition",
      data: i => [positions[i * 2], positions[i * 2 + 1], 0],
      size: 3
    },
    {
      name: "aBaseRotation",
      data: (i, total) => [i / total],
      size: 1
    }
  ];

  const uniforms = {
    uPosition: {
      value: [0, 0, 0]
    }
  };

  const vertex = `
    attribute vec3 aPosition;
    uniform vec3 uPosition;
    attribute float aBaseRotation;

    vec4 quatFromAxisAngle(vec3 axis, float angle) {
      float halfAngle = angle * 0.5;
      return vec4(axis.xyz * sin(halfAngle), cos(halfAngle));
    }

    vec3 rotateVector(vec4 q, vec3 v) {
      return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);
    }

    float easeInOutSin(float t){
      return (1.0 + sin(${Math.PI} * t - ${Math.PI} / 2.0)) / 2.0;
    }

    void main(){
      vec4 quatX = quatFromAxisAngle(vec3(1.0, 0.0, 0.0), ${Math.PI / 2});
      vec4 quatZ = quatFromAxisAngle(vec3(0.0, 0.0, 1.0), (aBaseRotation * ${Math.PI * 2}));
      vec3 basePosition = rotateVector(quatZ, rotateVector(quatX, position));

      basePosition *= 1.0 - 0.4 * min(1.0, max(0.0, -3.0 + distance(uPosition, aPosition)));
      gl_Position = aPosition + basePosition;
    }
  `;

  const instance = new THREE.Phenomenon({
    geometry,
    multiplier,
    material,
    castShadow,
    attributes,
    uniforms,
    vertex
  });

  return instance;
}

// === STRUCTURE ===

function base() {
  const renderer = new THREE.WebGLRenderer({
    antialias: true
  });

  renderer.setClearColor(0x212121, 0);
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.setPixelRatio(1);

  document.querySelector("body").appendChild(renderer.domElement);

  const scene = new THREE.Scene();

  const camera = new THREE.PerspectiveCamera(
    40,
    window.innerWidth / window.innerHeight,
    0.1,
    10000
  );
  camera.position.set(0, 20, 35);
  camera.lookAt(scene.position);
  scene.add(camera);

  const ambientLight = new THREE.AmbientLight("#ffffff", 0.1);
  scene.add(ambientLight);

  const emissive = `#${new THREE.Color().setHSL(0.5, 0.7, 0.4).getHexString()}`;

  const box = new THREE.Mesh(
    new THREE.BoxGeometry(440, 440, 440),
    new THREE.MeshPhongMaterial({ emissive: "#212121", side: THREE.BackSide })
  );
  scene.add(box);

  const light = new THREE.SpotLight(0xffffff, 1, 80, Math.PI * 0.25, 1, 2);
  light.position.set(0, 30, 5);

  scene.add(light);

  window.addEventListener(
    "resize",
    () => {
      camera.aspect = window.innerWidth / window.innerHeight;
      camera.updateProjectionMatrix();
      renderer.setSize(window.innerWidth, window.innerHeight);
    },
    false
  );

  const controls = new THREE.OrbitControls(camera);

  return { renderer, scene, camera, controls };
}

function getArrayWithNoise(array, noise) {
  return array.map(item => item + getRandomBetween(noise));
}

function getRandomBetween(value) {
  const floor = -value;
  return floor + Math.random() * value * 2;
}

if (
  navigator.userAgent.match(/(iPod|iPhone|iPad)/) &&
  navigator.userAgent.match(/AppleWebKit/)
) {
  document.body.insertAdjacentHTML("beforeend", `<span>Tap for 60FPS</span>`);
  const span = document.querySelector("span");
  window.addEventListener("touchstart", () => {
    span.outerHTML = "";
  });
}

              
            
!
999px

Console