Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible sketch class generation #142

Open
Kevinpgalligan opened this issue Jan 23, 2024 · 2 comments
Open

More flexible sketch class generation #142

Kevinpgalligan opened this issue Jan 23, 2024 · 2 comments

Comments

@Kevinpgalligan
Copy link
Contributor

It would be nice if we could share functionality between sketches, and also if the sketch could be instantiated with user-supplied parameters. For this I suggest an alternative defsketch interface, while keeping the old one for simplicity / backward compatibility.

Example defsketchx interface (x is for "extended", maybe?):

(defsketchx my-sketch (some-mixin-class another-mixin-class)
    ;; These can be passed by the user to make-instance
    (x (y 100))
    ((width 200)
     (height 400))
   (circle (or x 50) y))

Then instantiation might look like (make-instance 'my-sketch :x 70 :y 120). Maybe some-mixin-class hooks into draw and always provides a black background.

The specific application I have in mind is having a widgets-window class that automatically creates a separate window with sliders/buttons to modify the sketch parameters.

(defsketchx my-sketch (widgets-window) ()
    ((x (widget:slider 0 width))
     (y (widget:dropdown 10 50 100)))
  (circle (widget:get-value x) (widget:get-value y) 10))
@Gleefre
Copy link
Contributor

Gleefre commented Jan 23, 2024

As a workaround this could be achieved using the stealth-mixin library.

(defclass widgets-mixin ...)

(defsketch my-sketch (...)
  ...)

(stealth-mixin:add-mixin 'widgets-mixin 'my-sketch)

@Gleefre
Copy link
Contributor

Gleefre commented Jan 23, 2024

An example:

(defpackage #:sketch-user
  (:use #:cl)
  (:local-nicknames (#:s #:sketch)))

(in-package #:sketch-user)


(defclass black-background-mixin () ())

(defmethod s:draw :before ((sketch black-background-mixin) &key &allow-other-keys)
  (s:background s:+black+))

(s:defsketch test ()
  (s:circle 200 200 100))

(make-instance 'test)

(sleep 5)

(stealth-mixin:add-mixin 'black-background-mixin 'test)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants