L-Systems and C# Rendering Code
Description
- UMass Lowell Undergrad Project, Spring 2011
- Source: L-Systems-in-OpenTK
- Inspired by Minecraft, looked for methods of tree generation that seemed more natural
- Found “Algorithmic Beauty of Plants” by Przemyslaw Prusinkiewicz and Aristid Lindenmayer
- Experimented with Open-TK, OpenGL Bindings for C#
This project was for my geometric modeling class, where I was pursuing a way to create realistic tree growth. I never was able to simulate tree growth in the end, but I did learn a lot about L-Systems from this awesome book I found while searching for research papers.
The Algorithmic Beauty of Plants, http://algorithmicbotany.org/papers/#abop
The authors of the above book showed a way to model plant growth over time as well as a way to represent the self-similarity that is seen in many plants as a formalized process known as an L-System. I wrote a program to display seven different predefined L-Systems and draws them over-time. This was my first project written in C# and used the C# OpenGL bindings, OpenTK. It was a lot of fun to try out this new-to-me high level language compared to most of the C/C++ class work I was used to.
Examples
Rules:
Angle:
Iter:
F -> FF-FFF+F+FF-F
90 deg
4
Rule 1:
Rule 2:
Angle:
Iter:
L -> L+R++R-L–L-R+
R -> -L+RR++R+L–L-R
60 deg
4
start = "F"; next[0] = "F[+F+F]F[-FF]F"; ang = 20.0f; iter = 5; for( int n = 0; n < iter; n++ ) start = start.Replace("F", next[0]); for( int n=0; n < start.Length; n++ ) { if(start[n] == '[') GL.PushMatrix(); if(start[n] == ']') GL.PopMatrix(); if(start[n] == 'F' && n < timer){ GL.Translate(0.0f, 0.1f, 0.0f); GL.Begin(BeginMode.Lines); GL.Vertex3( 0.0f, -0.1f, 10.0f ); GL.Vertex3( 0.0f, 0.0f, 10.0f); GL.End(); if(start[n] == '-') GL.Rotate( -ang, Vector3d.UnitZ ); if(start[n] == '+') GL.Rotate( ang, Vector3d.UnitZ ); }