globals [ time ] turtles-own [ x-cor y-cor z-cor ] to setup ca set time 0 set-default-shape turtles "circle" cct number [ ;; randomly distribute the turtles over the xy plane set x-cor random-float 40 - 20 set z-cor random-float 40 - 20 set y-cor 0 move render ] end to go set time time + 1 ask turtles [ move render ] end to move ; turtle procedure set y-cor ( 5 * cos ( 5 * ( time + x-cor ) ) ) + ( 5 * cos ( 5 * ( time + z-cor ) ) ) end to render ; turtle procedure ; convert 3-space coordinates to screen coordinates setxy (x-cor + ( z-cor / 2 )) (y-cor + ( z-cor / 2 )) ; make lightness/darkness proportional to height, for added 3D effect set color scale-color blue y-cor -12 10 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 1998 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 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo 3D Surface model. ; http://ccl.northwestern.edu/netlogo/models/3DSurface. ; 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/3DSurface ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 278 23 612 378 40 40 4.0 1 10 1 1 1 CC-WINDOW 11 170 265 365 Command Center BUTTON 63 47 130 80 NIL setup NIL 1 T OBSERVER BUTTON 142 47 209 80 NIL go T 1 T OBSERVER SLIDER 11 104 264 137 number number 10 1500 120 10 1 NIL @#$#@#$#@ WHAT IS IT? ----------- This model maps turtles between Cartesian and spherical 3-dimensional coordinates. To create the appearance of a curved 3D surface, the program generates turtles with random x- and z-coordinates, then computes each turtle's y-coordinate based on x and z, and time. The cosine function is used in the formula to produce a curved surface. Varying the y coordinate based on time produces motion. To render the surface in the NetLogo graphics window, it maps from 3D to 2D coordinates as follows: screen x = turtle x + (turtle z) / 2 screen y = turtle y + (turtle z) / 2 In other words, increasing z causes the turtle's apparent position to move both up and to the right. HOW TO USE IT ------------- Click the SETUP button to generate the turtles and place them on the surface. Click the GO (forever) button to run the model, which continuously varies the turtles' y-coordinates to generate a wavelike motion. The NUM-TURTLES slider determines the number of turtles that make up the surface. THINGS TO NOTICE ---------------- Notice that as the turtles move down (y-coordinate decreases) they become darker in color, and when they move up (y-coordinate increases) they become lighter. THINGS TO TRY ------------- Experiment with the NUM-TURTLES slider. How many turtles are needed to produce a realistic effect? Why doesn't it keep getting better-looking indefinitely as you add more turtles? In the "move" procedure, try other numbers besides 5 in front of and inside the cosine function. Explain the new behavior! to move ; turtle procedure set y-cor ( 5 * cos ( 5 * ( time + x-cor ) ) ) + ( 5 * cos ( 5 * ( time + z-cor ) ) ) end EXTENDING THE MODEL ------------------- Try changing the formula used to compute the y-coordinate to produce differently shaped surfaces. See if you can draw not just a surface, but a three dimensional shape such as a cone or a sphere. LANGUAGE FEATURES ----------------- Notice the use of SCALE-COLOR to change a turtle's color based on its y-coordinate. Also see the model "Wave Machine" for a version that uses patches rather than turtles to make a 3-D membrane. CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (2001). NetLogo 3D Surface model. http://ccl.northwestern.edu/netlogo/models/3DSurface. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 2001 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/3DSurface for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 circle false 0 Circle -7566196 true true 35 35 230 @#$#@#$#@ NetLogo 2.0alpha1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@