This cell has two pistons on each side, allowing multiple cells to be chained together like so:
In order for the trap to close, the top pistons contract and the bottom pistons expand:
As it turns out, theories about how Venus Fly Traps close indicate similar possibilities.
The acid growth theory states that individual cells in the outer layers of the lobes and midrib rapidly move 1H+ (hydrogen ions) into their cell walls, lowering the pH and loosening the extracellular components, which allows them to swell rapidly byosmosis, thus elongating and changing the shape of the trap lobe.
Alternatively, cells in the inner layers of the lobes and midrib may rapidly secrete other ions, allowing water to follow by osmosis, and the cells to collapse. Both of these mechanisms may play a role and have some experimental evidence to support them.
Finally, I wanted to simulate a trigger mechanism whereby the cell that senses a fly signals its neighbors to contract, but with a constant messaging delay between adjacent cells. The signaling in the real Venus Fly Trap occurs through ionization:
When the trigger hairs are stimulated, an action potential (mostly involving calcium ions—see calcium in biology) is generated, which propagates across the lobes and stimulates cells in the lobes and in the midrib between them. It is hypothesized that there is a threshold of ion buildup for the Venus flytrap to react to stimulation.
Ideally I wanted to only represent Cells in my code, but I ended up having important logic in Joints as well. The behavior of the Cells and the Joints together create all of the behaviors the creature exhibits.
Each cell has the following behavior. The system calls the Touched function when the fly touches a cell, which, if the cell is sensitive (a.k.a. if it is in the top row), the cell Contracts. The cell also Contracts if it receives a Contract message from an incident Bond. Contract shrinks the cell over a set amount of time, and passes the Contract message along to all incident Bonds which are not the Bond from which the Contract message was received.
Likewise, each bond, if it has angle 0.0 (meaning is a horizontal bond), contracts over a set amount of time, and passes the contract message along to whichever cell it did not receive the contract message from, after waiting a set amount of time in order to simulate the messaging delay:
The fly is also interesting in its own right. Its motion is controlled by two smoothly but randomly varying 1D signals which control the direction and the magnitude of a force applied to the fly. Each of these signals is an arbitrary periodic walk through a 2D Simplex noise texture.
Just for code-and-cellular-autonomy-aesthetic reasons, I would like to eliminate the Joint from this system and have only Cells, although it might actually be more physically accurate to represent Joints as well (the space between cells in a real organism is not simply a vacuum, after all).
Of course this could be done in 3D, in which case a cone-like shape could work. Simply extruding the 2D structure into 3D would not work, as the ends of the tightened cylinder would be open. Of course something closer to an actualy Venus Fly Trap could also be modeled, which would be a bit more complicated than a radially symmetric cone.
More subtlety could be added to the fly detection mechanism, and this could be tested with false flys, like raindrops, twigs, etc., with which real Venus Fly Traps must deal.
Once again, here is a link to the live demo where you can try a couple different versions: