Created
May 6, 2021 05:11
-
-
Save basith374/8de1425091b39f4e9a9c17cb7555da0e to your computer and use it in GitHub Desktop.
water effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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