Graphics Programming

Ray Tracer development and some more. By Pawel Bokota.

Archive for December 2009

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;
}
Advertisements

Written by Pawel

December 30, 2009 at 4:42 pm