Skip to content Skip to sidebar Skip to footer

Controlling Dynamic Properties In Shady According To Video Frames Not Time

I am trying to use Shady to present a sequence of image frames. I'm controlling the flow from another machine, so that I first instruct the machine running Shady to present the fir

Solution 1:

When you make s.page a dynamic property, the function assigned to it must take one argument (t), but you can still just use any variables in the space when defining that function, and not even use the time argument at all.

So, for example, you could do something as simple as:

w = Shady.World(...)
s = w.Stimulus(...)
s.page = lambda t: w.framesCompleted

which will set the page property to the current frame count. That sounds like it could be useful for your problem.

Solution 2:

Your global-variable idea is one perfectly valid way to do this. Or, since it looks like you're defining things as methods of an instance of your own custom class, you could use instance methods as your animation callbacks and/or dynamic property values—then, instead of truly global variables, it makes sense to use attributes of self:

import Shady

classFoo(object):

    def__init__(self, stimSources):
        self.wind = Shady.World()
        self.stim = self.wind.Stimulus(stimSources, multipage=True)
        self.stim.page = self.determinePage  # dynamic property assignmentdefdeterminePage(self, t):
        # Your logic here.# Ignore `t` if you think that's appropriate.# Use `self.wind.framesCompleted` if it's helpful.# And/or use custom attributes of `self` if that's# helpful (or, similarly, global variables if you must).# But since this is called once per frame (whenever the# frame happens to be) it could be as simple as:return self.stim.page + 1# ...which is indefinitely sustainable since page lookup# will wrap around to the number of available pages.# Let's demo this idea:
foo = Foo(Shady.PackagePath('examples/media/alien1/*.png'))
Shady.AutoFinish(foo.wind)

Equivalent to that simple example, you could have the statementself.stim.page += 1 (and whatever other logic) inside a more-general animation callback.

Another useful tool for frame-by-frame animation is support for python's generator functions, i.e. functions that include a yield statement. Worked examples are included in python -m Shady demo precision and python -m Shady demo dithering.

It can also be done in a StateMachine which is always my preferred answer to such things:

import Shady

classFoo(object):
    def__init__(self, stimSources):
        self.wind = Shady.World()
        self.stim = self.wind.Stimulus(stimSources, multipage=True)


foo = Foo(Shady.PackagePath('examples/media/alien1/*.png'))         

sm = Shady.StateMachine()
@sm.AddStateclassPresentTenFrames(sm.State):
    defongoing(self): # called on every frame while the state is active
        foo.stim.page += 1if foo.stim.page > 9:
            self.ChangeState()

@sm.AddStateclassSelfDestruct(sm.State):
    onset = foo.wind.Close

foo.wind.SetAnimationCallback(sm)

Shady.AutoFinish(foo.wind)

Post a Comment for "Controlling Dynamic Properties In Shady According To Video Frames Not Time"