Beispiel #1
0
def demo_boxes(scene: CodeScene):
    scene.add_background(f"{example_dir}/resources/blackboard.jpg")

    title = Text("examples/boxes.py", font=DEFAULT_FONT)
    title.to_edge(UP)
    scene.add(title)
    comp1 = TextBox("Component A", shadow=False)
    comp2 = TextBox("Component B", shadow=False)
    comp3 = TextBox("Component C", shadow=False)
    comp1.next_to(title, DOWN, buff=2)
    comp1.to_edge(LEFT)
    comp2.next_to(comp1, DOWN, buff=1)
    comp3.next_to(comp1, RIGHT, buff=4)
    arrow1 = Connection(comp2, comp1, "Do something")
    arrow2 = Connection(comp1, comp3, "Do another thing")

    scene.play(FadeIn(comp2))
    scene.wait_until_beat(1)
    scene.play(Create(arrow1))
    scene.play(FadeIn(comp1))
    scene.wait_until_beat(1)
    scene.play(Create(arrow2))
    scene.play(FadeIn(comp3))

    scene.wait_until_beat(4)
    scene.clear()
 def add_to_scene(self,
                  scene,
                  initial_blank_seconds=0.,
                  end_blank_seconds=0.):
     scene.wait(initial_blank_seconds)
     scene.play(FadeIn(self.lol))
     scene.wait()
     scene.play(Write(self.commons), FadeIn(self.commons_left),
                FadeIn(self.commons_right))
     scene.wait(end_blank_seconds)
    def construct(self):

        # Atom level
        adenine = Text(ADENINE_SMILES)

        # Nucleotide level
        dna = Text('ACTGAATATAGACTATA',
                   t2c={
                       'A': RED,
                       'C': BLUE,
                       'T': GREEN,
                       'G': PURPLE
                   })

        # Amino acid level
        aas = 'VQGGAAVQQEVLA'
        aas = Text(aas, t2c=get_aa_hex_color_dict('skylign_protein'))

        # Logo level
        logo = LoLLogo()

        # Animate... from nucleotide to LoL Commons
        self.wait()
        self.play(Write(adenine))
        self.wait()

        if self.add_vector_transform:
            # FIXME: This is not quite pretty / useful at the moment
            numbers = Text(
                '[0.12 0.32 0.01 0.88 0.99 0.22 0.55 0.42 0.13 0.07]')
            replacements = [adenine, dna, aas, numbers, logo.lol]
        else:
            replacements = [adenine, dna, aas, logo.lol]

        for source, target in zip(replacements, replacements[1:]):
            self.play(ReplacementTransform(source, target))
            self.wait()

        self.play(Write(logo.commons), FadeIn(logo.commons_left),
                  FadeIn(logo.commons_right))
        self.wait()
        for replacer in self.replacers:
            logo.replace_left_right(self, replacer, run_time_s=0.8)
            self.wait(0.3)

        # Move logo to left lower corner
        if self.logo_down:
            mini_logo = logo.copy()
            mini_logo.scale(0.5)
            mini_logo.to_corner()
            self.play(Transform(logo, mini_logo))

        # And keep the scene
        # self.play(Write(Text('Corporate info follows...')))
        self.wait(5)
Beispiel #4
0
def test_scene_time():
    with tempconfig({"dry_run": True}):
        scene = Scene()
        assert scene.renderer.time == 0
        scene.wait(2)
        assert scene.renderer.time == 2
        scene.play(FadeIn(Circle()), run_time=0.5)
        assert pytest.approx(scene.renderer.time) == 2.5
        scene.renderer._original_skipping_status = True
        scene.play(FadeIn(Square()), run_time=5)  # this animation gets skipped.
        assert pytest.approx(scene.renderer.time) == 7.5
