A list of helpful libraries and code

Fluid
Here's a little fluid simulation library. Includes demo. Feel free to use it wherever. Also if you make any improvements let me know! :playdate:

Docs
local fluid = Fluid.new(x, y, width, height, options)
options.tension adjusts surface stiffness.
options.dampening increases or decreases wave oscillation.
options.speed adjusts speed at which waves move.
options.vertices adjust the number of points on the surface.

fluid:setBounds(x, y, width, height)
Change the bounds of the fluid. Keep in mind that the surface of the fluid may peek outside these bounds.

fluid:reset()
Reset fluid surface so that it is still.

fluid:getPointOnSurface(x)
With x between the left and right side of the fluid surface, this function returns a point containing the x and y of the surface at x.

fluid:touch(x, velocity)
Push or pull on the surface at the vertex closest to x. A high velocity creates larger waves. A negative velocity pulls upward on the surface (simulate something coming out of the fluid).

fluid:update()
Call each frame to update the fluid simulation.

fluid:fill()
Draws the fluid filled (uses current color or pattern).

fluid:draw()
Draws an outline of the fluid (uses current context line/color properties).

Library
fluid.zip (16.1 KB)

fluid-toys

28 Likes