---party-xvila.nlogo
来自「NETLOGO」· NLOGO 代码 · 共 387 行
NLOGO
387 行
turtles-own [man? woman? happy?]patches-own [men women people]globals [boring-groups moves number-happy group-sites]to setup ca set group-sites patches with [group-site?] set-default-shape turtles "person" cct number [ set size 3 ;; makes them easier to see ;;blue represents male, pink represents female. No stereotypes are meant ;;to be promoted. Simply change the colors right here if you'd like. ifelse (random 2 = 0) [set man? true set woman? false set color blue] [set man? false set woman? true set color pink] ifelse (random 2 = 0) [set heading 90] [set heading 270] ;; randomly face right or left set ycor 0 set xcor random screen-size-x ] ask turtles [move-into-groups] setup-patches setup-plots set moves 0 update-labels spread-people update-plotsendto setup-patches ask patches [ set men 0 set women 0 set people 0] ask turtles [ if man? [set men (men + 1)] if woman? [set women (women + 1)]] ask patches [ set people (men + women)] update-happiness update-boring-groupsendto go if (number-happy = number) [ stop ;; stop the simulation if everyone is happy ] group-people ;; put all people on the x-axis update-happiness move-if-unhappy update-boring-groups update-labels spread-people ;; move the people into vertical columns set moves (moves + 1) update-plots if limit-speed? [ wait 0.75 ] ;; keep the spread groups on the screen for a bitendto update-labels ask group-sites [ set plabel count turtles-here ]endto update-happiness ask patches [ set people (men + women)] ask turtles [ ;;; you are happy if the proportion of people of the opposite sex does not exceed your tolerance if man? [ifelse (women / people) > (tolerancem / 100) [set happy? false] [set happy? true]] if woman? [ifelse (men / people) > (tolerancew / 100) [set happy? false] [set happy? true]] ;; if (happy? = true) [set num-happy (num-happy + 1)] ] set number-happy count turtles with [happy?] ;; update number-happy variableendto move-if-unhappy ask turtles [ if (not happy?) [ifelse man? [set men men - 1] ;;decrease the count in your old group [set women women - 1] ifelse (random 2 = 0) [set heading 90] [set heading 270] ;; randomly face right or left fd 1 ;; move out of your group move-into-groups ifelse man? [set men men + 1] [set women women + 1]]] ;;increase the count in your new in groupendto move-into-groups ;;turtle procedure ; move forward until you hit the closest group if not group-site? [ fd 1 if limit-speed? [ wait 0.1 ] ;; slow it down so user can see it happening move-into-groups]endto-report group-site? ;; turtle or patch procedure ;; if your pycor is 0 and your pxcor is where a group should be located, ;; then you're a group site (patch) or on a group site (turtle). ;; first figure out how many patches apart the groups will be let group-interval floor (screen-size-x / num-groups) report ;; first check pycor (pycor = 0) and ;; then check if the distance between groups divides evenly into ;; our distance from the right hand edge of the screen (((screen-edge-x - pxcor) mod group-interval) = 0) and ;; finally, make sure we don't wind up with more groups than ;; the user asked for (floor ((screen-edge-x - pxcor) / group-interval) < num-groups)endto update-boring-groups ask group-sites [ set plabel-color white if people > 0 [if ((men = 0) or (women = 0)) [set plabel-color gray]]] set boring-groups (count group-sites with [plabel-color = gray])endto setup-plots set-current-plot "Happy Partygoers" set-plot-y-range 0 numberendto update-plots set-current-plot "Happy Partygoers" set-current-plot-pen "Happy" plot (count turtles with [happy?]) set-current-plot "Single Sex Groups" plot boring-groupsend;; spread people out vertically to spread-people ask turtles [ifelse man? [set heading 0 fd 2] [set heading 180 fd 2] jump count other-turtles-here] ;; this trick works because of the serial ordering of turtle executionend ;; pile people up on the x-axis to group-people ask turtles [set ycor 0]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 1997 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. (1997). NetLogo Party model.; http://ccl.northwestern.edu/netlogo/models/Party.; 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/Party; for terms of use.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW2191056149341564.01141110CC-WINDOW5507812602Command CenterBUTTON7107543setupsetupNIL1TOBSERVERTNILBUTTON7477580gogoT1TOBSERVERTNILBUTTON78475117step-oncegoNIL1TOBSERVERTNILMONITOR721563264movesmoves01SLIDER771020343tolerancemtolerancem0.099.026.01.01%SLIDER77122200155numbernumber03007511NILMONITOR69215173264number-happynumber-happy01MONITOR24266142315single-sex-groupsboring-groups01PLOT56010803250Happy Partygoersmovesnumber0.010.00.0150.0truefalsePENS"Happy" 1.0 0 -11352576 truePLOT559256802458Single Sex Groupsmovesseg-groups0.010.00.012.0truefalsePENS"Single Sex" 1.0 0 -65536 trueSLIDER7784200117num-groupsnum-groups5201011NILSWITCH28167161200limit-speed?limit-speed?01-1000SLIDER784820581tolerancewtolerancew0.099.026.01.01%@#$#@#$#@WHAT IS IT?-----------*********Copyright Xavier Vil
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?