2015-12-01 Notes + HW

posted Dec 1, 2015, 5:57 AM by Samuel Konstantinovich   [ updated Dec 1, 2015, 5:57 AM ]
Goal: Good Coding Practices (Code Demo + fix lab)
Homework:
1. Complete LabN02
2. Netlogo Video 14. This is to solidify your ifelse understanding. 

Demo Code from class

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

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


to go
  every 1.0 / 30.0[
    ask turtles [ 
      act
      set label quadrant  
    ]
  ]
end


;turtle context command
to act
  if quadrant = 1
  [ quad1 ]
  if quadrant = 2
  [ quad2 ]
  if quadrant = 3
  [ quad3 ]
  if quadrant = 4
  [ quad4 ]
end

;turtle context command
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 quad1
   set color red
end

to quad2
   set color blue
end

to quad3
   set color green
end

to quad4
   set color yellow
end

Comments