170 likes | 302 Vues
New Mexico Computer Science For All. Breeds and Shapes in NetLogo Maureen Psaila-Dombrowski. Breeds in NetLogo. Predefines Four Types of agent Turtles Patches Links Observer Predefines ONE type of Turtle Allows the programmer (YOU!) to define different “Breeds” of Turtles.
E N D
New Mexico Computer Science For All Breeds and Shapes in NetLogo Maureen Psaila-Dombrowski
Breeds in NetLogo • Predefines Four Types of agent • Turtles • Patches • Links • Observer • Predefines ONE type of Turtle • Allows the programmer (YOU!) to define different “Breeds” of Turtles
Breeds in NetLogo – Remember! • Breeds are types of Turtles • Has all the properties that turtle has in addition to breed specific • Breeds are a Subset of Turtles Turtles Breed1 Breed2 …
When to Use Breeds • Many reasons to use breeds, some include: • Want agents with attributes • Example: genders, species, infected,… • Want agents that can behave differently • Ask each breed to behave differently • Want to refer to each breed separately • Want agents to have different variables
Define a Breed • Define turtle breeds using the breed keyword • At the top of the program • Before any procedures Breed [ plural_namesingular_name ] • Examples: breed [wolves wolf] breed [sheep a-sheep]
Create a Breed • Similar to creating turtles: create-<breeds>number create-<breeds>number [ commands ] • Example: breed [wolves wolf] breed [sheep a-sheep] to setup clear-all create-wolves 50 [ set color black] create-sheep 50 [ set color white] end
Set Breed Attributes • Can set breed attributes (NetLogo predefined agent variables): ask <breed> [set attribute #] ask wolf 3 [set size 5] ask <breeds> [set attribute #] ask wolves [set size 5] • Attributes: • breed • color • heading • hidden? • label • label-color • pen-mode (up, down, erase) • shape • size • who • xcor • ycor
Breed Attribute: Shape • You can set the shape of a turtle or specific breed • Set initial shape set-default-shape turtles stringset-default-shape breedstring • Changes the shape of breeds after used • Example: in setup procedure set-default-shape turtles "circle” set-deault-shape cows “cow” create-turtles 1 ;; new turtle's shape is "circle" create-cows 1 ;; new turtle's shape is ”cow"
Breed Attribute: Shape (continued) • Can set shape within the code set shape “shape_name” • Example ask wolf 10 [set shape “sheep’]
How do you find shapes? • Top of program – Tools Tab • Turtles Shape editor to view shapes • Can look at the shapes in the Turtle Shape Editor window and pick one • Over 30 shapes to choose from • Can Import a shape from the Library • Over 200 shapes to choose form • Can Edit an existing shape –RENAME it • Can create a new shape • Once you pick/import/edit/create a shape – note the name carefully
First row: default, airplane, arrow, box, bug, butterfly, car Second row: circle, circle 2, cow, cylinder, dot, face happy, face neutral Third row: face sad, fish, flag, flower, house, leaf, line Fourth row: line half, pentagon, person, plant, sheep, square, square 2 Fifth row: star, target, tree, triangle, triangle 2, truck, turtle Sixth row: wheel, x
Breed Specific Agent Variables • Can specify variables for breeds • Each agent in that breed has its own value • At top of the program before procedures <breeds>-own [var1 ...] breed [sheep a-sheep] breed [wolves wolf] turtles-own [energy] ;; both wolves and sheep wolves-own [WolfBirthRate] ;; only wolves sheep-own [SheepBirthRate] ;; only sheep
Breed Specific Actions • To get Breeds to do specific actions: ask breeds [commands…] ask breed # [commands…] ask breeds with [ condition][commands] • Example ask sheep [ left random 90 right random 90 forward 1 ]
Summary • Can have Breeds in NetLogo • Subset of Turtles • For each Breed • Define • Create Breed • Set attributes (NetLogo predefined agent variables) • Set shape • Specific Agent Variables • Specify Agent specific commands