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

noLoop() not honored by saveGif() #7354

Open
1 of 17 tasks
gohai opened this issue Nov 3, 2024 · 2 comments
Open
1 of 17 tasks

noLoop() not honored by saveGif() #7354

gohai opened this issue Nov 3, 2024 · 2 comments

Comments

@gohai
Copy link
Contributor

gohai commented Nov 3, 2024

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

1.11.0

Web browser and version

130.0.6723.92

Operating system

macOS

Steps to reproduce this

Steps:

  1. Run the snippet below

Snippet:

function setup() {
  createCanvas(400, 400);
  saveGif('mySketch', 5, { units: "frames" });
  noLoop();
}

function draw() {
  background(220);
  console.log("draw");
}

It'd be great to have the ability to create animated Gifs from graphics that aren't possible to create real-time (e.g. because each frame requires a web API call, which takes multiple seconds to complete). p5's redraw() function would be great for this to use (i.e. this invokes draw whenever a frame is ready to be added to the animation). Unfortunately, the current implementation of saveGif() does not seem to honor noLoop() - as the draw function is called periodically regardless.

@gohai gohai added the Bug label Nov 3, 2024
Copy link

welcome bot commented Nov 3, 2024

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

@bloomingbridges
Copy link

Looking at how saveGif() is implemented it seems to be doing exactly that:

  • Call noLoop() to stop rendering
  • Calculate the delay between frames (based on current frame rate)
  • Call redraw() periodically, adding frames to an array until a given duration has been reached
  • Call loop() to continue rendering as before
  • Encode the frames array as an animated GIF and prompt download action

While I definitely think there are times where you'd want to manually grab frames and export the lot as a GIF, I would be hesitant to call the current behavior a bug.

After all, if I save the individual frames using saveFrame() whenever they're ready, I can use other software to assemble the GIF with complete control (over which frames make it into the animation, frame delays, colour palette etc).

Though I'm sure you've already come to the same conclusion by now.
Happy new year 2025!

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

2 participants