123

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.

            
              <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/99/three.min.js"></script>
<!--script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script-->
<script>
  var lineVertShader = `
  #define dig0 !(digit != -1.0 && digit != 1.0 && digit != 4.0)
  #define dig1 !(digit != -1.0 && digit != 1.0 && digit != 2.0 && digit != 3.0 && digit != 7.0)
  #define dig2 !(digit != -1.0 && digit != 5.0 && digit != 6.0)
  #define dig3 !(digit != -1.0 && digit != 0.0 && digit != 1.0 && digit != 7.0)
  #define dig4 !(digit != -1.0 && digit != 1.0 && digit != 3.0 && digit != 4.0 && digit != 5.0 && digit != 7.0 && digit != 9.0)
  #define dig5 !(digit != -1.0 && digit != 2.0)
  #define dig6 !(digit != -1.0 && digit != 1.0 && digit != 4.0 && digit != 7.0)
  #define cond(a) if(int(idx + 0.1) == (a) && 
  #define retVal ){return 1.0;}
  
  uniform float digit;
  attribute float idx;
  varying float vOff;
  varying vec2 vUv;
  
  float isOff(){
    cond(0) dig0 retVal
    else cond(1) dig1 retVal
    else cond(2) dig2 retVal
    else cond(3) dig3 retVal
    else cond(4) dig4 retVal
    else cond(5) dig5 retVal
    else cond(6) dig6 retVal
    
    //return 1.0;
  }

  void main() {
    vOff = isOff();
    vUv = uv;
    vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
    gl_Position = projectionMatrix * mvPosition;
  }
  `;

  var lineFragShader = `
  uniform vec3 diffuse1;
  uniform vec3 diffuse2;
  varying float vOff;
  varying vec2 vUv;
  
  void main() {
    
    if (vOff > 0.5) discard;
    
    gl_FragColor = vec4( mix(diffuse1, diffuse2, vUv.y), 1.0 );
  }
  `;

</script>

<!--https://developers.google.com/youtube/iframe_api_reference?hl=ru#Loading_a_Video_Player-->
<div id="player"></div>

<script src="https://www.youtube.com/iframe_api"></script>
<script>
  var player;

  function onYouTubePlayerAPIReady() {
    console.log("!");
    player = new YT.Player('player', {
      height: Math.floor(window.innerHeight / 4),
      width: Math.floor(window.innerWidth / 3),
      videoId: 'EAYfJckSEN0',
      events: {
        'onReady': onPlayerReady
      }

    });

    function onPlayerReady(event) {
      event.target.playVideo();
    }

  }

</script>
            
          
!
            
              html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}
canvas {
  width: 100%;
  height: 100%;
  display; block;
}
#player {
  position: absolute;
  bottom: 0;
  right: 0;
}

            
          
!
            
              var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, 1, 0.1, 1000);
var pos = new THREE.Vector3(0, 0.5, 7);
//camera.position.set(0, 0.5, 7);
var renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setClearColor(0x050005);
renderer.setPixelRatio(0.5);
var canvas = renderer.domElement
document.body.appendChild(canvas);


//var controls = new THREE.OrbitControls(camera, canvas);

// GRID
var division = 20;
var limit = 10;
var grid = new THREE.GridHelper(limit * 2, division, 0x001060, 0x001060);

var moveable = [];
for (let i = 0; i <= division; i++) {
  moveable.push(1, 1, 0, 0); // move horizontal lines only (1 - point is moveable)
}
grid.geometry.addAttribute(
  "moveable",
  new THREE.BufferAttribute(new Uint8Array(moveable), 1)
);
grid.material = new THREE.ShaderMaterial({
  uniforms: {
    time: {
      value: 0
    },
    limits: {
      value: new THREE.Vector2(-limit, limit)
    },
    speed: {
      value: 5
    }
  },
  vertexShader: `
    uniform float time;
    uniform vec2 limits;
    uniform float speed;
    
    attribute float moveable;
    
    varying vec3 vColor;
  
    void main() {
      vColor = color;
      float limLen = limits.y - limits.x;
      vec3 pos = position;
      if (floor(moveable + 0.5) > 0.5){ // if a point has "moveable" attribute = 1 
        float dist = speed * time;
        float currPos = mod((pos.z + dist) - limits.x, limLen) + limits.x;
        pos.z = currPos;
      } 
      gl_Position = projectionMatrix * modelViewMatrix * vec4(pos,1.0);
    }
  `,
  fragmentShader: `
    varying vec3 vColor;
  
    void main() {
      gl_FragColor = vec4(vColor, 1.);
    }
  `,
  vertexColors: THREE.VertexColors
});
scene.add(grid);

// CLOCK
var points = [
  new THREE.Vector2(0.1, 2),
  new THREE.Vector2(0.9, 2),
  
  new THREE.Vector2(0, 1.9),
  new THREE.Vector2(0, 1.1),
  
  new THREE.Vector2(1, 1.9),
  new THREE.Vector2(1, 1.1),
  
  new THREE.Vector2(0.1, 1),
  new THREE.Vector2(0.9, 1),
  
  new THREE.Vector2(0, 0.9),
  new THREE.Vector2(0, 0.1),
  
  new THREE.Vector2(1, 0.9),
  new THREE.Vector2(1, 0.1),
  
  new THREE.Vector2(0.1, 0),
  new THREE.Vector2(0.9, 0)
];
var idx = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6];
var uvs = [0.1, 0, 0.9, 0,  0, 0.05, 0, 0.45,  1, 0.05, 1, 0.45,  0.1, 0.5, 0.9, 0.5,  0, 0.55, 0, 0.95,  1, 0.55, 1, 0.95,  0.1, 1, 0.9, 1];

//console.log(new THREE.BoxBufferGeometry());

var geometry = new THREE.BufferGeometry().setFromPoints(points);
geometry.addAttribute('idx', new THREE.BufferAttribute(new Float32Array(idx), 1));
geometry.addAttribute('uv', new THREE.BufferAttribute(new Float32Array(uvs), 2));
geometry.center();
var matrix = new THREE.Matrix4().makeShear(0, THREE.Math.degToRad(3), 0);
geometry.applyMatrix(matrix);
geometry.translate(0, 1.1, 0);

var digits = [];

function createDigit( position ) {

  let material = new THREE.ShaderMaterial({
    uniforms: {
      diffuse1: {
        value: new THREE.Color(0xff00ff)
      },
      diffuse2: {
        value: new THREE.Color(0xff3000)
      },
      digit: {
        value: 0
      }
    },
    vertexShader: lineVertShader,
    fragmentShader: lineFragShader
  });

  let digit = new THREE.LineSegments(geometry, material);
  digit.position.copy(position);
  digit.scale.setScalar(0.9);
  
  digits.push(digit);
  
  scene.add(digit);
}

var dots;
function createDots(){
  let geom = new THREE.BufferGeometry().setFromPoints([
    new THREE.Vector2(-1.55, 1.45),
    new THREE.Vector2(-1.55, 1.35),
    new THREE.Vector2(-1.55, 0.65),
    new THREE.Vector2(-1.55, 0.55),
    new THREE.Vector2(1.55, 1.45),
    new THREE.Vector2(1.55, 1.35),
    new THREE.Vector2(1.55, 0.65),
    new THREE.Vector2(1.55, 0.55)
  ]);
  geom.setIndex([0, 1, 2, 3, 4, 5, 6, 7]);
  geom.applyMatrix(matrix);
  let mat = new THREE.LineBasicMaterial({color: 0xff0000});
  dots = new THREE.LineSegments(geom, mat);
  scene.add(dots);
}

// hours
createDigit( new THREE.Vector3(-3.6, 0, 0) );
createDigit( new THREE.Vector3(-2.5, 0, 0) );
// minutes
createDigit( new THREE.Vector3(-0.55, 0, 0) );
createDigit( new THREE.Vector3( 0.55, 0, 0) );
//seconts
createDigit( new THREE.Vector3( 2.5, 0, 0) );
createDigit( new THREE.Vector3( 3.6, 0, 0) );

createDots();

var clock = new THREE.Clock();
var date = 0;

var hours = 0, minutes = 0, seconds = 0;



render();

function render() {
  if (resize(renderer)) {
    camera.aspect = canvas.clientWidth / canvas.clientHeight;
    camera.updateProjectionMatrix();
  }
  
  camera.position.set(
    Math.cos(clock.getElapsedTime() * 0.25),
    Math.sin(clock.getElapsedTime() * 0.314)*0.25,
    0
  ).add(pos);
  camera.lookAt(scene.position);
  
  grid.material.uniforms.time.value = clock.getElapsedTime() * 0.5;
  
  date = new Date();
  hours = date.getHours();
  minutes = date.getMinutes();
  seconds = date.getSeconds();
  digits[0].material.uniforms.digit.value = Math.floor(hours / 10) == 0 ? -1 : Math.floor(hours / 10);
  digits[1].material.uniforms.digit.value = hours % 10;
  digits[2].material.uniforms.digit.value = Math.floor(minutes / 10);
  digits[3].material.uniforms.digit.value = minutes % 10;
  digits[4].material.uniforms.digit.value = Math.floor(seconds / 10);
  digits[5].material.uniforms.digit.value = seconds % 10;
  
  dots.visible = seconds % 2 == 0;
  
  renderer.render(scene, camera);
  requestAnimationFrame(render);
}

function resize(renderer) {
  const canvas = renderer.domElement;
  const width = canvas.clientWidth;
  const height = canvas.clientHeight;
  const needResize = canvas.width !== width || canvas.height !== height;
  if (needResize) {
    renderer.setSize(width, height, false);
  }
  return needResize;
}
            
          
!
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