Particle Experiment

An experiment in manipulating a particle system.

Use the mouse wheel or q/w keys to change tool.
Pointer affects nothing.
Hand allows you to drag spawners and pull/push forces.
Remover destroys spawners and pull/push forces on click.
Pen allows you to draw collision walls for the particles.
Add (PullForce/PushForce/Spawner) creates a new appropriate object at the cursor.
ClearLines removes all collision walls.

A* Pathfinding Demo

A demo of the A* pathfinding algorithm.

Finds the shortest distance between the blue and red objects.
Click and drag the blue and red pieces to move them.
Click a tile to toggle its state as a wall.
Press the 'd' key to toggle whether diagonal movement is permitted.
Press the 'r' key to clear all walls on the grid.
Press the 's' key to toggle the g, h and f scores for each tile that is inspected.
Press the 'p' key to toggle the path visibility. Might be useful if the path is obscuring the scores.
Press the 't' key to toggle the time to compute the algorithm in milliseconds.
A* is the most used algorithm for finding the shortest path in general cases. The algorithm itself is a combination of Dijkstra's algorithm and an aproximate heuristical approach. You can perform the A* algorithm by computing the heuristic in many different ways, in my demo I used the manhattan method. My implementation is functional but not necessarily efficient. There are many ways it could be improved. This is my solution in Haxe.

2D Water Simulation

A demo of a simple water simulation

Click above the surface to drop a rock.
I wanted to create a water simulation, something that I could perhaps use in games. Using the spring object I showed in this post I could quickly put together something that resembles a water surface. I achieved this by lining a row of vertical springs with natural length of the height of the water, and connecting all adjacent points at the surface with horizontal springs.
Showing the demo in a kind of 'debug' mode you can clearly see the spring setup. You can also click and drag the points to affect to surface manually. When one of the vertical springs compresses its adjacent horizontal springs will pull on its adjacent vertical springs causing a rippling effect. The vertical springs have very a very low stiffness and damping so that they oscillate easier and for longer. The horizontal springs have a very high stiffness as they influence the magnitude of the ripple. When a rock is dropped at the point of it hitting the surface the two vertical springs it lands inbetween have a downwards force applied to them, and the physics does the rest. You can achieve a cleaner effect by having only vertical springs and manually changing the vertical velocity component of neighbouring springs based on the delta height. This produced less lateral movement, but I think looks less interesting than having horizontal springs. It's a matter of preference. As you can see from the 'debug' version of the demo the surface is just a collection of points, which when the area underneath is filed creates a row of trapeziums rather than a nice fluid surface. To an extent you can increase the number of vertical springs, as a smaller step will mean a smoother curve, but the simulation starts to look much worse as the number of springs is increased, not to mention the increase in resource usage. A simpler solution is to interpolate between the points to create a smooth curve. I used the Catmull-Rom spline method, which ensures the curve goes through all the points (important for collisions with the surface). I'm interpolating with 8 steps between each control point, but you can change the to increase/decrease performance or decrease/increase smoothness without affecting the simulation.

Interpolating Points for 2D Water Simulation

A demo of interpolation between points for a work-in-progress simple water simulation.

Click and drag points to see the effect of the interpolation, small movements are best. Press space to toggle interpolated and linear points. Using the spring system I've showcased before I'm working on a simple 2D water simulation that could be put into a game. The effect isn't done yet, there is a lot of tweaking to do, I intend to explain the effect in another post. In short there are a bunch of verticle springs that compress and expand. By default I'd draw a straight line between each set of points, but for a water effect this looks ugly. As the effect is based on real physics, I could increase the density of the springs, but the spring approximation to water breaks down quickly, not to mention an increase of resource usage. An easier option was to interpolate between the two points, using the Catmull-Rom splines method. The Catmull-Rom method ensures the curve goes through all the control points which is important to the simulation.

I'd recommend this and this for a guide on interpolation implementation.

L-System approximation of Koch Island curve

A demo of a simple L-System simulating a koch island fractal.

Q: Zoom Out
E: Zoom In
Click and Drag to move the camera
Space: Regenerate fractal based on current settings
The demo uses an axiom of "F+F+F+F" and a rule of "F -> F+F-F-FF+F+F-F". The program uses a turtle to interpret the data, whereby "F" draws a line to the next step based on the step size and current angle, "+" is an increment of the current angle and "-" is a decrement of the current angle, both by a fixed delta. The rule applied for a fixed number of iterations.