Image_Turtle & Image_Curve

First published at Sunday 12 March 2006

Warning: This blog post is more then 18 years old – read and use with care.

Image_Turtle & Image_Curve

The last days I was busy learning for a lecture for computer science which covers a lot of algorithms in graphics manipulation. For personal education I tried to implement some of them in the language I know best ... PHP .

Image_Turtle

Lindemayer system rendered with PHPLindemayer system rendered with PHP

This implements the Lindenmayer system in PHP. This is a system to draw images based on simple grammars. Most used for fractals or to simulate natural growth of plants. You perhaps wonder because of the name of this class, but the cursor which draws the objects is often called "turtle". It is really fun to play around with these grammars and the options which defines the route the turtle takes.

For the tree on the right side you just need this simple grammar with an angle of 25 degrees and recursion depth of 3:

w -> FFF[+F+F+F][-F+F+F+F+F] F -> FFF[+F+F+F][-F+F+F+F+F]

"w" is the starting symbol in this case.

I wrote some simple examples and you download them together with the classes here .

Image_Curve

Threedimension bezier curveThreedimension bezier curve

Another thing I needed to understand - and imho the easiest way is just to implement it - are bezier curves and BSplines. Hunting the errors in the implementation solved all misunderstandings in the profs script ;-).

This class offers a simple way to draw lines, bezier curves or BSplines from an array with points. You can download the class here .

You want to see an example? Ever implemented bezier curves on the base of the Bernsteinpolynom you know that it is really trivial to implement a 3D version - of course I implemented it for Image_3D . I hope to release a new version of Image_3D next weekend, so that you can render it by yourself.

Subscribe to updates

There are multiple ways to stay updated with new posts on my blog: