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

              
                
              
            
!

CSS

              
                body {
  overflow: hidden;
  margin: 0;
}
              
            
!

JS

              
                console.clear();
import * as THREE from "https://threejs.org/build/three.module.js";
import { OrbitControls } from "https://threejs.org/examples/jsm/controls/OrbitControls.js";

let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera(60, innerWidth / innerHeight, 0.1, 1000);
camera.position.setScalar(6);
let renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(innerWidth, innerHeight);
renderer.setClearColor(0x202020);
document.body.appendChild(renderer.domElement);

let controls = new OrbitControls(camera, renderer.domElement);

scene.add(new THREE.GridHelper());

let g = new THREE.PlaneGeometry();
g.translate(0, 0.5, 0);
let m = new THREE.ShaderMaterial({
  vertexShader: `
    attribute float iId;
    varying vec2 vUv;
    varying float viId;
    void main() {
      vUv = uv;
      viId = floor(iId + 0.01);
      gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position,1.0);
    }
  `,
  fragmentShader: `
    #define TWO_PI 3.1415926*2.
    varying vec2 vUv;
    varying float viId;
    float random (vec2 st) {
        return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123);
    }
    vec3 hsb2rgb( in vec3 c ){
        vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0), 6.0)-3.0)-1.0, 0.0, 1.0 );
        rgb = rgb*rgb*(3.0-2.0*rgb);
        return c.z * mix( vec3(1.0), rgb, c.y);
    }
    void main() {
      vec2 uv = vUv - 0.5;
      
      float dist = length(uv);
      vec2 fe = fwidth(uv);
      float e = min(fe.x, fe.y);
      float a = smoothstep(0.5, 0.5 - e, dist);
      
      vec2 gUv = uv * 20.;
      
      vec2 grid = abs(fract(gUv - 0.5) - 0.5) / fwidth(gUv) / 2.;
      float line = min(grid.x, grid.y);
      line = 1. - min(line, 1.0);
      a -= line;
      
      vec2 idx = floor(gUv);
      //idx += floor(viId * 100.);
      float rnd = random(idx);
      //float rnd = (random(idx) + random(vec2(3.14, viId))) *.5;
      vec3 col = hsb2rgb(vec3(rnd * TWO_PI, 1., 1.));
      
      gl_FragColor = vec4(col, a);
    }
  `,
  transparent: true
});
m.extensions = {derivatives: true};

let count = 11;
let dummy = new THREE.Object3D();
let mat4 = new THREE.Matrix4();
let o = new THREE.InstancedMesh(g, m, count);
let ids = [];
for(let i = 0; i < count; i++){
  dummy.position.set(0, 0, ((-5) + i ));
  dummy.scale.setScalar(5);
  dummy.updateMatrix();
  o.setMatrixAt(i, dummy.matrix);
  ids.push(i);
}
g.setAttribute("iId", new THREE.InstancedBufferAttribute(new Float32Array(ids), 1));
scene.add(o);

let clock = new THREE.Clock();

renderer.setAnimationLoop(() => {
  let t = clock.getElapsedTime();
  let s = Math.sin(t) * 0.5 + 0.5;
  o.getMatrixAt(9, mat4);
  mat4.decompose(dummy.position, dummy.quaternion, dummy.scale);
  dummy.scale.setScalar(s * 5);
  dummy.updateMatrix();
  o.setMatrixAt(9, dummy.matrix);
  o.instanceMatrix.needsUpdate = true;
  renderer.render(scene, camera);
});
              
            
!
999px

Console