Lecture: 12-17-2012

posted Dec 18, 2012, 5:28 AM by Samuel Konstantinovich   [ updated Dec 18, 2012, 5:28 AM ]
Here is the image manipulation code from class:


patches-own [originalColor]

to setup
  ca
  import-pcolors "car.jpg"
  ask patches [set originalColor pcolor]
end

to reset
  ask patches [set pcolor originalColor]
end

to grayscale
  ask patches [set pcolor pcolor mod 10]
end


to randomNeighbors
  ask patches [set pcolor [pcolor] of one-of neighbors]
end

to melt ;streak downwards
   ask patches [ set pcolor [pcolor] of patch (pxcor) (pycor + 1) ]
end

;use this function using the named color values, like:
; replace red blue   
;replace black white
to replace [ orig final]
  ask patches with [pcolor >= orig - 4 and pcolor <= orig + 4] [set pcolor pcolor - (orig - final) ]
end

Comments