Skip to content

Instantly share code, notes, and snippets.

@basith374
Created May 6, 2021 05:11
Show Gist options
  • Save basith374/8de1425091b39f4e9a9c17cb7555da0e to your computer and use it in GitHub Desktop.
Save basith374/8de1425091b39f4e9a9c17cb7555da0e to your computer and use it in GitHub Desktop.
water effect
import React, { useEffect, useRef } from 'react'
import * as PIXI from 'pixi.js'
import texture from 'cloud.jpg'
export default function RippleImage({ src, style }) {
const ref = useRef()
useEffect(() => {
const app = new PIXI.Application({
width: window.innerWidth,
height: window.innerHeight
})
ref.current.appendChild(app.view)
const image = new PIXI.Sprite.from(src)
image.width = window.innerWidth
image.height = window.innerHeight
app.stage.addChild(image)
const displacementSprite = new PIXI.Sprite.from(texture)
const displacementFilter = new PIXI.filters.DisplacementFilter(
displacementSprite
)
displacementSprite.texture.baseTexture.wrapMode = PIXI.WRAP_MODES.REPEAT
app.stage.addChild(displacementSprite)
app.stage.filters = [displacementFilter]
animate()
function animate() {
displacementSprite.x += 10
displacementSprite.y += 4
window.requestAnimationFrame(animate)
}
}, [])
return <div ref={ref} style={style} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment