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

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

              
                <script id="fs" type="x-shader/x-fragment">
  precision lowp float;
  
  varying vec2 vTextureCoord;
  uniform sampler2D uSampler;
  uniform float uTime;
  uniform float uAspect;
  uniform float uRandom;
  
  float rand (vec2 co) {
    return fract(sin(dot(co, vec2(uRandom, uRandom))) * pow(uRandom, 3.0));
  }

  void main (void) {
    vec4 coord = gl_FragCoord;
    float angle = 3.0;
    float split = 15.0;
    float speed = 0.1;
    float span = distance(coord.x, coord.y / angle) / split;
    float power = rand(vec2(floor(span))) + 1.0;
    float offset = pow(power, 2.0) * uTime * speed;
    float x = vTextureCoord.x + offset / angle * uAspect;
    float y = vTextureCoord.y - offset;
    gl_FragColor = texture2D(uSampler, vec2(x, y));
  }
</script>


              
            
!

CSS

              
                body {
  position: relative;
  overflow: hidden;
  background: #fff;
}

              
            
!

JS

              
                // variables
const width = window.innerWidth
const height = window.innerHeight
const imageSize = {
  width: width - 200,
  height: height - 200
}

// setup
const app = new PIXI.Application({
  transparent: true,
  resizeTo: window,
})
document.body.appendChild(app.view)

// filter
PIXI.filters.MyFilter = class extends PIXI.Filter {
  constructor() {
    const fragmentSrc = document.querySelector('#fs').textContent

    super(
      null, // vertex shader
      fragmentSrc, // fragment shader
      {
        uTime: 0.0,
        uAspect: height / width,
        uRandom: Math.random() * 100,
      }
    )
  }
}

// container
const container = new PIXI.Container()
app.stage.addChild(container)

// rectangle
const background = new PIXI.Graphics()
  .beginFill(0xffffff)
  .drawRect(0, 0, width, height)
  .endFill()
container.addChild(background)

// image
const image = PIXI.Sprite.from('https://picsum.photos/' + imageSize.width + '/' + imageSize.height)
image.x = 100
image.y = 100
container.addChild(image)

// filter setup
const filter = new PIXI.filters.MyFilter()
container.filters = [filter]

// animation
let move = 0

// scroll event
// window.addEventListener('wheel', event => {
//   move -= event.deltaY / 1000
//   if (move > 10) move = -10
//   else if (move < -10) move = 10
//   filter.uniforms.uTime = move
// })

// or

// auto animation
const timeline = gsap.timeline({repeat: -1})
gsap.set(filter.uniforms, {
  uTime: 20
})
timeline.to(filter.uniforms, {
  uTime: 0,
  duration: 2,
  ease: 'power3.out'
})
timeline.to(filter.uniforms, {
  uTime: -20,
  duration: 2,
  ease: 'power3.in'
})
              
            
!
999px

Console