| Paste number 70219: | self generating stuff |
| Pasted by: | topo |
| When: | 3 years, 2 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1I6J |
| Channel: | #lispcafe |
| Paste contents: |
(asdf:oos 'asdf:load-op :cl-opengl)
(asdf:oos 'asdf:load-op :cl-glu)
(load "glut.lisp")
(load "/Users/topo/slime-2.0/swank-loader.lisp")
(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 &rest parameter-list &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 "Error in ~a: ~a~%" ',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 "rgb double depth>=16 samples=8")
(glut:create-window "GLUT - <Untitled>")
(glut:display-func (safe-cffi-callback draw))
(let ((last-time))
(flet ((aux-animate (&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))Annotations for this paste:
| Annotation number 6: | here's a bit of a weird way |
| Pasted by: | sabetts |
| When: | 3 years, 2 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1I6J/6 |
| Paste contents: |
(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)))))
| Annotation number 5: | as a lambda |
| Pasted by: | sabetts |
| When: | 3 years, 2 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1I6J/5 |
| Paste contents: |
(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)))))))
| Annotation number 4: | as a macro |
| Pasted by: | sabetts |
| When: | 3 years, 2 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1I6J/4 |
| Paste contents: |
(defmacro make-structure ()
"Generate a lambda function at compile time. The problem here is
that it doesn't generate it at run time which maybe you want."
(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))))
| Annotation number 3: | or this maybe? |
| Pasted by: | sabetts |
| When: | 3 years, 2 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1I6J/3 |
| Paste contents: |
(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)
| Annotation number 2: | how about this? |
| Pasted by: | sabetts |
| When: | 3 years, 2 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1I6J/2 |
| Paste contents: |
(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))))))
| Annotation number 1: | draw, take 2 |
| Pasted by: | fugue88 |
| When: | 3 years, 2 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1I6J/1 |
| Paste contents: |
(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))