Graphics Programming

Ray Tracer development and some more. By Pawel Bokota.

L-systems continued

leave a comment »

I have extended my previous L-systems implementation by adding more symbols, which allow me to create 3-D figures. This time I used OpenGL for rendering and QT for the GUI. Below is a screenshot of my program and the 3-D “tree” that it generated. Also below, is my code for the L-system class, the heart of the program. The class is responsible for rewriting strings based on the rules and symbols given.

LSystem::LSystem(string start, Rule rule) : rules(rule)
    startAxiom = start;
    lang       = "";

void LSystem::run(int iterations)
    string curr = startAxiom;

    for (int i = 0; i < iterations; i++)
        for (int j = 0; j < curr.size(); j++)
            string buff = rules.getRule(curr[j]);

            if (!buff.empty())
                curr.replace(j, 1, buff);

                j += buff.size() - 1;

    lang = curr;

string LSystem::getGenString()
    return lang;

Written by Pawel

December 30, 2009 at 4:42 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: