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

Enhancement: Add precise frame control to py5_tool.animated_gif #350

Closed
hx2A opened this issue Sep 15, 2023 · 7 comments
Closed

Enhancement: Add precise frame control to py5_tool.animated_gif #350

hx2A opened this issue Sep 15, 2023 · 7 comments

Comments

@hx2A
Copy link
Collaborator

hx2A commented Sep 15, 2023

The py5_tool.animated_gif feature is great, but I miss from the gifAnimation library that I used with Processing Java/Python mode the "fine control" of choosing to add frames in some circumstances...

from py5_tools import animated_gif

n = 10

def setup():
    size(500, 500)
    no_stroke()
    frame_rate(16)
    # filename, number of frames, sample interval, frame duration in gif
    animated_gif('test.gif', n, 0.05, 1)
        
def draw():
    background(100)
    fill(255)
    text_size(40)
    text(frame_count, 200, 200)
    
    
    if frame_count > n + 5:
        exit_sketch()

test

When making small loops the "time control" afforded by animated_gif doesn't seem helpful. I then usually export all frames (or every odd frame) and generate the animation elsewhere. Am I missing somethig?

A lazy idea... could we have animated_gif_from_frames(filename, list_of_frames, duration)?

Originally posted by @villares in #349

hx2A added a commit to hx2A/py5generator_fork that referenced this issue Oct 1, 2023
@hx2A
Copy link
Collaborator Author

hx2A commented Oct 1, 2023

I started working on this and basically have it working.

I also should add this feature to py5_tools.capture_frames(). It shares code with the animated gif feature so I might as well include it.

https://py5coding.org/reference/py5tools_capture_frames.html

The function signatures of both will change a bit as a result.

@hx2A hx2A mentioned this issue Oct 6, 2023
@hx2A hx2A closed this as completed in 1b170ab Oct 6, 2023
@hx2A
Copy link
Collaborator Author

hx2A commented Oct 6, 2023

@villares , here's what the new functions look like:

http://dev.py5coding.org/reference/py5tools_capture_frames.html
http://dev.py5coding.org/reference/py5tools_animated_gif.html

This is a breaking change because some of the parameters are now keyword only.

@villares
Copy link
Contributor

villares commented Oct 8, 2023

Great!

Check out this example, please: https://github.com/py5coding/py5examples/blob/main/notebooks/Simple%20py5%20Examples.ipynb

I'm going to hunt my sketch-a-day sketches that use animated_gif.

@hx2A
Copy link
Collaborator Author

hx2A commented Oct 8, 2023

Great!

Check out this example, please: https://github.com/py5coding/py5examples/blob/main/notebooks/Simple%20py5%20Examples.ipynb

After this release, that example won't work. The first parameter is fine but the last three will need to be keyword arguments:

py5_tools.animated_gif('images/test.gif', count=10, period=1, duration=1)

You should be able to use the keywords now and then you don't have to worry about stuff breaking when the release happens.

@villares
Copy link
Contributor

villares commented Oct 8, 2023

Yeah, this is what I was thinking, "retrofitting" my previous sketches with keyword arguments.

@villares
Copy link
Contributor

villares commented Oct 8, 2023

I hate regex, but I think this worked fine. I used regexxer, a helper to find and replace stuff on multiple files, for those less well versed with the traditional CLI regex workflow.

image

@hx2A
Copy link
Collaborator Author

hx2A commented Oct 8, 2023

I hate regex, but I think this worked fine. I used regexxer, a helper to find and replace stuff on multiple files, for those less well versed with the traditional CLI regex workflow.

Good choice!

Nobody likes regex at first. The only way to learn to like regex is to use it frequently enough that you get good at it. I try to seek out opportunities to use regex so I can continue build my ability to use regex.

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