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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div id="app"></div>
              
            
!

CSS

              
                body {
  background: white;
}

#app {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                let app
let mainContainer
let textureContainer
let images = {}
let autoPlaySpeed = [3, 3]
//let displaceScale = [200, 70]
let displacementMap = 'https://demo.blab.studio/codepen/crystalize.jpg'
let displacementFilter
let textures = {
  1 : 'https://demo.blab.studio/codepen/boba.jpg'
}

app = new PIXI.Application()
app.renderer = PIXI.autoDetectRenderer({
  width: window.innerWidth, 
  height: window.innerHeight,
  resolution: window.devicePixelRatio,
  transparent: true,
  autoResize: true,
  antialias: false,
 })

app.view.id = 'pixi-canvas'
document.getElementById("app").appendChild(app.view)
mainContainer = new PIXI.Container()
app.stage.addChild(mainContainer)
textureContainer = new PIXI.Container()
mainContainer.addChild(textureContainer)

//add stuff to the loadig queue
app.loader.add('map', displacementMap)
Object.keys(textures).forEach((key) => {
  console.log(key, textures[key])
  app.loader.add(key, textures[key]);
})

//loading the assets
app.loader.load((loader, resources) => {
  console.log("loaded", resources)
  setTextures(resources)
  setDisplacementMap(resources)
  
  // Listen for animate update
  //app.ticker.add((delta) => {
  //  if (displacementSprite != null) {
      //TweenMax.set( displacementSprite, { pixi: { x:   displacementSprite.x += autoPlaySpeed[0] * delta, y: displacementSprite.y += autoPlaySpeed[1] * delta }})
   // }
	 // app.renderer.render( app.stage );
  //})
 })

//animate stuff
//animate()

//mouse movement
mouseMove()

setTimeout(() => {
  document.removeEventListener("mousemove", () => {})
  app.destroy()
}, 4000)


function animate() {
  // start the timer for the next animation loop
  requestAnimationFrame(animate)
  app.render(app.stage)
}

function mouseMove() {
  const canvas = document.getElementById("app")
  let timeout = null
  let timestamp = null
  let lastMouse = { x: 0, y: 0 }

  document.addEventListener("mousemove", (e) => {
    clearTimeout(timeout)
    
    if (timestamp === null) {
		  timestamp = Date.now()
			lastMouse.x = e.screenX
			lastMouse.y = e.screenY
			return
	  } 

		 	  let now = Date.now()
		 	  let dt =  now - timestamp
		 	  let dx = e.screenX - lastMouse.x
		 	  let dy = e.screenY - lastMouse.y
		 	  let speedX = Math.abs(Math.round(dx / dt * 100))*0.1
		 	  let speedY = Math.abs(Math.round(dy / dt * 100))*0.5

        /* if (speedX <= 50) {
          speedX = 50
        }
        if (speedX >= 400) {
          speedX = 400
        }
        if (speedY <= 50) {
          speedY = 50
        }
        if (speedY >= 400) {
          speedY = 400
        } */
    
        speedX = 50
        speedY = 50

        timestamp = now
        lastMouse.x = e.screenX
        lastMouse.y = e.screenY
        if (displacementFilter) {
          console.log(speedX, speedY)
          TweenMax.to(displacementFilter, 1, { pixi: { scaleX: speedX, scaleY: speedY }, ease: Sine.easeOut})
        }
				//console.log("mouse move over", speedX, speedY)

        //RESET after 1s
        timeout = setTimeout(() => {
          if (displacementFilter) {
  				 	TweenMax.to(displacementFilter, 1.5, { pixi: { scaleX: 0, scaleY: 0 }, ease: Back.easeOut });
          }
        }, 500);
        
        //mouse sprite following the mouse
        //console.log("mouse pos", e, e.clientX, e.clientY)
        TweenMax.to(textureContainer, 1,{ pixi: { x: e.clientX, y: e.clientY }, ease: Sine.easeOut})
      })
      
    }

function setTextures(resources) {

      let appRatio = app.screen.width/app.screen.height
      textureContainer.alpha = 1
      let i = 0

      let texturesLoaded = new Promise((resolve, reject) => {
        Object.keys(resources).forEach((key) => {
          console.log(key, typeof key, parseInt(key))
          key = parseInt(key)
          if (key > 0) {
            images[key] = new PIXI.Sprite(resources[key].texture)
            images[key].ratio = images[key].width/images[key].height
            textureContainer.addChild( images[key] );
            console.log("screen", app.screen.width, app.screen.height)
            console.log(appRatio, images[key].ratio, window.devicePixelRatio)
            
              TweenMax.set(images[key], { 
                width: app.screen.width, 
                height: app.screen.width/images[key].ratio, 
                pixi: {
                  alpha: 1,
                  anchor: 0.5,
                  x: app.screen.width/2,
                  y: (app.screen.width/images[key].ratio)/2
              }})
           
            i++
          }
          if (i >= Object.keys(resources).length-1) {
            resolve()
          }
        })
      })

      texturesLoaded.then(() => {
          
          // desktop
          TweenMax.set(textureContainer, { pixi: {
            alpha: 1,
            scale: 0.5,
            pivotX: textureContainer.width/2,
            pivotY: textureContainer.height/2
          }})

        //set the current texture
        setTimeout(() => {
          TweenMax.to(textureContainer, 0.7, { pixi: { alpha: 1, ease: Sine.easeOut }})
        }, 500)
      })    
}

function setDisplacementMap(resources) {
      //distortion basic
      displacementSprite  = new PIXI.Sprite( resources.map.texture  )
      mainContainer.addChild(displacementSprite)
      displacementFilter  = new PIXI.filters.DisplacementFilter( displacementSprite )
      displacementFilter.resolution = window.devicePixelRatio
      displacementSprite.texture.baseTexture.wrapMode = PIXI.WRAP_MODES.REPEAT
      displacementFilter.padding = 100
    
      TweenMax.set(displacementSprite, { pixi: {
        anchor: 0.5,
        scale: 0.75,
        x: app.screen.width/2,
        y: app.screen.height/2
      }})
    
      //initial tween
      TweenMax.fromTo(displacementFilter, 2, { pixi: { scaleX: 50, scaleY: 50 }}, { pixi: { scaleX: 0, scaleY: 0 }, ease: Sine.easeOut })
            
      //mainContainer.filters = [displacementFilter]
  }
    
              
            
!
999px

Console