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

Add control flow functions from p5js #113

Closed
Kevinpgalligan opened this issue Nov 9, 2023 · 2 comments
Closed

Add control flow functions from p5js #113

Kevinpgalligan opened this issue Nov 9, 2023 · 2 comments

Comments

@Kevinpgalligan
Copy link
Contributor

If drawing a static sketch (i.e. with no moving parts), then it seems wasteful to repeatedly call the (draw) function. Personally, I find it annoying when my laptop fan continues going crazy even after all the drawing has supposedly been completed.

p5js provides loop(), noLoop() and redraw() functions to alter the control flow. After drawing a static picture, for example, noLoop() can be called and no unnecessary CPU churn will take place afterwards. Another example: the user could click their mouse to start and stop a drawing loop.

So, my suggestion is to add the equivalent of these functions to sketch. I'm not sure how they would interact with redefinitions - I suppose that the loop would be started again once the sketch is redefined?

References:

@Gleefre
Copy link
Contributor

Gleefre commented Nov 9, 2023

As a workaround right now you can do that with kit.sdl2:

;;; test should name a sketch
* (make-instance 'test)
; => #<TEST {1006764313}>
* (setf (kit.sdl2:idle-render *) nil)  ; stops redrawing the sketch automatically
; => T
* (kit.sdl2:render (kit.sdl2:last-window))  ; redraws the last window
; => NIL
* (defmethod kit.sdl2:mousebutton-event ((window test) st ts but x y)
    ;; redraw the window on each mouse button click
    (when (eq st :mousebuttondown)
      (kit.sdl2:render window)))
; => #<STANDARD-METHOD KIT.SDL2:MOUSEBUTTON-EVENT (TEST T T T T T) {1005E3AF33}> 

@Kevinpgalligan
Copy link
Contributor Author

Done! We could consider adding the function to trigger redraws, but I can't think of any application that can't be achieved with start & stop functions.

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

No branches or pull requests

3 participants