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

              
                    <div class="images">
      <div class="img _one"></div>
      <div class="img _two"></div>
      <div class="img _three"></div>
    </div>    
<div id="webgl"></div>
              
            
!

CSS

              
                * {
  overflow:hidden;
}
      .img {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 0;
        height: 400px;
      }
      ._one {
        background: url(https://images.unsplash.com/photo-1563306206-900cc99112fc?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=765&q=80) center no-repeat;
        background-size: 700px;
      }
              
            
!

JS

              
                window.addEventListener("DOMContentLoaded", () => {
  const app = new App();

  app.init();
  app.render();
  window.addEventListener("resize", () => {
    app.onResize();
  });
});

class App {
  //レンダラーセッティング
  static get RENDERER_SETTING() {
    return {
      clearColor: 0xffffff,
      width: window.innerWidth,
      height: window.innerHeight,
    };
  }

  //マテリアルセッティング
  static get MATERIAL_SETTING() {
    return {
      color: 0xffffff,
    };
  }

  //コンストラクタ
  constructor() {
    this.renderer;
    this.scene;
    this.camera;
    this.geometory;
    this.material;
    this.curve;

    this.width = window.innerWidth;
    this.height = window.innerHeight;

    this.render = this.render.bind(this);
  }

  _setRenderer() {
    this.renderer = new THREE.WebGLRenderer();
    this.renderer.setClearColor(new THREE.Color(App.RENDERER_SETTING.clearColor));
    this.renderer.setSize(App.RENDERER_SETTING.width, App.RENDERER_SETTING.height);
    const canvas = document.querySelector("#webgl");
    canvas.appendChild(this.renderer.domElement);
  }

  _setScene() {
    this.scene = new THREE.Scene();
  }

  _setCamera() {
    this.camera = new THREE.PerspectiveCamera((2 * Math.atan(this.height / 2 / 100) * 180) / Math.PI, this.width / this.height, 1, 1000);
    this.camera.position.set(0, 0, 100);
    this.camera.updateProjectionMatrix();
  }

  _setMesh() {
    this.geometory = new THREE.PlaneBufferGeometry(this.width, this.height, 100, 100);
    this.material = new THREE.ShaderMaterial({
      vertexShader: `
      varying vec2 vUv;
      uniform vec2 uResolution;

      void main() {
        vUv = uv;
        gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
      }
      
      `,
      fragmentShader: `
      varying vec2 vUv;
      uniform float motion;
      float PI = 3.141529;

      void main() {
        vec2 newUV = vUv;
        float bottom = abs(1.0 - motion);
        float curveStrength = 0.8;
        float waveStrength = 1.0;
        float curve = motion + (sin(newUV.y * PI * waveStrength) * motion - motion) * bottom * curveStrength;
        float color = step(curve,newUV.x);
        gl_FragColor = vec4(color,color,color,1.0);
      }
      `,
      transparent: true,
      uniforms: {
        motion: {
          value: 0.0,
        },
      },
    });
    this.curve = new THREE.Mesh(this.geometory, this.material);
    this.scene.add(this.curve);
  }

  //初期化処理
  init() {
    this._setRenderer();
    this._setScene();
    this._setCamera();
    this._setMesh();

    const tl = gsap.timeline();
    const imgElement = document.querySelector(".img");
    tl.to(this.material.uniforms.motion, {
      value: 1,
      duration: 1,
    })
      .to(
        imgElement,
        {
          width: '500px',
          duration: 0.8,
        },
        "<0.9"
      )
  }

  //描画処理
  render() {
    requestAnimationFrame(this.render);
    this.renderer.render(this.scene, this.camera);
  }
  //リサイズ処理
  onResize() {
    this.width = window.innerWidth;
    this.height = window.innerHeight;
    this.camera.aspect = window.innerWidth / window.innerHeight;
    this.renderer.setSize(window.innerWidth, window.innerHeight);
    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
    this.camera.updateProjectionMatrix();
  }
}

              
            
!
999px

Console