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://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script>
  function createWeb(radius, radialSegments, circleSegments, linkingLevel, lastCircle, circleInaccuracy, angleInaccuracy){
    // points
    let vertices = [];
    let indices = [];
    let uv = [];
    let interpolation = [];
    
    vertices.push(new THREE.Vector3());
    uv.push(0.5, 0.5);
    interpolation.push(0);
    
    let base = new THREE.Vector3(1, 0, 0);
    let axis = new THREE.Vector3(0, 0, 1);
    let radiusStep = radius / circleSegments;
    let angleStep = Math.PI * 2 / radialSegments;
    
    let startIndex = 1;
    
    let circleInaccuracyValue = radiusStep * 0.5;
    let angleInaccuracyValue = angleStep * 0.33;
    let angleInaccuracies = [];
    for (let z = 0; z < radialSegments; z++){
      angleInaccuracies.push(THREE.Math.randFloat(-1, 1) * angleInaccuracyValue * angleInaccuracy);
    }
    
    for (let i = 1; i <= circleSegments; i++){
      for (let j = 0; j < radialSegments; j++){
        
        let rI = radiusStep * i + (THREE.Math.randFloat(-1, 1) * circleInaccuracyValue * circleInaccuracy);
        let aI = angleStep * j + angleInaccuracies[j];
        
        let v = new THREE.Vector3().copy(base).multiplyScalar(rI).applyAxisAngle(axis, aI);
        vertices.push(v);
        
        let uvX = (v.x - (-radius)) / (radius * 2);
        let uvY = (v.y - (-radius)) / (radius * 2);
        uv.push(uvX, uvY);
        let interp = v.length() / radius;
        interpolation.push(interp);
        
        let idx = j + startIndex;
        // link circles
        indices.push(idx, i === 1 ? 0 : idx - radialSegments);
        // link radialSegments
        if (!lastCircle && i === circleSegments) continue;
        if (Math.random() <= linkingLevel){
          indices.push(idx, j === radialSegments - 1 ? startIndex : idx + 1);
        }
      }
      startIndex += radialSegments;
    }
    
    let g = new THREE.BufferGeometry().setFromPoints(vertices);
    g.addAttribute("uv", new THREE.Float32BufferAttribute(uv, 2));
    g.addAttribute("interpolation", new THREE.Float32BufferAttribute(interpolation, 1));
    g.setIndex(indices);
    console.log(g)
    return g;
    
    
  }
</script>
            
          
!
            
              html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}
canvas {
  width: 100%;
  height: 100%;
  display; block;
}
            
          
!
            
              var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, 1, 1, 1000);
camera.position.set(0, 0, 13);
var renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setClearColor(0x404040);
var canvas = renderer.domElement
document.body.appendChild(canvas);

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

var webGeom = createWeb(6.66, 13, 66, 0.875, false, 1, 1);
var webMat = new THREE.ShaderMaterial({
  uniforms: {
    map: {value: new THREE.TextureLoader().load("https://cywarr.github.io/small-shop/CrossSpider.jpg")}
  },
  vertexShader: `
    varying vec2 vUv;
    void main() {
      vUv = uv;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
    }
  `,
  fragmentShader:`
    uniform sampler2D map;
    varying vec2 vUv;
    void main() {
      gl_FragColor = texture2D(map, vUv);
    }
  `
});
var web = new THREE.LineSegments(webGeom, webMat);
scene.add(web);




render();

function render() {
  if (resize(renderer)) {
    camera.aspect = canvas.clientWidth / canvas.clientHeight;
    camera.updateProjectionMatrix();
  }
  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