home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / graphics / fractal_1 / !Fractal / Help / L-Systems < prev    next >
Text File  |  1995-09-05  |  14KB  |  314 lines

  1.   ________________________________________________________________________
  2.  /                                                                        \
  3. |                   !Fractal : Help On L-Systems                           |
  4. |                                                                          |
  5. |                          September 1995                                  |
  6.  \________________________________________________________________________/ 
  7.  
  8. L-System : Turtle graphics as used for drawing plants etc.
  9. --------
  10. The L-system uses a LOGO like turtle language to describe shapes as a series
  11. of movements, and was introduced by A. Lindenmayer to help describe plants.
  12. Refer to the book The Algorithmic Beauty of Plants for full details of the
  13. work by Prusinkiewicz and Lindenmayer. Up to 80 definitions are stored
  14. internally, and can be saved as a text file, or a new file may be loaded.
  15.  
  16. Each shape definition is made up of the following components:
  17.  
  18. Name: 1-19 character name for identification.
  19.  
  20. Iterations: the number of times the algorithm is recursively expanded.
  21.  
  22. Angles: Rather than describing the amount of each turn as so many degrees,
  23. each turn is expressed as a fraction of a circle. Thus 6=60° (360°/6). The
  24. number should be even if you plan to use the '|' command to allow turns of
  25. 180°.
  26.  
  27. Axiom: a string of 1-255 characters incorporating turtle commands and rules.
  28.  
  29. Rules: a single letter identifier and 0-255 characters consisting of further
  30. rules or turtle commands. Note that the case of letters is significant.
  31.  
  32. The routine starts by taking the axiom string and then replaces each rule
  33. character in it by the equivalent rule string. This process is repeated
  34. for the number of iterations specified.
  35.  
  36. Thus if the axiom is F-F and the rule F=F+F, after the first expansion we
  37. get :  F+F-F+F, then F+F+F+F-F+F+F+F, and so on.
  38. After expansion the string is interpreted as a series of turtle commands,
  39. any rule characters being ignored. 
  40.  
  41. The key to the routine is this recursive expansion, and often the use of
  42. F as a rule and turtle command (which is somewhat confusing I admit, but
  43. very important).
  44.  
  45. Drawing
  46. -------
  47. Because the size of the image is unknown at the outset, the plot has to be
  48. repeated, with the image being correctly scaled to fit on the screen on the
  49. second pass. However you can use zooming or turn off Auto Scaling (see
  50. later), in which case only a single plot is performed.
  51.  
  52. Use Adjust to stop a plot. Note that currently it is not possible to restart
  53. a plot after Adjust is pressed. You are advised to start at low iterations
  54. and work up.
  55.  
  56. Basic Turtle Commands
  57. ---------------------
  58. The characters used are those in standard use. Note that 'F' is different
  59. from 'f'. (Fractint uses 'G' for 'f' since it is case insensitive).
  60. Initially the unit line length is 1 and the direction is along the x-axis.
  61.  
  62. F : draw a line forwards in the current direction and length.
  63. D : same as F, ie. draw a line forwards.
  64. f : move forwards without drawing a line.
  65. - : turn anti-clockwise 1 angle (see definition of angle above).
  66. + : turn clockwise 1 angle.
  67. | : turn 180°. Note - angle must be even for this to work correctly.
  68.  
  69. Advanced Turtle Commands
  70. ------------------------
  71. To get more complex displays requires the use of one or more these commands.
  72.  
  73. [  : stack the current position, angle, line length, width and colour.
  74. ]  : unstack the turtle details.
  75. !  : reverse meaning of '+' and '-'.
  76. cn : Set colour to n where n=0-255. See below for colour numbering.
  77. >n : increment colour by n where n is one or more digits.
  78. <n : decrement colour by n.
  79. @n : multiply the line length by n. The initial length is 1. 'n' is 1 or
  80.      more decimal digits and may contain a decimal place.
  81.      To divide precede the number by I (for inverse). eg. @I3 divides by 3,
  82.      or use @0.333. 
  83.      Precede the number by 'Q' for the square root, eg. @Q2 = length * 1.414
  84. #n : Multiply the line width by n - the initial width is a single pixel.
  85.      Numbers may be specified as for line length.
  86. {sprite} : Plots a sprite of this name at the current position and rotation.
  87.            The sprite is plotted the same size as the current line size.
  88.            See below for full details.
  89. {sprite,n} : As above but plots at the scale specified as 'n'.
  90.  
  91. Colour
  92. ------
  93. The initial colour is 255 (white in the default palette). To get a sensible
  94. progression of colours use the RGB palette.
  95.  
  96. If the colour exceeds 255 it wraps around. If a colour falls between 0-7
  97. when using < or >, then it is incremented/decrmented by 8, since colours 0-7
  98. are assumed to be too dark to be seen.
  99.  
  100. Menu Options
  101. ============
  102. The menu options are described next.
  103.  
  104. Data Entry Panel
  105. ----------------
  106. Use this panel to update the L-system data, or select a new L-system. To
  107. move the caret around the icons use !Fractal's standard editing keys. The
  108. various icons are:
  109.  
  110. Input: You must click on this for your changes to take effect.
  111.  
  112. Re-draw: This is the same as Input followed by a re-draw request.
  113.  
  114. Store: This takes the data and stores it in the internal file. If you move
  115. to another L-system without using this option your updates will be lost!
  116.  
  117. Restore: Refreshes the data on display from the copy in the internal file.
  118. This lets you back out changes without having to re-load the file.
  119.  
  120. Copy: Takes a copy of the current L-system so that you can edit it without
  121. modifying the original. You should give the copy a new name to avoid
  122. confusion.
  123.  
  124. Delete: Deletes the current L-system from the internal file.
  125.  
  126. Name: the 1-19 character identifier for this L-system.
  127.  
  128. Item: click on the left or right arrows to move to a different L-system.
  129. Remember to use Store if you want to keep any changes to the current
  130. L-system.
  131.  
  132. Iterations: Use the arrows to change or click on the number to key in a new
  133. value. Higher iterations give more complex patterns but will take much
  134. longer to draw.
  135.  
  136. Angle: determines the amount of turn for '+' and '-'.
  137.  
  138. Axiom: the 1-31 character string that is the initial rule.
  139.  
  140. Rules: Each rule must have a unique character for identification. Up to 9
  141. rules may be use, each of 0-79 characters. A null rule can be used to strip
  142. out turtle commands during expansion (see Cesaro for example). Remember to
  143. click Input or Redraw to enter your values.
  144.  
  145. L-System List Panel
  146. -------------------
  147. This panel lists all the L-systems that are held internally, showing the
  148. first 11 characters of their name with the current name being highlighted.
  149. Click on a name to select one. The predefined shapes all assume that the
  150. Default palette is in use - this is mainly of importance when plotting the
  151. plant shaped images.
  152.  
  153. Save
  154. ----
  155. The internal file of L-system definitions can be saved as a text file by
  156. dragging the text icon to a filer window. The associated sprites will be
  157. saved in the same directory if not already present. Saved definitions can be
  158. reloaded at any time - !Fractal will automatically select L-system if it is
  159. not the current fractal. Three files of definitions are supplied - click on
  160. Misc->Resouces to open a Filer window showing the files available.
  161.  
  162. You can edit the text file, but be careful to keep to the format which is:
  163.       L-System
  164.       sprite filename
  165.       Name=l-system name            } for each
  166.       Iter=iterations               } L-System
  167.       Angles=no. angles             }
  168.       Axiom=axiom string            }
  169.       ruleid=rule text              } 1 for each rule
  170.  
  171. The supplied definitions come from the Science of Fractals, Algorithmic
  172. Beauty of Plants, Fractint, and John Greening. Please send in more functions
  173. to AFG so we can all see them. I have added colour and sprites to some of
  174. the shapes.
  175.  
  176. Auto Scaling
  177. ------------
  178. When on this ensures that the image is automatically scaled to the maximum
  179. displayable size. Turn it off if you want to manually position the image -
  180. this is useful if you want to plot multiple shapes and place each at a
  181. certain position. To do this turn Image->Redraw->Clear off and manually set
  182. the x0/y0 (bottom left coords) and width/height values in the Image->Data
  183. panel. Remember that a unit length is 1 and plotting begins at 0,0. The best
  184. way to determine the values required for a shape is to draw the shape with
  185. auto scaling on, then use Display->X/Y Position to find the co-ordinates
  186. required.
  187.  
  188. The best way to create multiple shapes is to use the Script feature.
  189.  
  190. Fill
  191. ----
  192. When on invokes the CellFill function. This is useful for space filling
  193. curves such as the Hilbert or Peano, since it proves they are indeed just a
  194. single line. See the CellFill function for further details and options. 
  195.  
  196. Hints And Tips On Creating L-Systems
  197. ====================================
  198. To get an idea how L-systems work, look at the shapes prefixed 'Sier' and
  199. start at low iteration values. Note that shapes grow because a rule string
  200. contains more than one rule.
  201.  
  202. A good way to trace how a shape is built up is to add a colour change at the
  203. start or end of a rule, ie. add a >4 or >1. The different colours in the
  204. result show where a new copy of the rule was expanded. Try the colour
  205. cycling on this as well!
  206.  
  207. Shapes that are made up of lots of smaller copies of themselves are created
  208. by making the rules recursive, that is the rule string contains the same
  209. letter as the rule name (eg. F=FF) or a subsequent rule refers back to the
  210. first one (eg. F=AB, A=FB).
  211.  
  212. To set the initial direction, width or colour, place the required turtle
  213. commands in the Axiom. The initial direction is to the right so use '-' to
  214. make a shape start plotting upwards. That way they are only executed once -
  215. see Bush3 for an example.
  216.  
  217. The stack is a very powerful feature and worth experimenting with - it is
  218. the key to shapes that feature points, such as the plant examples. It also
  219. allows you to create a sub-shape with its own colour, size and width which
  220. may be placed anywhere within the main pattern. See Tree3 which uses 'L' for
  221. the Leaf rule. Typically these sub-shapes are placed at the end of a stacked
  222. sequence - PlantLeaf uses [--L] to place a leaf at the tip at particular
  223. points.
  224.  
  225. Two draw commands (F and D) are provided so that one may be expanded (by
  226. making the command a rule) and the other unexpanded. Tree3 uses this to
  227. allow the leaves to be drawn the same size. If the L rule used 'F' for
  228. drawing, the 'F' rule would expand making the leaf larger depending on where
  229. it was drawn - try it and see.
  230.  
  231. The length command (@) is generally used to make successive parts of the
  232. shape relatively smaller. See Tree1 for example which uses it to make the
  233. branches smaller and smaller. A similar effect can be achieved by using a
  234. rule of the form F=FF - at higher iterations each F character is expanded
  235. into more F draw commands.
  236.  
  237. Use the width command (#) to give body to plant and tree shapes for extra
  238. reality.
  239.  
  240. Sprites
  241. =======
  242. The sprite plotting feature is a powerful extension to the normal command
  243. syntax. Instead of using F to draw a line specify the name of a sprite, which
  244. will be plotted at the same length as the line and at the same rotation. To
  245. avoid long rule lines it can be useful to use a rule for a sprite eg.
  246.          P=+T-TT++T
  247.          T={trunk}
  248. Plotting with sprites will take longer, and it is often better when creating
  249. a new shape to start off with the outline, then substitute the sprites at a
  250. later time.
  251.  
  252. Creating Sprites
  253. ----------------
  254. The following guidelines must be followed for plotting to work correctly.
  255. The sprites are contained in a sprite file in the same directory as the
  256. L-system definitions. The name of the sprite file is specified in the second
  257. line of the L-system definition file.
  258.  
  259. The supplied sprite file is called "L-Sprites" - click on Misc->Resources to
  260. locate. Look at the example sprites provided to get an idea of the
  261. requirements, which are:
  262.  
  263. 1) The sprite must be square and should be a multiple of 4 pixels in size.
  264.  
  265. 2) A 256 colour must be chosen that has square pixels, such as mode 21 or
  266. mode 13.
  267.  
  268. 3) The sprite should be created with a mask. All pixels that are not to be
  269. plotted should be set to the mask colour so these pixels become transparent.
  270.  
  271. 4) When creating the shape bear in mind that top is to the right since that
  272. is the initial direction of plotting. You may find it easier to create the
  273. shape and rotate it 90° clockwise.
  274.  
  275. 5) Since the sprite gets rotated, pixels in the corners will tend to get
  276. lost at angles other than 0,90,180 & 270 degrees. To avoid black space
  277. however, you will normally need to set pixels up to the edge of the sprite.
  278.  
  279. The above rules are necessary because of the scaling and rotation that is
  280. performed. If you get strange results, check that you have followed these
  281. guidelines. The main limitation on the size of sprites is the amount of
  282. memory in your computer. Large sprites will soon consume all that is
  283. available. Sizes from 16-64 pixels should be adequate for most purposes.
  284. Larger sprites will tend to look better when scaled and rotated - small
  285. sprites will look more distorted. To maintain clarity try to avoid too much
  286. detail in the sprite.
  287.  
  288. To reload a sprite file after editing, simply drag its Filer icon onto a
  289. !Fractal window/icon, or drag the Save icon from !Paint.
  290.  
  291. Using Sprites
  292. -------------
  293. The sprite name is specified by {spritename} in a rule definition. If the
  294. sprite cannot be found, it is ignored. The sprites are displayed at the
  295. current line scale no matter how large the sprite is. To plot the sprite at
  296. a different relative size use {spritename,9.9} where '9.9' is the scaling
  297. factor.
  298.  
  299. The size of sprites is also controlled by the line length specifier '@' -
  300. this allows sprites to be plotted at increasingly smaller (or larger) sizes
  301. which is useful for plant like shapes.
  302.  
  303. Sprites can be used with the all the other plotting commands, though the
  304. colour and width commands do not affect the sprite. Interesting effects can
  305. be achieved by taking the shapes provided and replacing the 'F' commands by
  306. a sprite. To do this it will be necessary to preserve the recursive nature.
  307. Thus if the original rule was F=F+F-, then the replacement rule would need
  308. to be S=S{sprite}+S{sprite}-.
  309.  
  310. To avoid out of memory conditions it is best to use a number of L-system
  311. definition files with their own sprite files. To create a new file delete
  312. the entries not required, and save the remaining definitions under a new
  313. filename. Then edit the text file to specify a new sprite file name.
  314.