2014-11-26 Notes

posted Nov 26, 2014, 8:15 AM by Samuel Konstantinovich   [ updated Nov 26, 2014, 8:15 AM ]
No HW over break. 
Tuesday Quiz on netlogo including if and if-else.

Notes: You need to get "notes" from other people.
This is the base code from class:

to setup
  ca
  crt num-turtles [ 
    setxy random-xcor random-ycor
    ;set xcor random-float (2 * max-pxcor + 1) - pxcor 
  ]
end


to go
  ask turtles [ 
    act
    set label quadrant  
  ]
  wait 1 / 30
end

to act
  if quadrant = 1[
    wiggle turtle-speed 0
    if size < 5 [
      set size size + 0.1
    ]
    set color red
  ]
  if quadrant = 2[
    wiggle 2 * turtle-speed max-turn-angle
    if size > 1.1 [
      ;CHANGE: don't lower size if it is 1.1, or you get 0.9
      set size size - 0.2
    ]
    set color color + 0.2
  ]
  if quadrant = 3[
    wiggle turtle-speed / 2 max-turn-angle * 2
    if size > 1 [
      set size size - 0.1
    ]
  ]
  if quadrant = 4[
    wiggle turtle-speed max-turn-angle
    if size > 1 [
      set size size - 0.1
    ]
    set color 5 + 10 * random 14
  ]
end

to-report quadrant
  if xcor > 0 and ycor > 0
  [report 1]
  if xcor <= 0 and ycor > 0
  [report 2]
  if xcor <= 0 and ycor <= 0
  [report 3]
  report 4
end

to wiggle [ dist angle ]
  rt random angle
  lt random angle
  fd dist
end
Comments