Beispiel #5
0
    def insert(self,
               bt_node,
               side_offset_multiply: float = 2.5,
               down_offset_multiply: float = 2.5,
               direction=LEFT,
               start_from_root=True) -> BinaryTreeNode:
        if self.is_full():
            raise AttributeError("This node %s is completed" %
                                 str(self.node_id))
        bt_node.parent = self
        if start_from_root:
            parents = [self]
            while parents[-1].parent is not None:
                parents.append(parents[-1].parent)
            self.scene.add(bt_node)
            bt_node.next_to(parents[-1], buff=0, direction=UP)
            parents.pop()
            self.scene.play(FadeIn(bt_node.value),
                            run_time=bt_node.animation_duration)
            while len(parents) > 0:
                elem = parents[-1]
                self.scene.play(bt_node.value.animate.next_to(elem, buff=0),
                                run_time=bt_node.animation_duration)
                parents.pop()
        else:
            bt_node.next_to(self.value, buff=0)
            self.scene.play(Write(bt_node.value),
                            run_time=bt_node.animation_duration)

        if direction is LEFT and self.has_left():
            direction = RIGHT
            self.right = bt_node
        else:
            self.left = bt_node
        child_location = self.value.get_center() + \
                         side_offset_multiply * self.radius * direction + \
                         down_offset_multiply * self.radius * DOWN
        parent_child_vector = normalize(child_location -
                                        self.value.get_center())

        edge_start = (self.value.get_center() +
                      parent_child_vector * self.radius)
        edge_end = child_location - parent_child_vector * self.radius
        edge = Line(edge_start, edge_end)

        self.scene.play(bt_node.value.animate.move_to(child_location),
                        FadeIn(edge),
                        run_time=bt_node.animation_duration)
        return bt_node
 def play_encode_decode(self, scene):
     scene.play(FadeIn(self.text))
     scene.wait(1)
     scene.play(ReplacementTransform(self.text, self.masked_text))
     scene.wait(1)
     scene.play(FadeIn(self.encoder), FadeIn(self.decoder))
     scene.wait(1)
     scene.play(
         ReplacementTransform(self.text.copy(), self.encoder),
         ReplacementTransform(self.encoder.copy(), self.embedding),
         ReplacementTransform(self.embedding.copy(), self.decoder),
         ReplacementTransform(self.decoder.copy(), self.masked_decoded))
     scene.wait(1)
     scene.play(ReplacementTransform(self.masked_decoded, self.decoded))
     scene.wait(1)
