Lindenmayer System
A Simple L-system Image Generator Featuring Turtle Graphics
Public Member Functions | Private Attributes | List of all members
LSystem Class Reference

A stochastic bracketed context-free L-system. More...

#include <Lsystem.h>

Public Member Functions

void SetRoot (const std::wstring &omega)
 Set the root string. More...
 
void AddRule (const LProduction &rule)
 AddRule rule. More...
 
void Clear ()
 Clear the rules, buffers, and settings. More...
 
void Generate (const UINT n)
 Generate L-system from stored root and rules. More...
 
const std::wstring & GetString () const
 Get generated string. More...
 
const std::wstring & GetRuleString () const
 Get rule string. More...
 
const UINT GetGenerations () const
 Get number of generations. More...
 
const bool IsStochastic () const
 Is a stochastic L-system. More...
 

Private Attributes

CRandom m_cRandom
 PRNG.
 
std::wstring m_wstrRoot
 Root string.
 
std::map< wchar_t, std::vector< LProduction > > m_mapRules
 Productions.
 
std::wstring m_wstrRuleString
 Rule string.
 
std::wstring m_wstrBuffer [2]
 Generation buffers.
 
std::wstring * m_pResult = m_wstrBuffer
 Pointer to generated string.
 
bool m_bStochastic = false
 Includes a stochastic rule.
 
UINT m_nGenerations = 0
 Number of generations.
 

Detailed Description

This basic context-free stochastic bracketed L-system can be used to re-create some of the line drawings in ABOP. The productions are stored in a std::map<char, std::vector<LProduction>> which maps the left-hand side of a production to an std::vector of the productions that have that left-hand side. A text string m_wstrRuleString is used to store a printable rule string in text form which is used to display the rules on the window. Double-buffering in m_wstrBuffer[2] is used to generate the result string m_pResult.

Definition at line 70 of file Lsystem.h.

Member Function Documentation

◆ AddRule()

void LSystem::AddRule ( const LProduction rule)

Add a new production. The new production is inserted into m_mapRules, that is, the left-hand side is mapped to a vector of right-hand sides to which the new right-hand side is appended. The new rule is also appended to the rule string m_wstrRuleString for display.

Parameters
ruleA production.

Definition at line 59 of file Lsystem.cpp.

◆ Clear()

void LSystem::Clear ( )

Clear the rules, the rule string, the root string, the generation buffers, and the settings.

Definition at line 101 of file Lsystem.cpp.

◆ Generate()

void LSystem::Generate ( const UINT  n)

Generate a string from the root by applying the L-system productions in parallel, and repeating for a fixed number of generations. Double-buffering is used, that is, if generation \(i\) is stored in m_wstrBuffer[ \(j\)], where \(j \in \{0,1\}\), then generation \(i+1\) is stored in m_wstrBuffer[ \(j + 1 \pmod 2\)]. Zero generations means the root string, 1 generation means 1 pass from left to right applying the rules, etc.

Parameters
nThe number of generations.

Definition at line 125 of file Lsystem.cpp.

◆ GetGenerations()

const UINT LSystem::GetGenerations ( ) const

Reader function for the current number of generations m_nGenerations.

Returns
The current number of generations m_nGenerations.

Definition at line 190 of file Lsystem.cpp.

◆ GetRuleString()

const std::wstring & LSystem::GetRuleString ( ) const

Reader function for the rule string m_wstrRuleString.

Returns
A const reference to the rule string m_wstrRuleString.

Definition at line 183 of file Lsystem.cpp.

◆ GetString()

const std::wstring & LSystem::GetString ( ) const

Reader function for the result string *m_pResult.

Returns
A const reference to the result string *m_pResult.

Definition at line 176 of file Lsystem.cpp.

◆ IsStochastic()

const bool LSystem::IsStochastic ( ) const

Reader function for the stochasticity flag m_bStochastic.

Returns
true if the current rules are stochastic.

Definition at line 197 of file Lsystem.cpp.

◆ SetRoot()

void LSystem::SetRoot ( const std::wstring &  omega)

Set the root, that is, store it in m_wstrRoot and prepend it to the rule string m_wstrRuleString for display.

Parameters
omegaThe new root.

Definition at line 93 of file Lsystem.cpp.