Giter Club home page Giter Club logo

Comments (5)

maxhumber avatar maxhumber commented on May 21, 2024

Hey @davidwych! Thanks for the issue and suggestion.

I can look at adding the non-loop parameter 👍 Can I ask why you want it? I've never had a scenario when I didn't want something to loop.

As for the other issue. Could you drop in your data, so I can poke at it?

from gif.

davidwych avatar davidwych commented on May 21, 2024

@maxhumber

(1) The non-loop functionality would be useful for "one-time use" animations (e.g. in my case I'm creating this gif for a slide in a presentation, so I really just need the animation to run through once and then stay in the form it's in at the last frame for the remaining time I'm presenting the slide).

(2) Here's the piano data:
piano.npy.zip

to load it:

piano = np.load("piano.npy")
t = np.linspace(0, len(piano)/22050, len(piano))

n.b. in the code above: replace piano[0] with just piano

from gif.

maxhumber avatar maxhumber commented on May 21, 2024

Okay, figured out your first thing!

Seems like you need to adjust your ifs. Basically, you need two for every note. One to track the note, and another to keep the color turned on.

See this reproducible example:

import gif
from matplotlib import pyplot as plt

x = list(range(100))
y = [10] * len(x)

@gif.frame
def plot(i):
    plt.plot(x[:i], y[:i])
    plt.xlim([0, max(x)])
    plt.ylim([0, max(y) * 2])
    # track the RED note
    if x[i] > 50 and x[i] < 70:
        plt.axvspan(50, x[i-1], facecolor="Red", ls="--", lw=2.0, alpha=0.2)
    # track the BLUE note
    if x[i] > 80 and x[i] < 90:
        plt.axvspan(80, x[i-1], facecolor="Blue", ls="--", lw=2.0, alpha=0.2)
    # make sure the RED stays on
    if x[i] >= 70:
        plt.axvspan(50, 70, facecolor="Red", ls="--", lw=2.0, alpha=0.2)
    # make sure the BLUE stays on
    if x[i] >= 90:
        plt.axvspan(80, 90, facecolor="Blue", ls="--", lw=2.0, alpha=0.2)

frames = []
for i in range(len(x)):
    frame = plot(i)
    frames.append(frame)

gif.save(frames, 'piano.gif', duration=30)

Output:

piano

from gif.

maxhumber avatar maxhumber commented on May 21, 2024

As for the non-looping. Let me meditate on it... for now... just skip the slide a millisecond before it finishes 🤣

from gif.

davidwych avatar davidwych commented on May 21, 2024

Thanks so much! Sorry if this wasn't really an "issue" so much as me not knowing how conditionals work... :|

I thought maybe it had something to do with how arguments are handled by the decorator.

from gif.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.