home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Include / fractal.js < prev    next >
Encoding:
JavaScript  |  2002-05-13  |  2.4 KB  |  74 lines

  1. /***************************************************************
  2. ADOBE SYSTEMS INCORPORATED 
  3. Copyright 2002 Adobe Systems Incorporated 
  4. All Rights Reserved 
  5.  
  6. NOTICE:  Adobe permits you to use, modify, and distribute this 
  7. file in accordance with the terms of the Adobe license agreement 
  8. accompanying it.  If you have received this file from a source 
  9. other than Adobe, then your use, modification, or distribution
  10. of it requires the prior written permission of Adobe. 
  11. ***************************************************************/
  12. /***************************************************************
  13. Author: Mary Obelnicki
  14. ***************************************************************/
  15.  
  16. /***************************************************************
  17.  
  18. This function takes the path <aPath> and recursively replaces the 
  19. line segments in the path creating a fractal of the given depth. 
  20.  
  21. Arguments:
  22.  
  23. aPath
  24.     the path to turn into a fractal
  25. replaceFunction
  26.     the function the specifies how to change a line segment 
  27.     in for a fractal.  A <replaceFunction> must take specific arguments.
  28.      <argument1>
  29.          the path to edit
  30.      <argument2> 
  31.          the index of the first knot of the line segment on the path
  32.      <argument3>
  33.          the index of the second knot of the line segment on the path
  34.      <argument4> 
  35.          an array of the knots, the indexes of the knots
  36.         will be the same in the path and the array. This argument is 
  37.         optional and used for optimization.  getting the array of 
  38.         knots from the path can be very time consuming. 
  39.  
  40. depth
  41.     how many times to recursively replace the path's line segments. 
  42.  
  43. ***************************************************************/
  44.  
  45. /***************************************************************
  46. DO NOT EDIT BELOW THIS LINE
  47. ***************************************************************/
  48.  
  49. function fractal(aPath, replaceFunction, depth)
  50. {
  51.     //for each depth
  52.     var curDepth = 0; 
  53.     for(curDepth = 0; curDepth < depth; curDepth++)
  54.     {
  55.     var theKnots = aPath.knots; 
  56.     var numOfKnots = theKnots.length; 
  57.     var curKnot; 
  58.  
  59.     if (aPath.closed)
  60.         curKnot = numOfKnots-1; 
  61.     else
  62.         curKnot = numOfKnots-2;
  63.     //for every line segment
  64.  
  65.     for( ; curKnot >= 0; curKnot--)
  66.     {
  67.         //call the function
  68.         replaceFunction(aPath, curKnot, (curKnot+1)%numOfKnots, theKnots);
  69.     }
  70.     }
  71. }
  72.  
  73.  
  74.