Lecture:: 01-02-2013

posted Jan 2, 2013, 5:28 AM by Samuel Konstantinovich   [ updated Jan 3, 2013, 5:31 AM ]

Exam: Next Friday: Breeds and Turtle/Turtle + Turtle/Patch interaction.

 

Today we will talk about breeds. Here are new commands you should know:


breed 
set-default-shape
min-one-of
min-n-of   ; look at documentation as I didn't show it in class
face
distance

NOTE:
There are lots of commands like ask  which aren't new, but have added features with breeds. You can ask a breed like ask cars, or ask sheep. You should look at the commands that have <breeds> in the netlogo dictionary, as they are available to you to use.

Sample in-radius commands:

;this paints the patches in a circle white
to colorRadius  ;turtle OR patch context
    ask patches in-radius 8 [set pcolor white]
end

;this tells you how many nearby turtles there are:
count turtles in-radius 5


Code from class:

breed [cars car]

breed[ wolves wolf]

to setup

  ca

  set-default-shape wolves "wolf"

  set-default-shape cars "car"

  create-wolves 5 [set size 2]

  create-cars 5 [set size 3 fd 4]

end

  

to go

  ask wolves [wiggle]

  ask cars [carStuff]

  wait 0.05

end


to wiggle

  rt random 40

  lt random 40

  fd 1

end


to carStuff

  let x wolves in-radius 5

  if any? x

  [face min-one-of x [ distance myself]]

  fd .5

end

Comments