Esempio n. 1
0
    def construct(self):
        # Setup
        line = NumberLine()
        house = House()
        drunk = Drunk(direction=RIGHT)
        house.place_on(ORIGIN)
        drunk.step_on(ORIGIN)
        t_equals = TexMobject("t = ")
        time = TexMobject("0")
        time.next_to(t_equals, RIGHT, buff=0.15)
        VGroup(t_equals, time).next_to(line, DOWN, buff=0.5)
        old_drunk = drunk.copy()
        old_time = time.copy()
        self.add(house, line, drunk, t_equals)

        # Start wandering
        for k in range(20):
            new_time = TexMobject("%s" % str(k + 1))
            new_time.next_to(t_equals, RIGHT, buff=0.15)
            self.play(
                DrunkWander(drunk, random.choice([-1, 1]), total_time=0.5),
                Transform(time,
                          new_time,
                          rate_func=snap_head_and_tail(smooth),
                          run_time=0.5),
            )
        self.wait()

        # Reset
        self.play(Transform(time, old_time), Transform(drunk, old_drunk))
        self.wait()
Esempio n. 2
0
 def generate_sea_of_zeros(self):
     zero = TexMobject("0")
     self.sea_of_zeros = []
     for n in range(self.nrows):
         for a in range((self.nrows - n) / 2 + 1):
             for k in (n + a + 1, -a - 1):
                 self.coords.append((n, k))
                 mob = zero.copy()
                 mob.shift(self.coords_to_center(n, k))
                 self.coords_to_mobs[n][k] = mob
                 self.add(mob)
     return self