diff options
author | Bruno Cichon <ebrasca.ebrasca@gmail.com> | 2015-10-27 16:38:19 +0100 |
---|---|---|
committer | Bruno Cichon <ebrasca.ebrasca@gmail.com> | 2015-10-27 16:38:19 +0100 |
commit | 00e055406031fab6f4e2e5122c50c4050a1eb253 (patch) | |
tree | aafbe53ff8ce702106d490ad186bca9cd656b15a | |
parent | eb9fb605fb5d5695289ed1723340da6076cb863f (diff) |
Add documentation and one example.
-rw-r--r-- | README.txt | 14 | ||||
-rw-r--r-- | examples/l-system-exemple.lisp | 170 | ||||
-rw-r--r-- | examples/package.lisp | 6 | ||||
-rw-r--r-- | l-system-examples.asd | 13 |
4 files changed, 202 insertions, 1 deletions
@@ -1 +1,13 @@ -This is the stub README.txt for the "l-system" project. +#l-system + +This is based on Lindenmayer system with lists on place of strings. +Main goal of this proyect are flexibility. + +The basic idea are : l-system -> turtle-system -> graphics + +At the moment, this includes the following functionality: + +*Manage parametric l system based on list +*Early turtle-system + +For an example, see 'examples/l-system-exemple.lisp'. diff --git a/examples/l-system-exemple.lisp b/examples/l-system-exemple.lisp new file mode 100644 index 0000000..e95f4d3 --- /dev/null +++ b/examples/l-system-exemple.lisp @@ -0,0 +1,170 @@ +(in-package #:l-system-examples) + +(def-l-system-clause 'f + #'(lambda (list) + (let* ((r0 0.5235988) + (n0 (* 1.01 (car list)))) + `((f ,(* 1.11 n0)) + + ([) + (+ ,r0) + (f ,(* 0.89 n0)) + (]) + + ([) + (- ,r0) + (f ,(* 0.89 n0)) + (]) + + ([) + (/ ,r0) + (f ,(* 0.89 n0)) + (]) + + ([) + (q ,r0) + (f ,(* 0.89 n0)) + (]) + + (f ,(* 1.11 n0)) + + ([) + (+ ,r0) + (f ,(* 0.89 n0)) + (]) + + ([) + (- ,r0) + (f ,(* 0.89 n0)) + (]) + + ([) + (/ ,r0) + (f ,(* 0.89 n0)) + (]) + + ([) + (q ,r0) + (f ,(* 0.89 n0)) + (]) + + (f ,(* 1.11 n0)))))) + +(def-l-system-clause '+ + #'(lambda (list) + `((+ ,(+ 0.1 (car list)))))) + +(def-l-system-clause '- + #'(lambda (list) + `((- ,(+ 0.1 (car list)))))) + +;; Rest +(defclass test-window (gl-window) + ((start-time :initform (get-internal-real-time)) + (frames :initform 0) + (dt :initform 0) + (rotate :initform 0.0) + + (view-matrix :initform (kit.glm:perspective-matrix 50.0 1.1 1.0 800.0)) + (vao :initform nil) + (programs :initform nil))) + +(defmethod initialize-instance :after ((w test-window) + &key shaders &allow-other-keys) + (setf (idle-render w) t) + (gl:viewport 0 0 800 600) + + (with-slots (vao programs) w + (let* ((data + ;;convert list of vecs to array + (list-of-vectors->list + ;;make list of vecs + (turtle-system #'(lambda (old new x y z) + (list old new)) + ;;make structure of turtle commands + (l-system '((f 1.0)) 3)))) + (length (length data)) + (array (make-array length + :element-type 'single-float + :initial-contents data))) + (setf programs (compile-shader-dictionary shaders)) + (setf vao + (make-instance 'vao + :type 'vertex-3d + :primitive :lines + :vertex-count (/ length 3))) + (vao-buffer-vector vao 0 (* 4 length) array) + (vao-buffer-vector vao 1 (* 4 length) array)))) + + +;;; Rest + +(defmethod render ((window test-window)) + (with-slots (view-matrix vao programs rotate) window + (gl:clear-color 0.0 0.0 1.0 1.0) + (gl:clear :color-buffer) + + (use-program programs :vertex-color) + (uniform-matrix programs :view-m 4 (vector + (sb-cga:matrix* + view-matrix + (kit.glm:look-at + (sb-cga:vec 0.0 0.0 200.0) + (sb-cga:vec 0.0 10.0 0.0) + (sb-cga:vec 0.0 -1.0 0.0)) + (sb-cga:rotate* 0.0 + (incf rotate 0.00625) + 0.0)))) + (vao-draw vao))) + +(defmethod render :after ((window test-window)) + (with-slots (start-time frames rotate) window + (incf frames) + (let* ((current-time (get-internal-real-time)) + (seconds (/ (- current-time start-time) internal-time-units-per-second))) + + (when (> seconds 5) + (format t "FPS: ~A~%" (float (/ frames seconds))) + (setf frames 0) + (setf start-time (get-internal-real-time)))))) + +(defun start-example () + (kit.sdl2:start) + (sdl2:in-main-thread () + (sdl2:gl-set-attr :context-major-version 3) + (sdl2:gl-set-attr :context-minor-version 3)) + (make-instance 'test-window :shaders 'vao-color.programs.330)) + +(defvao vertex-3d () + (:separate () + (vertex :float 3) + (color :float 3))) + +(defdict vao-color.programs.330 () + (program :vertex-color (:view-m) + (:vertex-shader " +#version 330 + +uniform mat4 view_m; + +layout (location = 0) in vec3 vertex; +layout (location = 1) in vec3 color; + +smooth out vec3 f_color; + +void main() { + gl_Position = view_m * vec4(vertex, 1.0); + f_color = color; +} +") + (:fragment-shader " +#version 330 + +smooth in vec3 f_color; +out vec4 f_out; + +void main() { + f_out = vec4(f_color, + 1.0); +} +"))) diff --git a/examples/package.lisp b/examples/package.lisp new file mode 100644 index 0000000..4324bab --- /dev/null +++ b/examples/package.lisp @@ -0,0 +1,6 @@ +;;;; package.lisp + +(defpackage #:l-system-examples + (:use #:cl #:kit.sdl2 #:kit.gl.shader #:kit.gl.vao #:l-system #:sb-cga) + (:export #:start-example)) + diff --git a/l-system-examples.asd b/l-system-examples.asd new file mode 100644 index 0000000..cf2725d --- /dev/null +++ b/l-system-examples.asd @@ -0,0 +1,13 @@ +;;;; l-system-examples.asd + +(asdf:defsystem #:l-system-examples + :description "L-system or Lindenmayer system on lists" + :author "Bruno Cichon <ebrasca.ebrasca@gmail.com>" + :license "GPLv3+" + :pathname "examples" + :serial t + :depends-on (:glkit + :sdl2kit + :l-system) + :components ((:file "package") + (:file "l-system-exemple"))) |