Class Turtle

  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by org.jscience.biology.lsystems.fixed.Turtle
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer,, javax.accessibility.Accessible

public class Turtle
extends java.applet.Applet

This class is responsible for all the drawing of the LSystem. It has all capabilities to draw and show a 3 dimensional model of a system of the class LSystem also defined in this package. This class extends an applet and so it can be viewed in a frame or on a web page.
This class uses the Java3D 1.1.1 package to build the scene.

The method of drawing the lsystem is the one of the turtle interpretation described in the book "The algorithmic beauty of plants" written by Przemyslaw Prusinkiewicz and Aristid Lindenmayer. See chapter 1 "Graphical modeling using L-Systems" for more details.
The coordinate system used here has been slightly changed from the one used in the book. It now matches a normal coordinate system as we know it. See analysis of this project for more information.

When parsing the lsystem all signs make the turtle change its orientation and every occurence of a capital letter 'F' draws a truncated cone from the position of the turtle in it's actual direction. The truncated cone has the length, specified in the lsystem. Depending on how many times the sign '!' has already occurred the diameters of the truncated cone vary. It is the users responsibility to choose the right initial diameter and decrement so that the cones never have negative values.
Leafes, indicated between signs '{' and '}', are drawn as a set of triangles. It is also the users job to make the turtle begin and end a leaf at the same position. That means that all signs between starting leaf and ending leaf must be chosen the way to make the turtle 'return' to it's starting point, else the leaf won't be displayed correctely mabe not at all.

See Also:
Serialized Form

Nested Class Summary
Nested classes/interfaces inherited from class java.applet.Applet
Nested classes/interfaces inherited from class java.awt.Panel
Nested classes/interfaces inherited from class java.awt.Container
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
Field Summary
Fields inherited from class java.awt.Component
Fields inherited from interface java.awt.image.ImageObserver
Constructor Summary
Turtle(LSystem lsSystem)
          Constructs the Lindenmayer System in form of a 3 dimensional structure respecting the rules and values given in the passed LSystem.
Method Summary
 javax.vecmath.Matrix3f buildMatrix(javax.vecmath.Vector3f v3fCol0, javax.vecmath.Vector3f v3fCol1, javax.vecmath.Vector3f v3fCol2)
          Builds a new 3x3 matrix with the given three vectors by inserting the vector values in the matrix columns.
 javax.vecmath.Vector3f getPosition()
          Gets the actual position of the turtle.
 javax.vecmath.Matrix3f rotationMatrix(javax.vecmath.Vector3f v3fAxe, float fAngle)
          Calculates the rotation matrix for a 3D rotation around the axe going through the point 0,0,0 with the direction described by the vector of the given angle.
 void setPosition(javax.vecmath.Vector3f v3fPosition)
          Set a new position for the turtle.
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
Methods inherited from class java.awt.Panel
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public Turtle(LSystem lsSystem)
Constructs the Lindenmayer System in form of a 3 dimensional structure respecting the rules and values given in the passed LSystem. By default the branches are drawn in brown and the leafes in green color. Directional light and ambient light are set. The user may turn the scene using the mouse.

lsSystem - The LSystem to use. Note that the LSystem has to be built before it can be used.
Method Detail


public javax.vecmath.Matrix3f rotationMatrix(javax.vecmath.Vector3f v3fAxe,
                                             float fAngle)
Calculates the rotation matrix for a 3D rotation around the axe going through the point 0,0,0 with the direction described by the vector of the given angle.

v3fAxe - The vector describing the axis going through the origin (0,0,0).
fAngle - The angle describing the rotation value.
The 3x3 float matrix which is the rotation matrix.


public javax.vecmath.Matrix3f buildMatrix(javax.vecmath.Vector3f v3fCol0,
                                          javax.vecmath.Vector3f v3fCol1,
                                          javax.vecmath.Vector3f v3fCol2)
Builds a new 3x3 matrix with the given three vectors by inserting the vector values in the matrix columns.

v3fCol0 - The vector to be inserted in the first column.
v3fCol1 - The vector to be inserted in the second column.
v3fCol2 - The vector to be inserted in the third column.
A newly created 3x3 matrix.


public void setPosition(javax.vecmath.Vector3f v3fPosition)
Set a new position for the turtle.

v3fPosition - The new position


public javax.vecmath.Vector3f getPosition()
Gets the actual position of the turtle.

The actual position.