<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>70219</integer>
    </number>
    <user>
      <string>topo</string>
    </user>
    <title>
      <string>self generating stuff</string>
    </title>
    <contents>
      <string>(asdf:oos 'asdf:load-op :cl-opengl)
(asdf:oos 'asdf:load-op :cl-glu)
(load &quot;glut.lisp&quot;)

(load &quot;/Users/topo/slime-2.0/swank-loader.lisp&quot;)

(defparameter *window-width* 640)
(defparameter *window-height* 480)

;;(defparameter *a* (GLUT:SOLID-SPHERE 11.529d0 13 3))

(defvar a nil)

;;(defparameter a (GLUT:SOLID-SPHERE 11.529d0 13 3))

;;(defparameter *a* (time-in-seconds))

;;(time-in-seconds)

(defparameter *time* 0)
;;(defparameter  nil)
;;(defvar a (GLUT:SOLID-SPHERE 11.529d0 13 3))

(defun time-in-seconds ()
  (float (/ (get-internal-real-time) internal-time-units-per-second)))

(defmacro safe-cffi-callback (lisp-function &amp;rest parameter-list &amp;aux (callback-tmpname (gensym)))
  `(prog2
       (cffi:defcallback ,callback-tmpname :void ,parameter-list
	 (handler-case (,lisp-function ,@(mapcar #'car parameter-list))

	   (error (condition)
	     (setf (symbol-function ',lisp-function) (constantly nil))
	     (format t &quot;Error in ~a: ~a~%&quot; ',lisp-function condition))))
       (cffi:callback ,callback-tmpname)))

(defun random-elt (list)
(elt list (random (length list))))

(defun make-structure ()
  (case (random-elt '(transformation geo))
    (transformation (list (random-elt '(  (gl:scale 1 9 2 )  (gl:translate -2 -3 -1.5)  (gl:rotate 119 997 27 ) ))
			  
		    (make-structure))  )
    (geo (random-elt '( (glut:solid-sphere 11.529d0 13 3)  (glut:solid-cube 19.d0) )))))

;;(make-structure)



(defun aux-function () a)

(defun main-function ()
  ;;  ( setf a (make-structure))
  ;;  ( setq a #'(glut:solid-sphere 13.529d0 13 3))
  ;; time-in-seconds(time-in-seconds)
  ;;( setf fn #'cons)
  ;;( setf a #'time-in-seconds)
  ;;( setf a #'(time-in-seconds))
  
  ;;(setf a #',glut:solid-sphere 13.529d0 13 3)
  ;;( setf a #'glut:solid-sphere 13.529d0 13 3)
  ;;(setf a #'myfunction)
  ;;(setf a #'glut:solid-sphere 13.529d0 13 3)
  ;;(setf a #'glut:solid-sphere (13.529d0 13 3))
  ;;(setf a (lambda (foo bar) (glut:solid-sphere 13.529d0 13 3 foo bar)))
  ;;( setf a #'glut:solid-sphere)
  ;; ( setf a #'(glut:solid-sphere 13.529d0 13 3))
  (setf a (make-structure))
  ;;   ( setf a (make-structure))
  (aux-function))


;;(setf a (lambda () (glut:solid-sphere 13.529d0 13 3)))
;;(setf a (lambda (glut:solid-sphere 13.529d0 13 3)))
;;(main-function)


(defun draw ()
  (gl:clear-color 0 0 0 1)
  (gl:clear :color-buffer-bit :depth-buffer-bit)
  (gl:matrix-mode :projection)
  (gl:load-identity)
  (glu:perspective 60 (/ 800 600) 1 100)
  (gl:matrix-mode :modelview)
  (gl:load-identity)
  (gl:enable :lighting)
  (gl:enable :light0)
  (gl:enable :depth-test)
  (gl:enable :color-material)
  (gl:enable :auto-normal)
  (gl:enable :normalize)
  
  ;;a
  (gl:translate 0 -3 -60)
 
  ;;porque no funciona ni cuando llamo la funcion ni cuando llamo a la variable?
  
  ;;(aux-function )
  (dotimes (i 13)
    (gl:translate -4 3 6)
    ;;  (GLUT:SOLID-SPHERE 11.529d0 13 3)
    ;; (aux-function)
    ;;  (funcall a '3.529d0 '13 '3)
    a
    ;;  (funcall a)
    ;; (glut:solid-sphere 1.9d0 60 2)
    )
  
  
  (glut:swap-buffers))

(defun animate (dt))

(defun init ()
  (glut:init-posix-argv sb-ext:*posix-argv*)
  (glut:init-window-size *window-width* *window-height*)
  (glut:init-display-string &quot;rgb double depth&gt;=16 samples=8&quot;)
  (glut:create-window &quot;GLUT - &lt;Untitled&gt;&quot;)
  
  (glut:display-func (safe-cffi-callback draw))
  (let ((last-time))
    (flet ((aux-animate (&amp;aux (current-time (time-in-seconds))
                              (dt (- current-time
                                     (if last-time last-time current-time))))
             (setq *time* (+ *time* dt)
                   last-time current-time)
             (animate dt)
             (sb-sys:serve-all-events 0.01)
             (glut:post-redisplay)))
      (glut:idle-func (safe-cffi-callback aux-animate))))
  
  (flet ((window-resize (width height)
           (setq *window-width* width
                 *window-height* height)
           (gl:viewport 0 0 *window-width* *window-height*)))
    (glut:reshape-func (safe-cffi-callback window-resize (width :int) (height :int))))
  
  (swank:create-server)
  (glut:main-loop))

(unless (boundp 'inited)
  (defparameter inited nil)
  (init))</string>
    </contents>
    <universal-time>
      <integer>3435499934</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string>Common Lisp</string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </paste>
  <annotation>
    <number>
      <integer>1</integer>
    </number>
    <user>
      <string>fugue88</string>
    </user>
    <title>
      <string>draw, take 2</string>
    </title>
    <contents>
      <string>(defun draw ()
  (gl:clear-color 0 0 0 1)
  (gl:clear :color-buffer-bit :depth-buffer-bit)
  (gl:matrix-mode :projection)
  (gl:load-identity)
  (glu:perspective 60 (/ 800 600) 1 100)
  (gl:matrix-mode :modelview)
  (gl:load-identity)
  (gl:enable :lighting)
  (gl:enable :light0)
  (gl:enable :depth-test)
  (gl:enable :color-material)
  (gl:enable :auto-normal)
  (gl:enable :normalize)
  
  ;;a
  (gl:translate 0 -3 -60)
 
  ;;porque no funciona ni cuando llamo la funcion ni cuando llamo a la variable?
  
  ;;(aux-function )
  (dotimes (i 13)
    (gl:translate -4 3 6)
    ;; Here, A hold a value such as:
    ;;   ((GLUT:SOLID-SPHERE 3d0 13 3)
    ;;    (GLUT:SOLID-SPHERE 5d0 8 2))
    (dolist (primitive a)
      ;; PRIMITIVE is now a value such as: (GLUT:SOLID-SPHERE 3d0 13 3)
      ;; But it's still just data, until we ask Lisp to treat it as code:
      (eval primitive)))
  
  
  (glut:swap-buffers))
</string>
    </contents>
    <universal-time>
      <integer>3435500375</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>2</integer>
    </number>
    <user>
      <string>sabetts</string>
    </user>
    <title>
      <string>how about this?</string>
    </title>
    <contents>
      <string>(defun execute-structure ()
  (case (random 2)
    (0 (case (random 3)
         (0 (gl:scale 1 9 2))
         (1 (gl:translate -2 -3 -1.5))
         (2 (gl:rotate 119 997 27)))
       (execute-structure))
    (1 (case (random 2)
         (0 (glut:solid-sphere 11.529d0 13 3))
         (1 (glut:solid-cube 19.d0))))))
</string>
    </contents>
    <universal-time>
      <integer>3435510998</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>3</integer>
    </number>
    <user>
      <string>sabetts</string>
    </user>
    <title>
      <string>or this maybe?</string>
    </title>
    <contents>
      <string>(defun execute-structure (structure)
  (case (pop structure)
    (0 (case (pop structure)
         (0 (gl:scale 1 9 2))
         (1 (gl:translate -2 -3 -1.5))
         (2 (gl:rotate 119 997 27)))
       (execute-structure structure))
    (1 (case (pop structure)
         (0 (glut:solid-sphere 11.529d0 13 3))
         (1 (glut:solid-cube 19.d0))))))

(execute-structure 0 1 0 2 0 1 0 0 1)
</string>
    </contents>
    <universal-time>
      <integer>3435511533</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>4</integer>
    </number>
    <user>
      <string>sabetts</string>
    </user>
    <title>
      <string>as a macro</string>
    </title>
    <contents>
      <string>(defmacro make-structure ()
  &quot;Generate a lambda function at compile time. The problem here is
that it doesn't generate it at run time which maybe you want.&quot;
  (labels ((make-it ()
             (case (random 2)
               (0 (list (random-elt '((gl:scale 1 9 2 )
                                      (gl:translate -2 -3 -1.5)
                                      (gl:rotate 119 997 27)))
                        (make-structure)))
               (1 (random-elt '((glut:solid-sphere 11.529d0 13 3)
                                (glut:solid-cube 19.d0)))))))
    (lambda ()
      ,@(make-it))))

</string>
    </contents>
    <universal-time>
      <integer>3435511993</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>5</integer>
    </number>
    <user>
      <string>sabetts</string>
    </user>
    <title>
      <string>as a lambda</string>
    </title>
    <contents>
      <string>(defun make-structure ()
  (labels ((make-it ()
             (case (random 2)
               (0 (list (random-elt '((gl:scale 1 9 2 )
                                      (gl:translate -2 -3 -1.5)
                                      (gl:rotate 119 997 27)))
                        (make-structure)))
               (1 (random-elt '((glut:solid-sphere 11.529d0 13 3)
                                (glut:solid-cube 19.d0)))))))
    (let ((structure (make-it)))
      (lambda ()
        (dolist (i structure)
          (apply (first i) (rest i))))))) 
</string>
    </contents>
    <universal-time>
      <integer>3435512165</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>6</integer>
    </number>
    <user>
      <string>sabetts</string>
    </user>
    <title>
      <string>here's a bit of a weird way</string>
    </title>
    <contents>
      <string>(defun make-structure ()
  (labels ((doit ()
             (case (random 2)
               (0 (case (random 3)
                    (0 (gl:scale 1 9 2))
                    (1 (gl:translate -2 -3 -1.5))
                    (2 (gl:rotate 119 997 27)))
                  (doit structure))
               (1 (case (pop structure)
                    (0 (glut:solid-sphere 11.529d0 13 3))
                    (1 (glut:solid-cube 19.d0)))))))
    (let ((state (make-random-state *random-state*)))
      (lambda ()
        (setf *random-state* state)
        (doit)))))
</string>
    </contents>
    <universal-time>
      <integer>3435512521</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
</paste-with-annotations>
