turtles-own [ star-side ;; The length of the side that the turtle is drawing moves ;; The number of moves it has made (i.e. sides it has drawn) generation ] ;; How many generations of turtles have come before it. So, ;; if the turtle was hatched from a turtle that was hatched ;; by another turtle, it's generation is 2 globals [ first-fd ;; The distance the first turtle should initially walk upwards to get in position the-color ] ;; The color the turtles draw in to setup ca crt 1 set first-fd (screen-edge-y * .9) set the-color red ask turtles [ set size 15 ;; so turtles are easy to see set moves 0 set star-side (first-fd * 1.97538) ;; Calculate the length of the sides of the triangle it will draw set heading 0 set generation 0 ;; The greater the generation, the lighter the color set color scale-color the-color (fractal-level - generation) -1 (fractal-level + 1) fd first-fd ;; Walk upwards to the position it will start in pendown rt 180 rt 18 ] plot-num-turtles end to go set moves moves + 1 fd star-side if(moves >= 6) [die] ;; When the turtle has completed its star, it's done rt 180 rt 36 if(generation < fractal-level) ;; If it's not drawing at the deepest level of the figure, [hatch 1 ;; hatch a new turtle to draw at a lower level [set generation generation + 1 set star-side (star-side / 2) set color scale-color the-color (fractal-level - generation) -1 (fractal-level + 1) set moves 0 rt 18] ] plot-num-turtles end to plot-num-turtles set-current-plot "Num Turtles V. Time" plot (count turtles) end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1999 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2001. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1999). NetLogo Star Fractal model. ; http://ccl.northwestern.edu/netlogo/models/StarFractal. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/StarFractal ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 274 10 686 443 100 100 2.0 1 10 1 1 1 CC-WINDOW 4 397 272 535 Command Center BUTTON 146 42 211 75 go go T 1 T TURTLE T SLIDER 32 88 248 121 fractal-level fractal-level 0 4 3 1 1 NIL BUTTON 69 42 133 75 setup setup NIL 1 T OBSERVER T MONITOR 105 128 177 177 turtles count turtles 3 1 PLOT 2 179 272 394 Num Turtles V. Time Time Num Turtles 0.0 50.0 0.0 20.0 true false @#$#@#$#@ WHAT IS IT? ----------- This model creates a fractal-like structure consisting of stars drawn at various scales, the number of which is specified by the user. The structure is drawn by generations of turtles that draw stars at a given scale and hatch successive generations to draw new ones at smaller scales. HOW TO USE IT ------------- The FRACTAL-LEVEL slider controls the number of levels the structure is drawn in. For instance, a fractal level of 0 results in a single star, while a fractal level of 1 draws a star with smaller stars that begin at each of its 5 corners. This pattern is repeated as the level increases. RUNNING THE MODEL ----------------- Click the SETUP button to initialize the structure and GO to begin drawing it. THINGS TO NOTICE ---------------- The figure drawn embodies the most important fractal quality: self-similar structure at smaller scales. This means that no matter how far you "zoom in" to it, you will still see the same shape (namely, a star). The fractal level determines to how small a scale this property holds, so the greater the level the more you can "zoom in" and still see stars. Notice that at a fractal level greater than 1, the model begins with one turtle, which hatches new turtles at each corner, and these turtles similarly hatch new ones at each of their corners as well. This behavior is made possible by a powerful mathematical technique called recursion. A process is called recursive when its workings involve "performing itself". In this case, the process performed by each turtle at each step is to draw a new side of its star and then create new turtles to perform the very same process. A helpful property of recursive processes is that the instructions are often short, because each performer is executing the same instructions. Hence the brevity of Star Fractal's procedures. The ideas behind fractal scaling (the property of self-similar structures at different scales) and recursion are essentially the same. This is suggested by the fact that a recursive process is able to generate a fractal-like structure, as in this model. One way to think about it is that recursion applies these ideas to processes (like NetLogo programs), and fractal scaling applies them to physical or mathematical structures (like the figure drawn by Star Fractal). THINGS TO TRY ------------- Edit GO so that it's not a forever button and note what happens at each time step. Notice that what begins as a single drawing multiplies into many drawings, each of which is at a smaller scale but proceeds exactly like the larger one that spawned it. Thus, recursion begets self-sameness at different scales. Try the model initially with small fractal levels and work your way up to higher ones. Try to figure out how many more stars are incorporated into the figure each time the level increases by one. What kind of general rule you can come up with? That is, given a generation of turtles g, how many turtles will be in the generation g + 1? Start from g = 0 (This is a recursive rule.) EXTENDING THE MODEL ------------------- In increasing order of difficulty: Change the color scaling so that the smaller stars are brighter than the larger ones. Change the model so that it draws shapes other than stars. Will any shape work? The structure that this model draws is only "fractal-like", because even when you "zoom in" and look at smaller scales, the smaller stars aren't actually part of the larger ones; they're just connected to them at a vertex. An important property of fractals is that the larger structures are composed of the smaller ones, something which clearly doesn't hold here. For a tougher exercise, try changing the model so that the smaller stars (or whatever shapes are being drawn) are actually part of the larger ones, for instance by drawing them in the middle of their sides. Such a figure will be a lot less "noisy" than this one, in terms of how difficult it is to discern individual stars, and it will have different properties when you zoom in. NETLOGO FEATURES ----------------- This model makes use of an important NetLogo command: "hatch". Hatch allows one turtle to create a new one on the same patch and give it some initial instructions. In this case, the parent turtle sets the length of the star its offspring will draw, its initial heading, and several other variables. Notice that the new turtle uses the values of its parent turtle's variables in the body of the hatch procedure. Another useful primitive this model uses is "scale-color". It is used to make the brightness of the color the turtles are drawing inversely proportional to the turtle's generation, so that larger stars are brighter than smaller ones (this was done to make the larger ones more visible). The call "scale-color the-color (fractal-level - generation) -1 (fractal-level + 1)" works as follows: Subtract the value of GENERATION from that of FRACTAL-LEVEL. The higher that resulting value is on the scale from -1 to (FRACTAL-LEVEL + 1), the darker the shade of THE-COLOR the turtle will draw with. CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (1999). NetLogo Star Fractal model. http://ccl.northwestern.edu/netlogo/models/StarFractal. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1999 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/StarFractal for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 arrow true 0 Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box true 0 Polygon -7566196 true true 45 255 255 255 255 45 45 45 circle true 0 Circle -7566196 true true 35 35 230 person false 0 Circle -7566196 true true 155 20 63 Rectangle -7566196 true true 158 79 217 164 Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110 Polygon -7566196 true true 216 83 267 123 248 143 215 107 Polygon -7566196 true true 167 163 145 234 183 234 183 163 Polygon -7566196 true true 195 163 195 233 227 233 206 159 spacecraft true 0 Polygon -7566196 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135 thin-arrow true 0 Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150 truck-down false 0 Polygon -7566196 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30 Polygon -8716033 true false 195 75 195 120 240 120 240 75 Polygon -8716033 true false 195 225 195 180 240 180 240 225 truck-left false 0 Polygon -7566196 true true 120 135 225 135 225 210 75 210 75 165 105 165 Polygon -8716033 true false 90 210 105 225 120 210 Polygon -8716033 true false 180 210 195 225 210 210 truck-right false 0 Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165 Polygon -8716033 true false 210 210 195 225 180 210 Polygon -8716033 true false 120 210 105 225 90 210 turtle true 0 Polygon -7566196 true true 138 75 162 75 165 105 225 105 225 142 195 135 195 187 225 195 225 225 195 217 195 202 105 202 105 217 75 225 75 195 105 187 105 135 75 142 75 105 135 105 @#$#@#$#@ NetLogo 2.0beta4 @#$#@#$#@ setup repeat 25 [ ask turtles [ go ] ] @#$#@#$#@ @#$#@#$#@