1.0.13 • Published 4 years ago

react-webgl-noiseeffect v1.0.13

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

Description:

This is a noise effect inspired from Kenji Saito: https://codepen.io/kenjiSpecial/pen/wavooR

Reduced vertices for smaller icons to prevent to be choppy when presented with a number of elements.

Made it easier to be customized.

Wrapped it into a React component.

Allow multiple icons.

Demo:

https://xmluozp.github.io/react-webgl-noiseeffect/

Preconditions:

Images array is required.

Your picture's background has to be pure black or transparent (Black will be treated as transparent, other colors will be read as vertices). Pixel pictures perform best.

Installation:

npm i react-webgl-noiseeffect

Usage:

  1. Import

  2. Create an Array of your images

  3. Create a component, pass array in:

import NoiseEffect from 'react-webgl-noiseeffect';

//...
  const images = [
    { src: "images/01.png", width: 128, height: 128 },
    { src: "images/02.png", width: 128, height: 128 },
    { src: "images/03.png", width: 128, height: 128 },
  ]
//...
    <NoiseEffect images={images} />

Example:

import React, { useState } from 'react';
import './App.css';
import NoiseEffect from 'react-webgl-noiseeffect';

function App() {

  const [imageIndex, setImageIndex] = useState(0)
  const [display, setDisplay] = useState(true)

  const images = [
    { src: "images/01.png", width: 128, height: 128 },
    { src: "images/02.png", width: 128, height: 128 },
    { src: "images/03.png", width: 128, height: 128 },
  ]

  return (
    <div>
        <NoiseEffect
            id="c"
            images={images}
            index={imageIndex}
            color="#A0B0FF"
            display={display}
            density={0.6}
            speed={0.5}
            blur={blur}
            onLoad={() => { console.log("loaded") }}
        />

        <div>
            <button onClick={() => { setImageIndex(0) }}>switch to 0</button>
            <button onClick={() => { setImageIndex(1) }}>switch to 1</button>
            <button onClick={() => { setImageIndex(2) }}>switch to 2</button>
            <button onClick={() => { setDisplay(false) }}>Fade Out</button>
            <button onClick={() => { setDisplay(true) }}>Fade In</button>
            <button onClick={() => { setBlur(3) }}>Blur(3)</button>
            <button onClick={() => { setBlur(1) }}>Blur(1)</button>
            <button onClick={() => { setBlur(0.5) }}>Blur(0.5)</button>

        </div>
    </div>
  );
}

export default App;

Customize:

PropsTypeDefaultDesc
imagesArray[]{src:string, width: int, height: int}
idString"canvas_noiseeffect"id of Canvas, in case of multiple effects
indexInteger0Index of current displaying image
colorString"#FFFFFF"
isColorfulBooleanfalseIf show original color, eats memory
displayBooleantrue
densityFloat0.5
speedFloat1How fast of switching image
blurFloat1How crazy are those points flying
onLoadFunctionnullA Call back when the Canvas ready
1.0.13

4 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago