Skip to content

Commit

Permalink
animate by timeline order (left to right)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyboardAnt committed Nov 17, 2024
1 parent 2e3dc8f commit 0b80d2c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions docs/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,29 @@ def animate_algorithm(
algo_label = self.create_algorithm_label(algorithm.name, vertical_position)
self.play(Write(algo_label))

# Create and animate GPUs using the timeline's actual start position
# First, collect all rectangles grouped by their starting x position
rectangles_by_x = {}
for i, gpu in enumerate(algorithm.gpus):
current_x = start_x # Use the timeline's actual start x-coordinate
current_x = start_x
current_y = vertical_position - (i * self.gpu_config.vertical_spacing)

for time_unit in gpu.time_units:
if time_unit.color is not None:
rect = self.create_gpu_rectangle(
time_unit, np.array([current_x, current_y, 0])
)
self.play(Create(rect), run_time=self.gpu_config.animation_speed)
if current_x not in rectangles_by_x:
rectangles_by_x[current_x] = []
rectangles_by_x[current_x].append(rect)
current_x += time_unit.width

# Animate rectangles in order of their x positions
for x in sorted(rectangles_by_x.keys()):
self.play(
*[Create(rect) for rect in rectangles_by_x[x]],
run_time=self.gpu_config.animation_speed,
)

def construct(self):
# Create timeline
timeline_group = self.create_timeline()
Expand Down

0 comments on commit 0b80d2c

Please sign in to comment.