All Projects → batman-nair → puddle.js

batman-nair / puddle.js

Licence: MIT license
An ASCII/Node based fluid simulation library.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to puddle.js

lexicon-mono-seq
DOM Text Based Multiple Sequence Alignment Library
Stars: ✭ 15 (-85.29%)
Mutual labels:  javascript-library, ascii-art
html-to-react
A lightweight library that converts raw HTML to a React DOM structure.
Stars: ✭ 696 (+582.35%)
Mutual labels:  javascript-library
consono
The most correct, informative, appealing and configurable variable inspector for JavaScript
Stars: ✭ 17 (-83.33%)
Mutual labels:  javascript-library
sph vulkan
SPH simulation in Vulkan compute shader.
Stars: ✭ 29 (-71.57%)
Mutual labels:  fluid-simulation
webgl-regl-fluid-base
Regl base for webgl fluid simulations
Stars: ✭ 14 (-86.27%)
Mutual labels:  fluid-simulation
jflowsim
Highly interactive, thread-parallel Lattice Boltzmann CFD solver
Stars: ✭ 18 (-82.35%)
Mutual labels:  fluid-simulation
rottenjs
An all-in-one (2.6kb) Javascript library for web development
Stars: ✭ 15 (-85.29%)
Mutual labels:  javascript-library
iFrameX
Iframe generator with dynamic content injection like HTML, Javascript, CSS, etc. and two ways communication, parent <-> iframe.
Stars: ✭ 18 (-82.35%)
Mutual labels:  javascript-library
xGallerify
A lightweight, responsive, smart gallery based on jQuery
Stars: ✭ 52 (-49.02%)
Mutual labels:  javascript-library
animate
PixiJS runtime library for content from Adobe Animate CC
Stars: ✭ 142 (+39.22%)
Mutual labels:  javascript-library
owari
The End Generator
Stars: ✭ 23 (-77.45%)
Mutual labels:  ascii-art
rutils
ruitls.js 涵盖了前端开发常用的工具方法,有字符串、数字、数组、缓存、文件等,尽可能的避免前端在开发中重复造轮子
Stars: ✭ 14 (-86.27%)
Mutual labels:  javascript-library
costa-rica-iban
Funciones utiles para extraer y validar información general de números de cuenta IBAN de Costa Rica
Stars: ✭ 16 (-84.31%)
Mutual labels:  javascript-library
sph-tutorial
Brandon Pelfrey's SPH fluid simulation tutorial
Stars: ✭ 36 (-64.71%)
Mutual labels:  fluid-simulation
staballoy
Reactive UI framework for Titanium Alloy
Stars: ✭ 18 (-82.35%)
Mutual labels:  javascript-library
resizerjs
Simple resizing for flexbox
Stars: ✭ 16 (-84.31%)
Mutual labels:  javascript-library
constant-time-js
Constant-time JavaScript functions
Stars: ✭ 43 (-57.84%)
Mutual labels:  javascript-library
menu-hamburger
🍔 A clean, simple and easy to use library to create a Menu Hamburger
Stars: ✭ 17 (-83.33%)
Mutual labels:  javascript-library
Amino.JS
A powerful JavaScript library for interacting with the Amino API 🌟
Stars: ✭ 25 (-75.49%)
Mutual labels:  javascript-library
Fluid Simulation
Self advection, external force and pressure solve to a velocity field represented by a MaC grid.
Stars: ✭ 107 (+4.9%)
Mutual labels:  fluid-simulation

Puddle.js

An ASCII/Node based fluid simulation library built with vanilla JS and CSS Grids.

Try it out and play around!

Screencaps

Different Node styles!

Move Ripples

Random Ripples mode!

Random Ripples

How to use it?

Add puddle.js to your webpage. You can initialize any div container to hold the puddle element.

let puddle = new Puddle(<div-selector>);
puddle.setupGrid(); // To initialize the puddle

There are a lot of options which can be used to tweak your puddle element.

puddle.setNodeStyle(nodeStyle);  // nodeStyle one of ["base", "ascii", "water", "party"]  // Default "base"
puddle.setMathMode(mathMode);  // mathMode one of ["anair", "helias"]   // Default "anair"
puddle.setNodeSize(nodeSize);  // Default 3% of min(height, width) of container
puddle.setUpdateInterval(updateInterval);  // Default 100ms

puddle.toggleRandomRipples();	// Default False
puddle.toggleRandomRippleStrength(); // Default True
puddle.setMaxRippleStrength(rippleStrength);  // Default 100
puddle.setRandomRippleGenerationInterval(generationInterval);  // Default updateInterval  min: updateInterval
puddle.setRandomRippleTimeRange(timeRange);  // Default updateInterval  max: updateInterval
// Random ripples are generated at RippleGenerationInterval (+/-) RippleTimeRange/2

puddle.createRandomRipple();
puddle.createWave();

puddle.setDampeningRatio(dampeningRatio); // Default 0.8  between 0 and 1

puddle.toggleRippleOnMove(); // Default True

I built my personal site using this as an example for usage.

Internal workings

The different node styles are different classes NodeBase, AsciiNode, WaterNode, PartyNode.

There are 2 different math modes - how forces are updated every frame.

  1. Anair - The initial mode developed. Every node has X and Y forces. The whole force is is transfered to the nodes in the direction of the force in each frame.
  2. Helias - This was taken from here. The force updates in this mode are more based on actual wave motion.

Every node to be updated is added to an updateQueue. When a click is registered, all the surrounding nodes are added to the updateQueue. In the update loop, the next force value for the node is calculated based on existing forces in the surrounding nodes. Once update is done, the node is added to a drawQueue.

At every frame, there is an update section where net forces for nodes in the updateQueue are calculated. After that, in the draw section, the current force is updated and the node is drawn.

When a node is updated, it adds other nodes which will be affected by its force to the next updateQueue. This way only the affected nodes needs to be updated instead of updating te whole frame in every loop.

Contributing

Feel free to add your own node style or whatever! Send in a PR and we'll discuss! :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].