npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-shader-canvas

v1.0.0

Published

A small utility to render shaders using React

Downloads

20

Readme

react-shader-canvas

A small utility to render shaders using React

NPM JavaScript Style Guide

Install

npm install --save react-shader-canvas

Usage

import React, { Component } from 'react'

import { createShaderCanvas } from 'react-shader-canvas';

const shader = (props) => `
  #ifdef GL_ES
  precision mediump float;
  #endif

  uniform float u_time;
  uniform vec2 u_mouse;
  uniform vec2 u_resolution;
  
  float expStep( float x, float k, float n ){
    return exp( -k*pow(x,n) );
  }
  
  void main() {
    vec2 point = gl_FragCoord.xy / u_resolution.xy;
    float px = 1.0 / u_resolution.y;
    vec2 cp = vec2(cos(u_time),sin(u_time)) * 0.618 + 0.620;
  
    float l = expStep(point.x, ${props.timeSync ? 'cp.x * u_time' : 'cp.x'}, ${props.timeSync ? 'cp.y * u_time' : 'cp.y'});
    
    vec3 color = vec3(smoothstep(l, l+px, point.y), sin(u_time), cos(cp.y) * 0.5);
      
    gl_FragColor = vec4(color, 1.0);
  }
`

const ShaderComponent = createShaderCanvas(shader)

class App extends Component {
  state = {
    timeSync: false
  }

  updateState = (e) => this.setState(state => ({ timeSync: !state.timeSync }))

  render () {
    return (
      <div onClick={this.updateState}>
        <ShaderComponent id="exponential-step-curve" timeSync={this.state.timeSync} />
      </div>
    )
  }
}

Related

  • shaping-functions uses react-shader-canvas to render the shaping functions and curves.

API

createShaderCanvas

(shader: (props) => string) => ReactComponent

A function that takes a shader as an input and returns a React component which renders the shader on the canvas. The shader function gets passed the component props.

Component props

  • id (Required) - id of the canvas element. This is required to render the canvas

  • height (Optional) - height of the canvas.

  • width (Optional) - width of the canvas.

  • style (Optional) - canvas style.

License

MIT © nitin42