Kore Nordmann - PHP / Projects / Politics ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Kore Nordmann :Date: Fri, 27 Jul 2007 20:26:41 +0200 :Revision: 5 :Copyright: CC by-sa ========================== Image_Turtle & Image_Curve ========================== :Description: While learning for a lecture in computer science which covers several algorithms on graphic manipulation I implemented some of the algorithms for personal education and these are the results... 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`__ . __ http://www.php.net Image_Turtle ============ .. image:: tree.png :alt: Lindemayer 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. __ http://en.wikipedia.org/wiki/L-system 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`__ . __ http://kore-nordmann.de/home/php_code_snippets/image_turtle Image_Curve =========== .. image:: bezier_3d.png :alt: Threedimension 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. __ http://kore-nordmann.de/home/php_code_snippets/image_curve __ http://en.wikipedia.org/wiki/Bernstein_polynomial __ http://pear.php.net/package/Image_3D Trackbacks ========== Comments ========