![]() % Draws the triangle for each iteration and calls itself. % transparency = number between 0 and 1 transparency of each triangleĭrawTriangles(1,0,angleIncrement,r,r,lengthDecrement,transparency)įunction drawTriangles(len,angle,angInc,iterations,r. % lengthDecrement = number amount triangle shrinks each iteration % angleIncrement = number amount the triangle rotates each iteration % Draw a fractal triangle, with the following inputs: Take a look, and let me know if you have any questions!įunction fractalTriangle(r,angleIncrement,lengthDecrement,transparency) The inputs for fractalTriangle are described in the code below. We should have something that looks like this: So our draw subfunction will calculate the three points of the current triangle, based on the current length and angle parameters, and draw the triangle on top of the existing triangles. We want to rotate the triangle with each iteration, and also shrink it slightly. Then we simply draw lines between them using the plot command. Since we know that the three points of an equilateral triangle are separated by 120 degrees, we can simply rotate our first point to get our second and third points. It shows us the structure of the program we want to write, but will not run because the details haven't been filled in.įunction mainFunction (totalNumberOfIterations)įunction drawingFunction(remainingIterations)įor this example, we again harness the power of rotation! We want to draw a triangle centered around the origin. Note that the 'code' you see here is not really code at all. Thus, with a simple call to mainFunction you can draw an entire fractal structure! The only difference is that it calls itself with one less iteration. Then, importantly, drawingFunction calls itself. drawingFunction does the job of drawing your recursive structure, and takes as an input the number of recursions you want. ![]() Let's call it drawingFunction and color it blue in the example program below. In mainFunction, you call a second function- a sub-function. You begin with a function that will compute any global variables and compute and any non-iterative components of the drawing. The basic structure for each of these programs is very similar, so let's go over that first. Be warned: the greater the recursive depth, the longer the code will take to execute! You most likely won't have time in this class to code up your own recursive drawing, but you're encouraged to choose one of the patterns below and try changing a few parameters. Let's examine some of these deceptively simple-looking images. Perhaps the simplest fractals are created by the process of recursively drawing a particular pattern. In the Line format box, make the changes you want, such as changing the line width, color, kind of arrow, or type of line.You can only get so far into mathematical art without mentioning fractals! As a review, a fractal is an image for which the same structre is evident at any level of resolution. Right-click the line, click Format, and then click Line. You can add more line segments to the one you just drew. On the Home tab, in the Tools group, click the Down Arrow to expand the Drawing Tools menu. In the Format Shape pane, click Line and make the changes you want, such as changing the line width, color, kind of arrow, or type of line. Right-click the line and click Format Shape. Drag one of the end points to change the line’s direction or make it longer or shorter. Each segment glues to the end point it starts from, so that the lines together act like a single shape. Start at one end point of the existing line. To add more line segments to the one you just drew, use the ribbon instead.Ĭlick Home > Tools > Drawing Tools > Line. Ĭlick where you want to start drawing the line, hold the mouse button and move your pointer to where you want the line to end, then release the mouse button. When the Line tool is on, your pointer changes to. ![]() Right-click the drawing and on the floating toolbar, click the Drawing Tools list and then click the Line tool or the Pencil tool.
0 Comments
Leave a Reply. |