Cloudy Goo

Creative coding and exploration through software

Cephalopodaphilia: Tech Details

Procedural generation is the creation of form, colour or movement through direct calculation. This is in contrast to the more usual route of storing and retrieving pictures, animations or 3D objects pre-generated by humans.

Proceduralism isn't a new concept - lots of contributors have embiggened the space, many in quite unique ways. Some of the names that come to mind include Benoit Mandelbrot and Edward Lorenz with their iterative fractal systems: the granddaddys of proceduralism. Ed Catmull, along with colleague Raphael Rom, designed a conveniently malleable curve or 'spline'.

More recently Ken Perlin cornered the market in 'noise': an extremely versatile procedural building block. Many of the visual effects in movies, games and TV use Perlin noise in some form or other. Concurrently with Perlin but over in the UK, David Braben and Ian Bell built a game called Elite whose universe was procedurally generated. Elite had 8 galaxies, each containing 256 planets - not bad for the time.

Preliminaries

The goal is to reproduce or at least ape some characteristics of something that exists in nature. To that end, I have tried to tie tentacular reality to these notes by including small observations to help illustrate each design decision.

We are producing images of tentacles - that means any vector algebra presented will be 2-dimensional, unless otherwise stated.

So with the background out of the way, on to the detail.

Foundations: The Curve

The backbone of this model is a realistic curve - one that has proportions and curls like real tentacles.

First though we need a way to draw a curve. A simple solution is to observe the way one might draw a curve on paper:

Pick a position

Pick a direction

Step away from our position in our direction

Repeat steps 2 and 3 until happy

p(n+1) = p(n) + (segment_length * direction)

Lets also define a termination condition: a fixed number of line segments N for our curves.

Its often easier to perform calculations along a curve with some notion of where on the curve we are. The usual solution is to define a parameter t which represents a position on the curve from 0 to 1:

t = n / (N-1)

From Curve To Tendril

There are 2 main tunable parameters in our curve model. By altering these, one can produce essentially any curvey shape.

We can now draw our tentacle with thickness by drawing 'bones' along the curve or drawing either side of the tentacle by connecting the ends of each bone:

8 Tentacles Make A Cephalopod

Our simple direction model gives reasonable effects for a single curve. When we create a whole set of tentacles though, we want them all to share tentacleness but also to retain some individuality.

Considered from another angle, we want a generalised way to calculate curve direction at each point on each tentacle. We can create a function which provides direction value for each of our tentacles and whose value changes smoothly over the whole image.

Our direction function will use a set of 'attractor' points spread over the image, each with a defined radius of influence. The direction at a given position is the accumulated vector towards each point whose influence covers our sample position:

Observation: tentacles are more flexible towards the ends.

Now we can apply the direction function to our model in a realistic way by scaling its effect up towards the tentacle end: