Download presentation
Presentation is loading. Please wait.
Published byAmelia Morgan Modified over 9 years ago
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 … # Breed 1 # Breed 2 … Total # Turtles
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_name singular_name ] Examples: breed [wolves wolf] breed [sheep a-sheep]
6
Create a Breed Similar to creating turtles: create- number create- 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 Attributes: ▫breed ▫color ▫heading ▫hidden? ▫label ▫label-color ▫pen-mode (up, down, erase) Can set breed attributes (NetLogo predefined agent variables) : ask [set attribute #] ask wolf 3 [set size 5] ask [set attribute #] ask wolves [set size 5] ▫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 string set- default-shape breed string 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 -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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.