anchor.diff:          (+ heading (random .3) -0.15))))
   
   (defun make-avoid (self friend)
  -  (let ((heading (- (bearing self friend))))
  +  (let ((heading (+ pi (bearing self friend))))
       #'(lambda ()
           (+ heading (random .3) -0.15))))
   
  
positive.code:          (nearest (car (sort others #'< :key (lambda (x) (distance x sheep)))))
           (dist (distance nearest sheep))
           (new-status (cond
                             ((> dist 200) 'isolated)
                             ((> dist 60) 'lonely)
                             ((< dist 20) 'crowded)
                             (t 'content))))
      (unless (eq new-status (status sheep))
        (setf (status sheep) new-status)
        (cond
          ((eq (status sheep) 'isolated)
           (progn
             (setf (motivation sheep) .2)
             (setf (direction-fn sheep) (make-meander (heading sheep)))
             ))
          ((eq (status sheep) 'lonely)
           (progn
             (setf (motivation sheep) .4)
             (setf (direction-fn sheep) (make-seek sheep nearest))
             ))
          ((eq (status sheep) 'crowded)
           (progn
             (setf (motivation sheep) .5)
             (setf (direction-fn sheep) (make-avoid sheep nearest))
             ))
          ((eq (status sheep) 'content)
           (progn
             (setf (motivation sheep) .1)
             (setf (direction-fn sheep) (make-meander (heading sheep)))
             ))))    
      (setf (motivation sheep) (cond 
                                 ((eq (status sheep) 'isolated) .2)
                                 ((eq (status sheep) 'lonely) .4)
                                 ((eq (status sheep) 'crowded) .3)
                                 ((eq (status sheep) 'content) .1))))
    (call-next-method))
  
  (defmethod draw :around (cr object)
    (when cr (call-next-method)))
  
  (defmethod draw (cr actor)
    (cairo-set-source-rgb cr 0.8 0.4 0.2)
    (cairo-arc cr (x actor) (- +drawing-area-height+ (y actor)) 5 0 (* 2 pi))
    (cairo-fill cr)
  
negative.code: 
  (defun make-medium-herd-world ()
    (let ((world (make-instance 'bounded-environment :time-step +time-step+
                                :x-min 0 :y-min 0 :x-max 700 :y-max 500)))
      (dotimes (i 20)
        (let ((x (+ 50 (random 600)))
              (y (+ 50 (random 400))))
          (add-actor world (make-instance 'sheep :x x :y y))))
      world))
  
  (defparameter *medium-herd-world* (make-medium-herd-world))
  
  (defun make-two-crowded-sheep-world ()
    (let ((world (make-instance 'bounded-environment :time-step +time-step+
                                :x-min 0 :y-min 0 :x-max 700 :y-max 500)))
      (add-actor world (make-instance 'sheep :x 300 :y 300))
      (add-actor world (make-instance 'sheep :x 305 :y 300))
      world))
  
  (defparameter *two-crowded-sheep-world* (make-two-crowded-sheep-world))
  
  (defun make-nucleated-sheep-world ()
    (let ((world (make-instance 'bounded-environment :time-step +time-step+
                                :x-min 0 :y-min 0 :x-max 700 :y-max 500)))
      (dotimes (i 8) (add-actor world (make-instance 'sheep :x (+ i 200) :y 150)))
      (dotimes (i 8) (add-actor world (make-instance 'sheep :x (+ i 350) :y 350)))
      (dotimes (i 8) (add-actor world (make-instance 'sheep :x (+ i 500) :y 150)))
      world))
  
  (defparameter *nucleated-sheep-world* (make-nucleated-sheep-world))
  
  ;; (defclass environment-window (gtk-window)
  ;;   ((runningp
  ;;     :initarg :runningp
  ;;     :accessor runningp
  ;;     :initform t)
  ;;    (
  
  (defun main ()
    (within-main-loop
     (let ((runningp t)
           ;(environment *medium-herd-world*)
           ;(environment *two-crowded-sheep-world*)
           (environment *nucleated-sheep-world*)
           (window (make-instance 'gtk-window
                                  :type :toplevel
                                  :title "Village"))
  