Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ If you did everything correctly, you should be able to =(ql:quickload :sketch)=

#+BEGIN_SRC lisp
CL-USER> (ql:quickload :sketch-examples)
CL-USER> (make-instance 'sketch-examples:hello-world)
CL-USER> (make-instance 'sketch-examples:sinewave)
CL-USER> (make-instance 'sketch-examples:brownian)
CL-USER> (make-instance 'sketch-examples:life) ; Click to toggle cells,
; any key to toggle iteration
CL-USER> (make-instance 'sketch-examples:input)
CL-USER> (make-instance 'sketch-examples:stars)
CL-USER> (in-package sketch-examples)
SKETCH-EXAMPLES> (run-hello-world)
SKETCH-EXAMPLES> (run-sinewave)
SKETCH-EXAMPLES> (run-brownian)
SKETCH-EXAMPLES> (run-life) ; Click to toggle cells,
; any key to toggle iteration
SKETCH-EXAMPLES> (run-input)
SKETCH-EXAMPLES> (run-stars)
#+END_SRC

*** Running example code from this page
Expand All @@ -108,11 +109,11 @@ TUTORIAL> ;; ready
#+END_SRC

** Tutorial
Defining sketches is done with the =defsketch= macro, which is essentially a wrapper for =defclass=.
Defining sketches is done with the =defsketch= macro. This defines a function called `run-NAMEHERE` for starting your sketch. Alternatively, you can do `(run-sketch 'NAMEHERE)`.

#+BEGIN_SRC lisp
(defsketch tutorial ())
(make-instance 'tutorial)
(run-tutorial)
#+END_SRC

If all goes well, this should give you an unremarkable gray window. From now on, assuming you're using Emacs + SLIME, or a similarly capable environment, you can just re-evaluate =(defsketch tutorial () <insert drawing code here>)= and the sketch will be restarted without you having to close the window or make another instance of the class.
Expand Down
1 change: 1 addition & 0 deletions src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:draw

:defsketch
:run-sketch

:sketch-title
:sketch-width
Expand Down
17 changes: 17 additions & 0 deletions src/sketch.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@
collect `(,(binding-accessor b) *sketch*)
collect (binding-name b)))))

(defun define-sketch-run-function (name bindings)
`(defun ,(alexandria:symbolicate 'run- name)
(&rest args
&key ,@(loop for b in bindings
collect (list (binding-name b) (binding-initform b)))
&allow-other-keys)
(declare (ignore ,@(loop for b in bindings collect (binding-name b))))
(apply #'make-instance ',name args)))

(defmacro defsketch (sketch-name binding-forms &body body)
(let ((bindings (parse-bindings sketch-name binding-forms
(class-bindings (find-class 'sketch)))))
Expand All @@ -323,10 +332,18 @@
,@(define-sketch-channel-observers bindings)
,(define-sketch-prepare-method sketch-name bindings)
,(define-sketch-draw-method sketch-name bindings body)
,(define-sketch-run-function sketch-name bindings)

(make-instances-obsolete ',sketch-name)
(find-class ',sketch-name))))

(defun run-sketch (name &rest args)
(let ((cls (find-class name nil)))
(when (or (null cls)
(not (c2mop:subclassp cls (find-class 'sketch))))
(error (format nil "Couldn't find a sketch called ~a" name)))
(apply #'make-instance name args)))

;;; Control flow

(defun stop-loop ()
Expand Down