home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************
- ADOBE SYSTEMS INCORPORATED
- Copyright 2001 Adobe Systems Incorporated
- All Rights Reserved
-
- NOTICE: Adobe permits you to use, modify, and distribute this
- file in accordance with the terms of the Adobe license agreement
- accompanying it. If you have received this file from a source
- other than Adobe, then your use, modification, or distribution
- of it requires the prior written permission of Adobe.
- ***************************************************************/
- /***************************************************************
- Author: Mary Obelnicki
- ***************************************************************/
-
- /***************************************************************
-
- Description goes here
-
- ***************************************************************/
-
- #include "../../Include/Vector.js"
- #include "../../Include/fractal.js"
-
- /***************************************************************
- To change the behavior of this script,
- make your changes below
- ***************************************************************/
-
- //will draw a kochSnowflake with radius 200, depth 2;
- var comp = application.currentComposition;
- var diameter = Math.min(comp.size.x, comp.size.y);
- kochSnowflake(diameter/2, 3, comp.size.x/2, comp.size.y/2);
-
- /***************************************************************
- DO NOT EDIT BELOW THIS LINE
- ***************************************************************/
-
-
- function kochSnowflake(radius, depth, x, y)
- // draws a koch snowflake of depth <depth> with a radius of <radius>.
- {
- // create the base triangle
- var basePath = kochSetup(radius, x, y);
- //call the fractal function on the base triangle
- fractal(basePath, kochReplaceLine, depth);
- }
-
- function kochSetup(rad, inX, inY)
- //draws an equalateral triangle path object on a circle of radius <rad>.
-
- //returns: the path that is the triangle (not the object).
- {
- //draw the initial triangle
- var triangle = application.currentComposition.createObject(LMGeometricType.path, inX, inY);
-
- var anglePerPoint = 2*Math.PI/3;
- var angleOffset = Math.PI/2; // so a point is straight up
- var startAngle = 0 + angleOffset;
-
- //point 0
- var path = triangle.addPath(rad*Math.cos(startAngle), -rad*Math.sin(startAngle), 0);
- triangle.deletePath(1);
-
- //point 1
- path.addKnot(rad*Math.cos(startAngle-anglePerPoint), -rad*Math.sin(startAngle-anglePerPoint), 1);
-
- //point 2
- path.addKnot(rad*Math.cos(startAngle-2*anglePerPoint), -rad*Math.sin(startAngle-2*anglePerPoint), 2);
- path.closed = true;
- return path;
-
- }
-
- function kochReplaceLine(path, knotOneIndex, knotTwoIndex, knotsArray)
- //path: the path to edit
- //knotOne: the index of the first knot in the line segment
- //knotTwo: the index of the second knot in the line segment
- //knotsArray: an array containing the knots, the index of <knotOne>
- //<knotTwo> must be the same in <knotsArray> and <path>.knots.
- // an optional arguement for speed
- {
- //vectors representing the defining points of the line segment.
- var p1;
- var p2;
- if (arguments.length == 4)
- {
- p1 = new Vector(knotsArray[knotOneIndex].position.x, -knotsArray[knotOneIndex].position.y);
- p2 = new Vector(knotsArray[knotTwoIndex].position.x, -knotsArray[knotTwoIndex].position.y);
- }
- else
- {
- p1 = new Vector(path.knots[knotOneIndex].position.x, -path.knots[knotOneIndex].position.y);
- p2 = new Vector(path.knots[knotTwoIndex].position.x, -path.knots[knotTwoIndex].position.y);
- }
-
- //the line segment
- var p2minusp1 = Vector.subtract(p2, p1);
- //one thrid of the line segment
- var segment = Vector.scalerMult(p2minusp1, 1/3);
-
- //add the three knots to the path to chage the line segment to the next depth
- // of the koch snowflake.
-
- //the first knot
- var pointA = Vector.add(p1, segment);
- path.addKnot(pointA.x, -pointA.y, knotOneIndex+1);
-
- //the second knot
- var pointC = Vector.add(pointA, Vector.zAxisRotate(segment, Math.PI/3));
- path.addKnot(pointC.x, -pointC.y, knotOneIndex+2);
-
- //the thrid knot
- var pointB = Vector.add(pointA, segment);
- path.addKnot( pointB.x , -pointB.y, knotOneIndex+3);
-
- }
-