vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.4k stars 67 forks source link

Save sketches as static images #54

Closed nery90 closed 1 year ago

nery90 commented 2 years ago

Dear Dev, first, let me thank you for this fantastic library. At the risk of asking something potentially trivial, I would like to know whether it is possible to save sketches as static images e.g. png. I am a researcher and I am very interested in using Sketch to programatically generate diagrams and graphics to (i) share my research results; and (ii) teach some Computer Science modules. I am new to Lisp, and so, again, I might be asking something very basic. Unfortunately, I could not find an answer to my question by looking at Sketch's source code. Or maybe this is not a correct use case for Sketch? I will be very happy if you could give me some pointers.

Thanks for your efforts.

Nery

vydd commented 1 year ago

This would be great, and I think I had something in works.

vydd commented 1 year ago

Hi @nery90 ! I've just pushed c0d635d694484bdf5fe488fcb1378c5bf508f742 to master and added SAVE-PNG. I still need to document it and add parameters for custom width/height, but could you please test it out and let me know if it works for you?

Here's example code:

(defsketch save-png-example ()
  (rect 100 100 200 200)
  (save-png #p"~/output.png"))

(make-instance 'save-png-example) ; you can just close it after it renders the rect

This will of course save the png every frame, but I'm sure you can find a way around it :)

nery90 commented 1 year ago

@vydd , this is great. This is just to say thanks. I'll put this feature to good use.