12-05-2013 HW e

posted Dec 5, 2013, 5:37 AM by Samuel Konstantinovich   [ updated Dec 5, 2013, 8:08 AM ]
HW:
Watch Tutorials 16 + 19. A Quiz tomorrow can be on (16,17,19)
Complete lab from yesterday.

Code from class today:

globals [totalBirths]
patches-own [counter]

to setup
  ca
  reset-ticks
  ask patches [ 
    if pxcor > 0 [set pcolor white] 
  ]
  ask n-of 5 patches with[pcolor = white] [set pcolor blue]
  ask n-of 5 patches with[pcolor = black] [set pcolor red]
end

to patchstuff
  if random 100 < 2
    [    
      set counter counter + 1
      set totalBirths totalBirths + 1
      sprout 1[set color pcolor ] 
    ]
    
end

to turtlestuff
  fd .2
  rt random 30
  lt random 30
  if pcolor != black and pcolor != white and pcolor != color
  [
   set label "I am melting" 
  ]
  if label = "I am melting"[set size size - .1]
  if size < .2 [die]
end

to go
  ask patches with [pcolor = red or pcolor = blue] 
  [ 
    patchstuff
  ]

  ask turtles [
    turtlestuff
  ]
  tick
  wait 1 / 30
end
Comments