Skip to content

Commit

Permalink
Update Scene.save_state and Scene.restore
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Apr 21, 2022
1 parent cb768c2 commit 97400a5
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions manimlib/scene/scene.py
Expand Up @@ -575,22 +575,18 @@ def add_sound(

# Helpers for interactive development
def save_state(self) -> None:
self.saved_state = {
"mobjects": self.mobjects,
"mobject_states": [
mob.copy()
for mob in self.mobjects
],
}
self.saved_state = [
(mob, mob.copy())
for mob in self.mobjects
]

def restore(self) -> None:
if not hasattr(self, "saved_state"):
raise Exception("Trying to restore scene without having saved")
mobjects = self.saved_state["mobjects"]
states = self.saved_state["mobject_states"]
for mob, state in zip(mobjects, states):
mob.become(state)
self.mobjects = mobjects
self.mobjects = []
for mob, mob_state in self.saved_state:
mob.become(mob_state)
self.mobjects.append(mob)

# Event handling

Expand Down

0 comments on commit 97400a5

Please sign in to comment.