Giter Club home page Giter Club logo

react-webgl-fluid's Introduction

react-webgl-fluid

http://x8bitrain.github.io/react-webgl-fluid

A React implementation of Pavel Dobryakov's WebGL Fluid Simulation as a component, not only is it a fun simulation to play with but when tweaked the settings to be less resource intensive and lower resolution, the simulation can be a cool UI element you could add to something like a navbar or page background like this: https://btr.pm/projects/

How it works

Not a rewrite of the original script but just a basic, easy to use React component that adds a <script> tag containing a modified version of the original when the component mounts, the script then hooks into a <canvas> component generated by React, then it renders the Fluid sim.

You can edit the simulation settings on line 28 of fluid-init.js https://github.com/x8BitRain/react-webgl-fluid/blob/master/assets/js/fluid-init.js#L4

Main changes

The modifications to the original Fluid WebGL script are as follows:

  • Removed code that initializes the control panel for changing the sim settings.
  • Absolute paths to .png resources.
  • Name of the canvas element the scripts hooks into from document.getElementsByTagName('canvas')[0]; to document.getElementsByClassName('fluid-canvas')[0];
  • Altered sim configuration to be lower res and density, also background is white now.
  • Inline style as a states so you can change the dimensions of the canvas on the fly with React.

react-boilerplate

Build using a simple React boilerplate from Lewagon configured with:

  • React, ReactDOM
  • Webpack 4
  • Babel with es2015 and react presets
  • .js or .jsx
  • main application.scss stylesheet is imported in index.js as a module to enjoy hot reloading

Scripts

To start the local Webpack Dev Server (usually on port 8080):

yarn start

To lint all JavaScript files in the src folder:

yarn lint

To build static HTML and JS files for production or whatever rly)))

webpack -p

react-webgl-fluid's People

Contributors

dependabot[bot] avatar x8bitrain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-webgl-fluid's Issues

Issues in Safari on MacOS

Hey there,

Thanks for all your help in the past issue, still working that out for now. I have a new issue I was hoping you'd be able to help with: The WebGL Sim doesn't work on Safari on MacOS. Trying using this link to see if you can get it to work on your end: https://helloshivam-2020.netlify.com

No errors in console so I don't know what it could be. Pavel's demo doesn't work great either.

Implementation in Gatsby

I'm trying to add this into my GatsbyJS site, however, on every page change, the script getting added again which ruins the performance of the sim. Is there a way to handle that change? Is there a way to perhaps remove the script and then add it back when someone navigates back to the page with the sim?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.