anchor.diff:                                              (* (float3-z vv) vscale)
                                               1.0))))))
   
  -(defun reset (pos vel cluster-scale velocity-scale num-bodies)
  -  (randomize-bodies pos vel cluster-scale velocity-scale num-bodies))
  -
  -(defun integrate-nbody-system (new-pos old-pos vel delta-time damping num-bodies p)
  -  (let ((grid-dim (list (ceiling (/ num-bodies p)) 1 1))
  -        (block-dim (list p 1 1)))
  -    (integrate-bodies new-pos old-pos vel delta-time damping num-bodies
  -                      :grid-dim grid-dim
  -                      :block-dim block-dim)))
  +
  +;;;
  +;;; main
  +;;;
   
   (defun main ()
  -  (let ((dev-id 0)
  -        (num-bodies 2048)
  -        (cluster-scale 1.56)
  -        (velocity-scale 2.64)
  -        (delta-time 0.016)
  -        (damping 1.0)
  -        (p 256)
  -        (window (make-instance 'nbody-window)))
  -    (with-cuda-context (dev-id)
  -      (with-memory-blocks ((new-pos 'float4 num-bodies)
  -                           (old-pos 'float4 num-bodies)
  -                           (vel 'float4 num-bodies))
  -      (with-cuda-timer
  -        ;; set values to slots of the nbody window
  -        (setf (slot-value window 'new-pos) new-pos
  -              (slot-value window 'old-pos) old-pos
  -              (slot-value window 'vel) vel
  -              (slot-value window 'delta-time) delta-time
  -              (slot-value window 'damping) damping
  -              (slot-value window 'num-bodies) num-bodies
  -              (slot-value window 'p) p)
  -        ;; reset position and velocity of bodies
  -        (reset old-pos vel cluster-scale velocity-scale num-bodies)
  -        ;; copy position and velocity on host memory to device memory
  -        (memcpy-host-to-device old-pos vel)
  -        ;; start CUDA timer
  -        (start-timer)
  -        ;; start glut main loop
  -        (glut:display-window window))))))
  +  (glut:display-window (make-instance 'nbody-window)))
   
   (defun not-implemented ()
     (error "not implemented."))
  
positive.code:     (gl:attach-shader m-program m-vertex-shader)
      (gl:attach-shader m-program m-pixel-shader)
      ;; link program object
      (gl:link-program m-program)
      ;; create texture
      (create-texture 32))
    
    (defun eval-hermite (pa pb va vb u)
      (let ((u2 (* u u))
            (u3 (* u u u)))
        (let ((b0 (+ (- (* 2 u3) (* 3 u2)) 1))
              (b1 (+ (* -2 u3) (* 3 u2)))
              (b2 (+ (- u3 (* 2 u2)) u))
              (b3 (- u3 u)))
          (+ (* b0 pa) (* b1 pb) (* b2 va) (* b3 vb)))))
    
    (defun create-gaussian-map (b n)
      (let ((incr (/ 2.0 n))
            (j 0))
        (do ((y 0 (1+ y))
             (yy -1.0 (+ yy incr)))
            ((= y n))
          (do ((x 0 (1+ x))
               (xx -1.0 (+ xx incr)))
              ((= x n))
            (let* ((dist (min (sqrt (+ (* xx xx) (* yy yy))) 1.0))
                   (hermite (eval-hermite 1.0 0 0 0 dist))
                   (value (truncate (* hermite 255))))
              (setf (cffi:mem-aref b :unsigned-char j)       value
                    (cffi:mem-aref b :unsigned-char (+ j 1)) value
                    (cffi:mem-aref b :unsigned-char (+ j 2)) value
                    (cffi:mem-aref b :unsigned-char (+ j 3)) value)
              (incf j 4))))))
    
    (defun create-texture (resolution)
      (setf m-texture-data (cffi:foreign-alloc :unsigned-char :count (* 4 resolution resolution)))
  
negative.code: ;;;
  
  (defmethod glut:display-window :before ((w nbody-window))
    (nbody-init)
    (gl:enable :depth-test)
    (gl:clear-color 0 0 0 0))
  
  (defmethod glut:close ((w nbody-window))
    (nbody-release))
  
  (defmethod glut:display ((w nbody-window))
    ;; update simulation
    (nbody-update-simulation)
    ;; clear buffers
    (gl:clear :color-buffer :depth-buffer-bit)
    ;; view transform
    (gl:matrix-mode :modelview)
    (gl:load-identity)
    (gl:translate 0.0 0.0 -100.0)
    (gl:rotate 0.0 1.0 0.0 0.0)
    (gl:rotate 0.0 0.0 1.0 0.0)
    ;; display bodies
    (nbody-display :particle-sprites)
    ;; swap buffers
    (glut:swap-buffers)
    ;; display frame rate
    (display-frame-rate (nbody-num-bodies) (nbody-get-frame-rate)))
  
  (defmethod glut:reshape ((w nbody-window) width height)
    ;; configure on projection mode
  