This version of the experiment takes the most standard openGL approach
possible: GLSL Attribute buffers for most of the Shader interactions, and
sophistication is use of a “z” uniform to let all the 2D
objects have their own z plane.
turtles, which in turn contain arrays of individual patch and turtle
objects. Each turtle and patch contain its shape, x,y position and color.
Turtles also have a heading while the patches have a heat value. The higher
level patches and turtles object contain a count of their objects along
with the WebGL Attribute buffers they use.
The program is not object oriented in the usual sense but typical
migrating to the shaders.
Re-creates each turtle triangle by its heading and x,y loc.
Drops heat onto the patch directly under it
Performs a 2-pass diffusion of the patch heat.
The Diffusion Rate, Turtle Heat & Speed sliders are read every step
so they can be changed during run-time. (use setup button to change patches
In terms of computation, this involves:
There are 15,625 patches, with 93,750 vertices and colors initially so
Each step uploads all the patch colors (1,125,000 bytes) and all turtle
triangles (24,000 bytes) by re-binding those two attribute buffers.
Upping the turtles to 1000 results in acceptable performance. Each step
re-calculates the turtles position and heading: 3,000 rotations and
translations as well as determining the patch they are over, transferring
heat to the patch.
The diffusion process performs two passes over the 15,625 patches, and
calculates the diffusion with the 8 neighbor patches, for a total of
I’m seriously amazed how well it performs, given the large amount
changes each step.
The second model moves to much more computing done
in the GPU.