tapioca24 / p5.capture

🎬 super easy recording for p5.js animations
MIT License
230 stars 6 forks source link

Options for filename patterns #12

Closed tapioca24 closed 2 years ago

tapioca24 commented 2 years ago

v1.2.0 specification

file format filename pattern example
video (webm, gif, mp4), zip timestamp (YYYYMMDD-HHmmdd) 20220729-003612.webm
image (png, jpg, webp) 7-digit numbers 0000123.png

The timestamp is to avoid duplicate file names.

Issues

The following issues are considered.

Requirements

It is cool if the following requirements are met.

tapioca24 commented 2 years ago

There are two options.

Objects to customize filename parameters

For example, something like this:

P5Capture.setDefaultOptions({
  baseFilename: {
    pattern: "my-sketch-<timestamp>",  // <timestamp> is replaced by a timestamp at runtime
    timestampFormat: "MMM-DD-YYYY-HHmmss",
  },
  imageFilename: {
    pattern: "my-sketch-<count>",  // <count> is replaced by a count at runtime
    digitsInCounter: 10,
    counterStartValue: 100
  }
})

Functions that return a filename

For example, something like this:

P5Capture.setDefaultOptions({
  baseFilename(date) {
    return `my-sketch-${date.valueOf()}`
  },
  imageFilename(count) {
    const newCount = count + 100
    const countStr = newCount.toString().padStart(10, "0")
    return `my-sketch-${countStr}`
  }
})
tapioca24 commented 2 years ago

I prefer the function option because it is simpler and more flexible. It would meet almost all requirements.

msoriaro commented 2 years ago

Hi there! Thanks so much for dedicating time to this! In my opinion, the function option is also the most flexible. The user can have their own functions written with any arbitrary complexity, and for those who are not experts they can always just copy-paste an easy example for the most basic features (basically, those functions you have there in the example). Then an expert user can build upon that as much as they please. If this does not complicate your development of the library, I believe it's a useful feature for many use cases. Thank you so much once again!

tapioca24 commented 2 years ago

@msoriaro Thank you for your input. It has helped me to confirm that the function option is optimal. I am working on this now! Basically this will be ready soon. I will let you know when it''s done.

tapioca24 commented 2 years ago

Hi, @msoriaro.

Added by https://github.com/tapioca24/p5.capture/pull/13. Released in 1.3.0. Now you can customize filenames using the baseFilename and imageFilename options! Thank you again for your valuable suggestions. Let me know if you have any problems.