<commit_before>#!/usr/bin/env python

'''
'''

__docformat__ = 'restructuredtext'
__version__ = '$Id$'

import sys

from pyglet import clock
from pyglet import image
from pyglet import window

w = window.Window()

class AnimationPlayer(object):
    expected_delay = 0

    def __init__(self, animation):
        self.animation = animation
        self.index = -1
        self.next_frame(0)

    def next_frame(self, dt):
        self.index = (self.index + 1) % len(self.animation.frames)
        frame = self.animation.frames[self.index]
        if frame.delay is not None:
            delay = frame.delay - (self.expected_delay - dt)
            delay = min(max(0, delay), frame.delay)
            clock.schedule_once(self.next_frame, delay)
            self.expected_delay = delay

    def blit(self, x, y):
        self.animation.frames[self.index].image.blit(x, y)

try:
    animation = image.load_animation(sys.argv[1])
except image.codecs.ImageDecodeException:
    from pyglet import media
    source = media.load(sys.argv[1])
    source._seek(0)
    animation = source.get_animation()

clock.tick()
player = AnimationPlayer(animation)

while not w.has_exit:
    clock.tick()

    w.dispatch_events()
    w.clear()
    player.blit(w.width//2, w.height//2)
    w.flip()
<commit_msg>experimental/animation.py: Fix frame.delay reference, which was renamed to   frame.duration in AnimationFrame in r6ddcd54890a1. Add meaningful version.<commit_after>#!/usr/bin/env python

'''
'''

__docformat__ = 'restructuredtext'
__version__ = '1.2'

import sys

from pyglet import clock
from pyglet import image
from pyglet import window

class AnimationPlayer(object):
    expected_delay = 0

    def __init__(self, animation):
        self.animation = animation
        self.index = -1
        self.next_frame(0)

    def next_frame(self, dt):
        self.index = (self.index + 1) % len(self.animation.frames)
        frame = self.animation.frames[self.index]
        if frame.duration is not None:
            delay = frame.duration - (self.expected_delay - dt)
            delay = min(max(0, delay), frame.duration)
            clock.schedule_once(self.next_frame, delay)
            self.expected_delay = delay

    def blit(self, x, y):
        self.animation.frames[self.index].image.blit(x, y)

try:
    animation = image.load_animation(sys.argv[1])
except image.codecs.ImageDecodeException:
    from pyglet import media
    source = media.load(sys.argv[1])
    source._seek(0)
    animation = source.get_animation()
except IndexError:
    sys.exit('usage: animation.py <image>')


w = window.Window()

clock.tick()
player = AnimationPlayer(animation)

while not w.has_exit:
    clock.tick()

    w.dispatch_events()
    w.clear()
    player.blit(w.width//2, w.height//2)
    w.flip()

{'fraction_non_alphanumeric': 0.11889367816091954, 'fraction_numerical': 0.010416666666666666, 'mean_word_length': 2.928067700987306, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5292388', 'n_tokens_mistral': 915, 'n_tokens_neox': 888, 'n_words': 204}