Friday 23 June 2017

Dominos at Dusk: L-systems and Realistic Motion with Blender

This week we had Adam Latchem talk through one of his own projects: Dominos At Dusk. A video of the session is here.

It's a project which combines several elements:
  • l-systems for creating fractal shapes
  • physics for realistic motion
  • ray-tracing for realistic rendering




L-Systems

Aristid Lindenmayer, a theoretical biologist and botanist, wanted to see if he could model how plants grow - how they branch and rotate their extensions, and how their overall forms are self-similar in nature. He came up with a really simple method for generating complex, and sometimes very natural organic looking forms, which are now called L-systems.

The core of the idea is to take a string of symbols, and to repeatedly apply a set of rules which change the symbols in that string. For example, if we had a string ABC and a rule that said B->A and another rule C->AB, we can see that applying these rules turns that string into AAAB. Why is this? Well there is no rule for transforming the A symbol so it stays as it is. There is a rule which turns B into A, and the final rule replaces the symbol C with two symbols AB. We can keep repeatedly applying the rule set.

This get's interesting if we interpret those symbols visually or physically. We could say that A means "draw a line forwards", and B means turn left by 60 degrees, and C might mean change colour. You can see that if we executed these string "programs" we could get interesting shapes developing. The reason the fractal self-similarity emerges sometimes is that segments of a shape can be replaced by similar smaller segments.


The wikipedia page has a fuller explanation, with some worked examples that are quite easy to follow.

Adam chose the Koch snowflake - and you can follow a worked example here.


If you're interested, there's no reason to stick with 2-dimensional forms. Here's Adam showing a 3-d L-system.



3-D Scenes in Blender with Python

Blender is an extremely versatile tool for working with objects in 3-dimensional space - and it does things like physics based motion, sophisticated rendering for realistic images, and lots lots more. I've always found it to be a bit too rich with a steep learning curve - but there is no doubt it is ridiculously powerful - just take a look at it's impressive features page. And Blender is free and open source.

Blender is also very programmable, with Python, a very popular and easy to use language. Adam developed Python code to:

  • implement an L-system symbol generator
  • use that to create a Koch snowflake
  • use that snowflake to place 3d domino objects


The nice thing is that you can easily use Blender's Python interfaces to create objects in its world using your own code. In fact, almost all of Blender's functionality is available through Python, and that means you can do things like configure scene parameters like lighting and physics. You can find his code on github: https://github.com/adamlatchem/dominoesAtDusk

Here's a view of dominos arranged around the Lock snowflake.



Physics for Motion

Blender can fairly realistically simulate the motion and interaction of objects by applying the laws of nature - well maybe not all of nature's forces, but a few of the them that goven how objects fall, accelerate, slow down, bounce off each other, and so on.

This was actually a little tricky, but the process of manually tweaking the scene and its physical characteristics, like mass, does lead to a rather impressive animation.

Here's an early experiment Adam developed to show simple blocks falling and bumping into each other.



Ray Tracing

You'll notice in that video that the scene is rendered not as cartoonish blocks but very realistically. The lighting seems real, as do the shadows and reflectances. In fact the objects in the scene seem to have their own materials. This is another key feature of Blender - called ray tracing.

Ray tracing is a huge and sophisticated subject all by itself. At its simplest, the idea is to follow rays from the viewer / eye / camera backwards through the scene to see which objects they hit, were reflected from, and whether any made their way back to a light source.


Ray trace diagram.svg
By Henrik - Own work, GFDL, Link


We'll cover ray tracing at a future Algorithmic Art meetup.


Final Video

Adam spent quite a bit of time refining the scene, object placement, the physics, motion of the camera ... and also music for the video, which is stunning itself.

The result was amazing, and received spontaneous applause!

Put your headphones on and play this full-screen ...



Explore Further

Some links to explore further:

  • L-systems generators (1) (2) (3) - experiment yourself, vary the parameters and transformation rules - no need to install any software, work on the web.
  • The Algorithmic Beauty of Plants - a whole book by Aristid Lindenmayer, now online for free, direct link (17Mb pdf)
  • The Artificial Life of Plants - a nice well illustrated survey paper on L-systems (pdf)
  • Mastering Blender - the book that was recommended to me, after I said that many of them had too steep a learning curve.
  • Blender's Bullet physics engine user manual (pdf
  • Blender's Python interface manual
  • BlenderGuru additional getting started help for Blender
  • Turtle Graphics ... which you can trace back to the 1960s. 

No comments:

Post a Comment