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

              
                <!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>[three.js]emitRectangle</title>
  <link rel="stylesheet" href="./style.css">
</head>
<body>
<!-- partial:index.partial.html -->
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/89/three.min.js"></script>
<!-- OrbitControls.js -->
<script src="https://dl.dropbox.com/s/wsnza5pvz8iq46j/OrbitControls.js?dl=0r"></script>
</head>
<body>
  <canvas id="myCanvas"></canvas>
  <script id="fragmentShader" type="x-shader/x-fragment">
    uniform float time;
    uniform sampler2D colorTexture;
    varying vec2 vUv;
    void main( void ) {
      vec2 uv =  vUv;
      // uv.x += abs(cos(time)*0.2+cos(time)*0.05);
      // uv.y += sin(time)*0.5;
      vec4 color = texture2D( colorTexture, uv/1.0);
      gl_FragColor = vec4( color );
    }
  </script>

  <script id="vertexShader" type="x-shader/x-vertex">
    varying vec2 vUv;
    void main()
    {
      vUv = uv;
      vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
      gl_Position = projectionMatrix * mvPosition;
    }
  </script>

</body>
<!-- partial -->
  <script  src="./script.js"></script>

</body>
</html>

              
            
!

CSS

              
                  *{
    margin: 0;
  }
  canvas {
    display: block;
    width: 100%;
    height: 100%;
    margin: auto;
    position: fixed;
    overflow: hidden;
  }
              
            
!

JS

              
                    window.addEventListener('load', init);
    let uniforms;
    let clock, controls;
    function init() {
      let count = 0;
      let mesh;
      let meshList = [];

      clock = new THREE.Clock();

      const renderer = new THREE.WebGLRenderer({
        antialias: true,
        canvas: document.querySelector('#myCanvas'),
      });
      renderer.setPixelRatio(window.devicePixelRatio);
      renderer.setSize(window.innerWidth , window.innerHeight);
      renderer.shadowMap.enabled = true; //影を入れる
      renderer.shadowMap.type = THREE.PCFSoftShadowMap;

      const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 4000);
      camera.position.set(0, 0, 1500);
      camera.lookAt(new THREE.Vector3(0, 0, 0));

      controls = new THREE.OrbitControls(camera);
      controls.autoRotate = true;

      const scene = new THREE.Scene();
      scene.background = new THREE.Color( 0xffffff );
      scene.fog = new THREE.Fog( 0x000000, 50, 200 );


      window.addEventListener( 'resize', function(){
        onWindowResize(camera, renderer);
      }, false );

      uniforms = {
        "time": { value: 1.0 },
        "colorTexture": { value: new THREE.TextureLoader().load( 'https://dl.dropbox.com/s/5g5hy4xbxvifnb3/bg.jpg?dl=0' ) },
      };
      uniforms[ "colorTexture" ].value.wrapS = uniforms[ "colorTexture" ].value.wrapT = THREE.RepeatWrapping;

      tick();
      function tick() {
        renderer.render(scene, camera);
        if (count % 2 == 0) {
          mesh = new MyGroup();
          scene.add(mesh);
          meshList.push(mesh);
        }else{}

        for (var i = 0; i < meshList.length; i++) {
          meshList[i].update();
        }

        // controls.update();
        requestAnimationFrame(tick);
        controls.update();
        count = count + 1;
      }
    }

    class MyGroup extends THREE.Object3D {
      constructor() {
        super();
        this.barList = [];
        this.gravity = 1.02;
        this.vy = 0;


        for (let i = 0; i < 1; i++) {
          var rand = Math.floor(getRandom(2,10)*20);
          this.bar = new THREE.Mesh(
            new THREE.BoxBufferGeometry(rand,rand,rand ),
            new THREE.ShaderMaterial( {
    					uniforms: uniforms,
    					vertexShader: document.getElementById( 'vertexShader' ).textContent,
    					fragmentShader: document.getElementById( 'fragmentShader' ).textContent
				    } )
          );
          // this.bar.castShadow = true;

          const radian = i / length * Math.PI * 2;
          this.bar.position.set(
            getRandom(-window.innerWidth, window.innerWidth), // X座標
            -2000, // Y座標
            getRandom(-window.innerWidth, window.innerWidth)// Z座標
          );

          this.bar.rotation.x = Math.PI/2*Math.floor(getRandom(0,4));
          this.bar.rotation.y = Math.PI/2*Math.floor(getRandom(0,4));
          this.bar.rotation.z = Math.PI/2*Math.floor(getRandom(0,4));

          this.bar.vy =  this.vy * (Math.random() - 0.5);
          this.add(this.bar);
          this.barList.push(this.bar);
        }
      }

      update() {
        for (let i = 0; i < this.barList.length; i++) {
          this.barList[i].vy += 1;
          this.barList[i].vy *= this.gravity;
          this.barList[i].position.y += this.barList[i].vy;

          // this.barList[i].rotation.y += .1;

          //y座標一定値まですぎたら削除
          if (this.barList[i].position.y > 0) {
            this.barList[i].vy /= 1.5;
          }
          if (this.barList[i].position.y > 2000) {
            this.remove(this.barList[i]);
            this.barList.splice(i, 1);
          }
        }
        var delta = clock.getDelta();
        uniforms[ "time" ].value += delta * 1;
      }
    }

    function onWindowResize(camera, renderer) {
      camera.aspect = window.innerWidth / window.innerHeight;
      camera.updateProjectionMatrix();

      renderer.setSize( window.innerWidth, window.innerHeight );
    }

    function getRandom(min, max) {
      return Math.random() * (max - min) + min;
    }

    function getRandom(min, max) {
      return Math.random() * (max - min) + min;
    }

              
            
!
999px

Console