1 / 16

New Mexico Computer Science For All

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.

lou
Download Presentation

New Mexico Computer Science For All

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. New Mexico Computer Science For All Breeds and Shapes in NetLogo Maureen Psaila-Dombrowski

  2. 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

  3. 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 …

  4. 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

  5. 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]

  6. 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

  7. 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

  8. 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"

  9. Breed Attribute: Shape (continued) • Can set shape within the code set shape “shape_name” • Example ask wolf 10 [set shape “sheep’]

  10. 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

  11. 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

  12. Go to Program to show shapes

  13. 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

  14. 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 ]

  15. Show variables and Actions in program

  16. 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

More Related