Mercurial > code > home > repos > light9
comparison flax/Timeline.py @ 110:490843093506
all of this stuff is super rough and not well thought out yet.
all of this stuff is super rough and not well thought out yet.
i'm just checking in so we have some stuff to work with for the
sprint tonight.
author | dmcc |
---|---|
date | Tue, 10 Jun 2003 10:31:57 +0000 |
parents | ec82e1eea3c8 |
children | 2ed9bfd1dd0e |
comparison
equal
deleted
inserted
replaced
109:ec82e1eea3c8 | 110:490843093506 |
---|---|
2 DummyClass, last_less_than, first_greater_than | 2 DummyClass, last_less_than, first_greater_than |
3 from time import time | 3 from time import time |
4 from __future__ import division # "I'm sending you back to future!" | 4 from __future__ import division # "I'm sending you back to future!" |
5 | 5 |
6 """ | 6 """ |
7 Changelog: | 7 Quote of the Build (from Ghostbusters II) |
8 Fri May 16 15:17:34 PDT 2003 | 8 Dana: Okay, but after dinner, I don't want you putting any of your old cheap |
9 Project started (roughly). | 9 moves on me. |
10 | 10 Peter: Ohhhh no! I've got all NEW cheap moves. |
11 Mon May 19 17:56:24 PDT 2003 | |
12 Timeline is more or less working. Still bugs with skipping | |
13 FunctionFrames at random times. | |
14 | 11 |
15 Timeline idea | 12 Timeline idea |
16 ============= | 13 ============= |
17 time | 0 1 2 3 4 5 6 | 14 time | 0 1 2 3 4 5 6 |
18 ---------+----------------------------- | 15 ---------+----------------------------- |
175 | 172 |
176 # this too | 173 # this too |
177 class LoopFunction(FunctionFrame): | 174 class LoopFunction(FunctionFrame): |
178 def __call__(self, timeline, timedevent, node): | 175 def __call__(self, timeline, timedevent, node): |
179 timeline.set_time(0) | 176 timeline.set_time(0) |
180 print 'looped!' | 177 # print 'looped!' |
181 | 178 |
182 class DoubleTimeFunction(FunctionFrame): | 179 class DoubleTimeFunction(FunctionFrame): |
183 def __call__(self, timeline, timedevent, node): | 180 def __call__(self, timeline, timedevent, node): |
184 timeline.set_rate(2 * timeline.rate) | 181 timeline.set_rate(2 * timeline.rate) |
182 print 'doubled!', timeline.rate | |
185 | 183 |
186 class HalfTimeFunction(FunctionFrame): | 184 class HalfTimeFunction(FunctionFrame): |
187 def __call__(self, timeline, timedevent, node): | 185 def __call__(self, timeline, timedevent, node): |
188 timeline.set_rate(0.5 * timeline.rate) | 186 timeline.set_rate(0.5 * timeline.rate) |
187 print 'halved!', timeline.rate | |
189 | 188 |
190 class TimedEvent: | 189 class TimedEvent: |
191 """Container for a Frame which includes a time that it occurs at, | 190 """Container for a Frame which includes a time that it occurs at, |
192 and which blender occurs after it.""" | 191 and which blender occurs after it.""" |
193 def __init__(self, time, frame, blender=None): | 192 def __init__(self, time, frame, blender=None): |
324 """Returns all events between i and j, exclusively. If direction | 323 """Returns all events between i and j, exclusively. If direction |
325 is FORWARD, j will be included. If direction is BACKWARD, i will | 324 is FORWARD, j will be included. If direction is BACKWARD, i will |
326 be included. This is because this is used to find FunctionFrames | 325 be included. This is because this is used to find FunctionFrames |
327 and we assume that any function frames at the start point (which | 326 and we assume that any function frames at the start point (which |
328 could be i or j) have been processed.""" | 327 could be i or j) have been processed.""" |
328 return [e for e in self.events if e >= i and e <= j] | |
329 | |
329 if direction == FORWARD: | 330 if direction == FORWARD: |
330 return [e for e in self.events if e > i and e <= j] | 331 return [e for e in self.events if e > i and e <= j] |
331 else: | 332 else: |
332 return [e for e in self.events if e >= i and e < j] | 333 return [e for e in self.events if e >= i and e < j] |
333 def __getitem__(self, key): | 334 def __getitem__(self, key): |
414 clock_time = time() | 415 clock_time = time() |
415 if last_clock is None: | 416 if last_clock is None: |
416 last_clock = clock_time | 417 last_clock = clock_time |
417 diff = clock_time - last_clock | 418 diff = clock_time - last_clock |
418 new_time = (self.direction * self.rate * diff) + last_time | 419 new_time = (self.direction * self.rate * diff) + last_time |
419 new_time = max(new_time, 0) | |
420 new_time = min(new_time, self.length()) | |
421 | 420 |
422 # update the time | 421 # update the time |
423 self.last_clock_time = clock_time | 422 self.last_clock_time = clock_time |
424 self.current_time = new_time | 423 self.current_time = new_time |
425 | 424 |
426 # now, find out if we missed any functions | 425 # now, find out if we missed any functions |
427 if self.fn_track.has_events(): | 426 if self.fn_track.has_events(): |
428 lower_time, higher_time = last_time, new_time | 427 lower_time, higher_time = last_time, new_time |
428 if lower_time == higher_time: print "zarg!" | |
429 if lower_time > higher_time: | 429 if lower_time > higher_time: |
430 lower_time, higher_time = higher_time, lower_time | 430 lower_time, higher_time = higher_time, lower_time |
431 | 431 |
432 events_to_process = self.fn_track.get_range(lower_time, | 432 events_to_process = self.fn_track.get_range(lower_time, |
433 higher_time, self.direction) | 433 higher_time, self.direction) |
434 | 434 |
435 for event in events_to_process: | 435 for event in events_to_process: |
436 # they better be FunctionFrames | 436 # they better be FunctionFrames |
437 event.frame(self, event, None) # the None should be a Node, | 437 event.frame(self, event, None) # the None should be a Node, |
438 # but that part is coming later | 438 # but that part is coming later |
439 | |
440 # now we make sure we're in bounds (we don't do this before, since it | |
441 # can cause us to skip events that are at boundaries. | |
442 self.current_time = max(self.current_time, 0) | |
443 self.current_time = min(self.current_time, self.length()) | |
439 def reverse_direction(self): | 444 def reverse_direction(self): |
440 """Reverses the direction of play for this node""" | 445 """Reverses the direction of play for this node""" |
441 self.direction = self.direction * -1 | 446 self.direction = self.direction * -1 |
442 def set_direction(self, direction): | 447 def set_direction(self, direction): |
443 """Sets the direction of playback.""" | 448 """Sets the direction of playback.""" |
473 T(0, scene1, blender=linear), | 478 T(0, scene1, blender=linear), |
474 T(5, scene2, blender=quad), | 479 T(5, scene2, blender=quad), |
475 T(10, scene3, blender=smoove), | 480 T(10, scene3, blender=smoove), |
476 T(15, scene2)) # last TimedEvent doesn't need a blender | 481 T(15, scene2)) # last TimedEvent doesn't need a blender |
477 | 482 |
478 if 1: | 483 halver = HalfTimeFunction('1/2x') |
484 doubler = DoubleTimeFunction('2x') | |
485 if 0: | |
479 # bounce is semiworking | 486 # bounce is semiworking |
480 bouncer = BounceFunction('boing') | 487 bouncer = BounceFunction('boing') |
481 halver = HalfTimeFunction('1/2x') | |
482 doubler = DoubleTimeFunction('2x') | |
483 tl = Timeline([track1], [T(0, bouncer), | 488 tl = Timeline([track1], [T(0, bouncer), |
484 T(0, halver), | 489 T(0, halver), |
485 T(15, bouncer), | 490 T(15, bouncer), |
486 T(15, doubler)]) | 491 T(15, doubler)]) |
487 else: | 492 else: |
488 looper = LoopFunction('loop1') | 493 looper = LoopFunction('loop1') |
489 tl = Timeline([track1], [T(14, looper)]) | 494 tl = Timeline([track1], [T(0, doubler), |
495 T(5, halver), | |
496 T(14, looper)]) | |
490 tl.play() | 497 tl.play() |
491 | 498 |
492 import Tix | 499 import Tix |
493 root = Tix.Tk() | 500 root = Tix.Tk() |
494 colorscalesframe = Tix.Frame(root) | 501 colorscalesframe = Tix.Frame(root) |