Beispiel #7
0
    def construct(self):

        comp1 = TextBox("Component A", shadow=False)
        comp2 = TextBox("Component B", shadow=False)
        comp3 = TextBox("Component C", shadow=False)
        comp1.to_edge(LEFT)
        comp2.next_to(comp1, DOWN, buff=1)
        comp3.next_to(comp1, RIGHT, buff=4)
        arrow1 = Connection(comp2, comp1, "Do something")
        arrow2 = Connection(comp1, comp3, "Another thing")

        self.play(FadeIn(comp2))
        self.play(Create(arrow1))
        self.play(FadeIn(comp1))
        self.play(Create(arrow2))
        self.play(FadeIn(comp3))

        self.wait(5)
    def construct(self):

        rng = np.random.RandomState(self.seed)

        moleculizer = partial(
            new_molecule,
            colors=lambda: rng.choice(MOLECULE_COLORS, size=3, replace=True))

        proteins = molecule_universe_grid(
            moleculizer, num_molecules=(5, 8)).scale(0.3).center()
        proteins_frame = SurroundingRectangle(proteins,
                                              color=WHITE).round_corners(0.5)
        universe_title = Text('Known proteins').scale(0.7).next_to(
            proteins_frame, UP)
        framed_proteins = VGroup(universe_title, proteins_frame,
                                 proteins).to_edge(LEFT)

        self.play(FadeIn(framed_proteins))
        self.wait(3)

        # --- Sequence -> Number -> MLM

        heavy, hcdr3 = hiv_antibody()
        heavy.next_to(framed_proteins, RIGHT)
        self.play(Transform(proteins[23], heavy))
        self.wait(5)

        mlm = MLM().next_to(framed_proteins, RIGHT)
        self.play(ShrinkToCenter(heavy))  # , mlm.text
        self.wait(5)

        # FIXME: just to break here
        if mlm.text is not None:
            return

        # --- Subsets
        selected_proteins = [
            proteins[i].copy() for i in rng.choice(
                len(proteins), replace=False, size=len(proteins) // 3)
        ]

        antibodies = VGroup(
            *
            [molecule_from_molecule(protein) for protein in selected_proteins])
        antibodies_frame = (SurroundingRectangle(antibodies).match_color(
            proteins_frame).match_width(proteins_frame).match_height(
                proteins_frame)).round_corners(0.5)
        framed_antibodies = VGroup(antibodies_frame, antibodies)

        framed_antibodies.next_to(proteins, RIGHT, buff=MED_LARGE_BUFF)
        self.play(
            *[
                ReplacementTransform(protein, antibody)
                for protein, antibody in zip(selected_proteins, antibodies)
            ], Write(antibodies_frame))
        self.wait(4)
Beispiel #9
0
    def construct(self):

        lib = Library()

        comp1 = lib.text_box("Component A", shadow=False)
        comp2 = lib.text_box("Component B", shadow=False)
        comp3 = lib.text_box("Component C", shadow=False)
        comp1.to_edge(LEFT)
        comp2.next_to(comp1, DOWN, buff=1)
        comp3.next_to(comp1, RIGHT, buff=4)
        arrow1 = lib.connect(comp2, comp1, "Do something")
        arrow2 = lib.connect(comp1, comp3, "Do another thing")

        self.play(FadeIn(comp2))
        self.play(ShowCreation(arrow1))
        self.play(FadeIn(comp1))
        self.play(ShowCreation(arrow2))
        self.play(FadeIn(comp3))

        self.wait(5)
Beispiel #10
0
def title_scene(scene):
    scene.add_background(f"{example_dir}/resources/blackboard.jpg")
    title = PangoText("How to use Code Video Generator", font="Helvetica")
    scene.play(ShowCreation(title))
    scene.play(
        FadeIn(
            PangoText("A code walkthrough",
                      font="Helvetica").scale(0.6).next_to(title,
                                                           direction=DOWN,
                                                           buff=LARGE_BUFF)))

    scene.wait(3)
    scene.clear()
Beispiel #11
0
def title_scene(scene):

    scene.add_background(f"{example_dir}/resources/blackboard.jpg")
    title = Text("How to use Code Video Generator", font="Helvetica")
    scene.play(Create(title))
    scene.play(
        FadeIn(
            Text(f"Code and examples from version {__version__}",
                 font="Helvetica").scale(0.6).next_to(title,
                                                      direction=DOWN,
                                                      buff=LARGE_BUFF)))

    scene.wait(3)
    scene.clear()
Beispiel #12
0
    def highlight_lines(self,
                        code: Code,
                        start: int = 1,
                        end: int = -1,
                        caption: Optional[str] = None):
        """
        Convenience method for animating a code object.

        Args:
            code: The code object, must be wrapped in `AutoScaled`
            start: The start line number
            end: The end line number, defaults to the end of the file
            caption: The text to display with the highlight
        """

        if end == -1:
            end = len(code.line_numbers) + code.line_no_from

        layout = ColumnLayout(columns=3)

        actions = []
        if caption and not self.caption:
            self.play(
                ApplyMethod(
                    code.fill_between_x,
                    layout.get_x(1, span=2, direction=LEFT),
                    layout.get_x(1, span=2, direction=RIGHT),
                ))

        if self.caption:
            actions.append(FadeOut(self.caption))
            self.caption = None

        if not caption:
            self.play(ApplyMethod(code.full_size))
        else:
            callout = TextBox(caption,
                              text_attrs=dict(size=0.4, font=DEFAULT_FONT))
            callout.align_to(code.line_numbers[start - code.line_no_from], UP)
            callout.set_x(layout.get_x(3), LEFT)
            actions += [HighlightLines(code, start, end), FadeIn(callout)]
            self.caption = callout

        self.play(*actions)

        if not self.caption:
            self.play(ApplyMethod(code.full_size))
        else:
            wait_time = len(self.caption.text) / (200 * 5 / 60)
            self.wait_until_measure(wait_time, -1.5)
Beispiel #13
0
def demo_boxes(scene: CodeScene):
    scene.add_background(f"{example_dir}/resources/blackboard.jpg")
    lib = Library()

    comp1 = lib.text_box("Component A", shadow=False)
    comp2 = lib.text_box("Component B", shadow=False)
    comp3 = lib.text_box("Component C", shadow=False)
    comp1.to_edge(LEFT)
    comp2.next_to(comp1, DOWN, buff=1)
    comp3.next_to(comp1, RIGHT, buff=4)
    arrow1 = lib.connect(comp2, comp1, "Do something")
    arrow2 = lib.connect(comp1, comp3, "Do another thing")

    scene.play(FadeIn(comp2))
    scene.wait_until_beat(1)
    scene.play(ShowCreation(arrow1))
    scene.play(FadeIn(comp1))
    scene.wait_until_beat(1)
    scene.play(ShowCreation(arrow2))
    scene.play(FadeIn(comp3))

    scene.wait_until_beat(4)
    scene.clear()
    def construct(self):

        a_million_forks = Text('A million forks in the road to our products'
                               )  # to drug development
        a_million_forks.to_edge(UP)

        new_drugs_per_billion_RD = [('1950', 100), ('1960', 50), ('1970', 10),
                                    ('1980', 5), ('1990', 3), ('2000', 2),
                                    ('2010', 1), ('2020', 1)]
        x = [x for x, _ in new_drugs_per_billion_RD]
        y = [y for _, y in new_drugs_per_billion_RD]
        colors = ["#003f5c", "#58508d", "#bc5090", "#ff6361", "#ffa600"]
        chart = BarChart(
            values=y,
            max_value=max(y),
            bar_colors=colors,
            bar_names=x,
            bar_label_scale_val=0.5,
        ).scale(0.8).to_edge(LEFT).shift(0.5 * DOWN)

        # text_top = (
        #     Text('EROOM\'s Law: More expensive, slower drug discovery')
        #     .scale(0.9)
        #     .next_to(chart, UP, buff=0.1)
        # )

        # text_left = (
        #     Text('Number of drugs per billion US$ R&D spending')
        #     .rotate(angle=TAU / 4, axis=OUT)
        #     .scale(0.3)
        #     .next_to(chart, LEFT, buff=0.5)
        # )

        text_top = (
            Text('Number of drugs per billion US$ R&D spending (log-scale)'
                 ).scale(0.3).next_to(chart, UP, buff=0.5))

        text_bottom = (
            Text("Eroom's law: a continuous decline in Pharma R&D productivity"
                 ).scale(0.3).next_to(chart, DOWN, buff=0.5))

        # --- Examples of forks in the road

        icons_text = [
            (SVGMobject(SVGS.ANTIBODY).set_color(BLUE).scale(0.8),
             Text('Is my antibody a potent, functional binder?')),
            (SVGMobject(SVGS.CYCLIC_PEPTIDE).set_color_by_gradient(
                BLUE, GREEN).scale(0.8),
             Text('Can we generate peptides without liabilities?')),
            (SVGMobject(SVGS.DNA).set_color_by_gradient(GREEN,
                                                        BLUE).scale(0.8),
             Text(
                 'Can we optimize DNA to better express traits in plants or humans?'
             )),
            (SVGMobject(SVGS.PACMAN).set_color(RED).scale(0.8),
             Text('What will an enzyme in the human gut do?')),
            # (
            #     SVGMobject(SVGS.PACMAN).set_color_by_gradient(GREEN, BLUE, RED).scale(0.8),
            #     Text('Can we optimize enzymes to better manufacture bioproducts?')
            # ),
            (SVGMobject(SVGS.PROTEIN3D).set_color_by_gradient(
                GREEN, BLUE, RED).scale(0.8),
             Text('What is the 3D structure of my biomolecule?')),
            (SVGMobject(SVGS.PATIENT).set_color_by_gradient(BLUE,
                                                            RED).scale(0.8),
             Text('Will a patient respond to treatment in a clinical trial?')),
            (SVGMobject(SVGS.MUTATION).set_color_by_gradient(BLUE, GREEN,
                                                             RED).scale(0.8),
             Text('...'))
        ]

        # icons_text = icons_text[:1]

        for (icon1, _), (icon2, _) in zip(icons_text, icons_text[1:]):
            icon2.next_to(icon1, DOWN, buff=0.5)

        for icon, text in icons_text:
            text.next_to(icon, RIGHT)

        questions = VGroup(*chain.from_iterable(icons_text))
        questions.scale(0.32)
        questions.next_to(chart, RIGHT, buff=1).shift(0.5 * UP)

        logo = LoLLogo().scale(0.7)
        # logo.next_to(questions, DOWN, buff=0.5)
        logo.move_to(questions)

        # --- Animate

        self.play(FadeIn(text_top))
        self.play(Write(chart), Write(text_bottom), run_time=4)
        self.wait(2)
        self.play(Write(a_million_forks))
        for icon, text in icons_text:
            self.play(FadeIn(icon, text))
            self.wait(3)

        # if we have put the logo under the questions...
        # self.play(FadeIn(logo))

        # if we prefer the logo to morph from the questions
        actionable_insights = (Text(
            'Getting actionable insights from biological sequences').next_to(
                logo, DOWN, buff=0.5).scale(0.4))
        self.play(ReplacementTransform(questions, logo))
        self.play(Write(actionable_insights))
        self.wait(2)