org.generation5.bio
Class LSystem

java.lang.Object
  extended byorg.generation5.bio.LSystem
All Implemented Interfaces:
Visualizable

public class LSystem
extends java.lang.Object
implements Visualizable

The class provides basic L-System functionality.


Constructor Summary
LSystem()
          Default constructor.
LSystem(java.lang.String initial)
          Constructor with initial rule specifier (axiom)
 
Method Summary
protected  void drawLSystem(java.lang.String strLSystem, double angle, int depth, java.awt.Graphics graphics)
          Draws the L-System itself.
 java.lang.String getAxiom()
          Retrieve the axiom used.
 java.lang.String getRule(char replace)
          Retrieve the rule for the specified letter.
 void initializeRules()
          Initializes the rules to be self-referential, essentially resetting them.
static void main(java.lang.String[] args)
          Test function that writes a couple of simple L-System examples of varying types as well as depths.
 void render(java.awt.Graphics graphics, int pw, int ph)
          Draw the L-System.
 void setAxiom(java.lang.String axiom)
          Set the axiom.
 void setBackground(java.awt.Color back)
          Set the background colour.
 void setDepth(int depth)
          Set the maximum depth the L-System should recursively draw.
 void setForeground(java.awt.Color fore)
          Set the foreground colour.
 void setParameters(double angle, double initAngle, int seg, double step)
          Set the parameters for the L-System.
 void setRule(char replace, java.lang.String rule)
          Set the rule for the given character.
 void setStartPoint(int sx, int sy)
          Set the initial starting point to draw the L-System at.
 void writeImage(java.lang.String filename, int width, int height)
          Write the L-System to an image file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LSystem

public LSystem()
Default constructor.


LSystem

public LSystem(java.lang.String initial)
Constructor with initial rule specifier (axiom)

Parameters:
initial - Initial rule (the axiom).
Method Detail

initializeRules

public void initializeRules()
Initializes the rules to be self-referential, essentially resetting them.


setAxiom

public void setAxiom(java.lang.String axiom)
Set the axiom. This is the initial rule that the L-System follows.

Parameters:
axiom - the axiom to use.

getAxiom

public java.lang.String getAxiom()
Retrieve the axiom used.

Returns:
the axiom in use.

setRule

public void setRule(char replace,
                    java.lang.String rule)
Set the rule for the given character. The rules are specified using the uppercase letters A through Z. Within the L-System, each instance of the letter replace is replaced by rule, recursively until the maximum depth is reached.

Parameters:
replace - the letter of the rule.
rule - the rule itself.

getRule

public java.lang.String getRule(char replace)
Retrieve the rule for the specified letter.

Parameters:
replace - the rule to retrieve.
Returns:
a string denoting the rule.

setParameters

public void setParameters(double angle,
                          double initAngle,
                          int seg,
                          double step)
Set the parameters for the L-System.

Parameters:
angle - the angle at which the +/- parameters rotate the L-System by.
initAngle - the initial angle the L-System starts at.
seg - the segment length.
step - the step size. This is the amount the L-System should multiply the step size by for different depth.

setDepth

public void setDepth(int depth)
Set the maximum depth the L-System should recursively draw.

Parameters:
depth - the depth.

setStartPoint

public void setStartPoint(int sx,
                          int sy)
Set the initial starting point to draw the L-System at.

Parameters:
sx - the starting x-point.
sy - the starting y-point.

render

public void render(java.awt.Graphics graphics,
                   int pw,
                   int ph)
Draw the L-System. Note that the class does no testing whether the L-System is drawn within bounds.

Specified by:
render in interface Visualizable
Parameters:
graphics - the graphics context.
pw - the context width.
ph - the context height.

drawLSystem

protected void drawLSystem(java.lang.String strLSystem,
                           double angle,
                           int depth,
                           java.awt.Graphics graphics)
Draws the L-System itself. The function is called recursively as the L-System rules specify.

Parameters:
strLSystem - the L-System axiom.
angle - the current angle.
depth - the current depth.
graphics - the graphics context.

setBackground

public void setBackground(java.awt.Color back)
Set the background colour.

Parameters:
back - the background colour.

setForeground

public void setForeground(java.awt.Color fore)
Set the foreground colour.

Parameters:
fore - the foreground colour.

writeImage

public void writeImage(java.lang.String filename,
                       int width,
                       int height)
Write the L-System to an image file.

Specified by:
writeImage in interface Visualizable
Parameters:
filename - the filename to write.
width - the width of the image.
height - the height of the image.

main

public static void main(java.lang.String[] args)
Test function that writes a couple of simple L-System examples of varying types as well as depths.

Parameters:
args - no arguments required.

This documentation is part of the Generation5 JDK.