turtles-own [dist ;; distance from 'goal' in current state old-dist ;; distance from 'goal' in last state intx ;; x-intersection (for parabola) inty ;; y-intersection (for parabola) diff ;; modified distance to x and y intercepts in current state old-diff] ;; modified distance to x and y intercepts in last state globals [cx ;; x-cor of the circle's center cy ;; y-cor of the circle's center f0x ;; x-cor of focus 0 (for ellipse) f0y ;; y-cor of focus 0 (for ellipse) f1x ;; x-cor of focus 1 (for ellipse) f1y ;; y-cor of focus 1 (for ellipse) state] ;; flag to alternate between different values with WatchMouse to setup ca set cx 0 set cy 0 set f0x 0 set f0y 0 set f1x 0 set f1y 0 set state 0 set (pcolor-of patch 0 0) white crt num-turtles ask turtles [ set color green setxy random-float screen-size-x random-float screen-size-y ] end to change-focus end to watchmouse ;; turns focus white where mouse is clicked if mouse-down? [ ask patches [ set pcolor black ] set cx (round mouse-xcor) set cy (round mouse-ycor) set (pcolor-of patch-at cx cy) white ] end to watchmouse2 ;; turns two foci white locals [ mousex mousey ] if mouse-down? [ set mousex (round mouse-xcor) set mousey (round mouse-ycor) if pcolor-of patch-at mousex mousey = white [ stop ] ask patches [ set pcolor black ] ifelse (state = 0) [set f0x (round mouse-xcor) set f0y (round mouse-ycor) set state 1] [set f1x (round mouse-xcor) set f1y (round mouse-ycor) set state 0] set (pcolor-of patch-at f0x f0y) white set (pcolor-of patch-at f1x f1y) white ] end to go ifelse mouse-down? [ ifelse not second-focus? [watchmouse] [watchmouse2] ] [ ask turtles [ move-turtles ] ] end to move-turtles ; turtle procedure set old-dist dist ifelse not second-focus? [set dist (distancexy-nowrap cx cy)] [set dist ((distancexy-nowrap f0x f0y) + (distancexy-nowrap f1x f1y)) / 2] ifelse ((int dist) = constant) [stop] [ifelse ((dist < old-dist) and (dist > constant)) [fd 1] [ifelse ((dist > old-dist) and (dist < constant)) [fd 1] [rt random-float 360 fd 1]]] 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 Conic Sections model. ; http://ccl.northwestern.edu/netlogo/models/ConicSections. ; 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/ConicSections ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 321 10 641 351 15 15 10.0 1 10 1 1 1 CC-WINDOW 322 350 623 472 Command Center SLIDER 15 105 281 138 num-turtles num-turtles 1 300 200 1 1 NIL SLIDER 21 154 281 187 constant constant 0 20 9 1 1 NIL BUTTON 42 50 103 84 NIL setup NIL 1 T OBSERVER SWITCH 88 209 241 242 second-focus? second-focus? 0 1 -1000 BUTTON 114 50 195 84 NIL go T 1 T OBSERVER TEXTBOX 81 324 228 375 To set a focus, click the mouse on a patch. @#$#@#$#@ WHAT IS IT? ----------- The model displays two basic conic sections: circles and ellipses. The figures are generated behaviorally as opposed to algebraically -- the turtles attempt to behave like points on the specified shape. A circle is the set of all points at a certain distance (radius) from a central point. An ellipse is the set of points such that the sum of the distances to two points is constant. These two points are called foci. The CONSTANT slider corresponds to the radius for circles and to the sum of distances to the foci for each turtle. As an illustration of this, imagine a string loosely looped around two nails, each representing a focus. If you pull the string tight with a pencil point and move the pencil point around the foci, you will draw an ellipse. The ancient Greeks discovered that each conic section can be found by taking a cross section of one or two cones with their points pointing toward each other. A circle results from taking a slice that is perpendicular to the axis, while an ellipse results from taking a slice of one cone that is not perpendicular to the axis. Similiarly, a parabola results from a cross section that passes through one cone in a vertical fashion, such that the plane of the cut is parallel to one face. A hyperbola results from a vertical section that passes through both cones. The turtles use feedback to make decisions about how they behave. They set out in random directions, and then they receive information as to whether or not they are getting closer to where they want to be. If they are getting closer, they continue moving forward in the direction they are going. If they are moving farther away, they set out in a new random direction. This process is akin to the children's game of "Hot & Cold", in which players are told whether they are getting "hotter" or "colder" in relation to a hidden goal. HOW TO USE IT ------------- *Circles: -Select the number of turtles with the TURTLES slider. -Press SETUP. -Make sure the SECOND-FOCUS switch is set to OFF. -Press the MOVE-TURTLES button. Adjust the radius of the circle with the CONSTANT slider. The turtles will automatically correct themselves as you change both CONSTANT and the location of the center. You can change the circle's center by clicking on a new point. *Ellipses: -Select the number of turtles with the TURTLES slider. -Press SETUP. -Make sure the SECOND-FOCUS switch is set to ON. -Press the MOVE-TURTLES button. As for a circle, the size of the ellipse can be modified with CONSTANT, and new foci can be picked by clicking the mouse. THINGS TO NOTICE ---------------- When forming a circle, turtles try to attain a distance of CONSTANT (a value determined by the user with a slider) from a center that the user determines by pointing and clicking (as explained above). When forming an ellipse, turtles try to attain a combined distance of 2 * CONSTANT from the two foci, again determined by the user's points and clicks. If the foci are too far apart, there be no way to satisfy this condition. What do the turtles do then? THINGS TO TRY ------------- You may be able to get a better feeling for the turtles' behavior if only a few turtles are on-screen at one time. Try setting num-turtles to a smallvalue (like 16 or 1) and watching the turtles. Both of these conic sections can be observed by shining a flashlight at a cone and looking at its shadow. Can you figure out at what angles the cone must be held? EXTENDING THE MODEL ------------------- If you have access to StarLogoT (NetLogo's Macintosh-only predecessor), look at the StarLogoT model 'emergent-circle'. Watch how the turtles react with each other- something that is missing from 'Conic Sections'. Implement this emergent behavior for one or both of the conics in this project. NETLOGO FEATURES ----------------- Like more traditional programming languages (e.g. C++), NetLogo can have functions that report a value to the caller. The function used here is called 'location'-- it has two inputs, an x-coordinate and a y-coordinate. In this model, it reports true or false. It is set up using "to-report" and "report". CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Conic Sections model. http://ccl.northwestern.edu/netlogo/models/ConicSections. 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/ConicSections for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 @#$#@#$#@ NetLogo 2.0alpha1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@