Skip to content

Commit

Permalink
Refactor - part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
marekkirejczyk committed Jun 17, 2023
1 parent 2463b27 commit 5d9a20c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
4 changes: 2 additions & 2 deletions zkmarek/video/mobjects/signature.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from manim import DOWN, LEFT, YELLOW, Create, Line, Rectangle, Text, Write, VGroup
from manim import DOWN, LEFT, YELLOW, Create, Line, Rectangle, MathTex, Write, VGroup

class Signature(VGroup):
def __init__(self, height=3, color=YELLOW):
Expand All @@ -8,7 +8,7 @@ def __init__(self, height=3, color=YELLOW):
start = 0.45 * width * LEFT + 0.25 * height * DOWN
end = -0.45 * width * LEFT + 0.25 * height * DOWN
self.line = Line(start, end, color=color)
self.text = Text("Signature", color=color)
self.text = MathTex("Signature", color=color)
self.text.scale(height)
self.add(self.rect, self.line, self.text)

Expand Down
81 changes: 57 additions & 24 deletions zkmarek/video/slides/ec/signature.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from manim import (DOWN, GREEN, GREY, LEFT, RED, RIGHT, UP, Create, DashedLine,
FadeIn, FadeOut, MathTex, Mobject, Rectangle, Scene,
SurroundingRectangle, Text, Transform, VGroup)
from zkmarek.video.mobjects.signature import Signature as SignatureBoxFront

from zkmarek.video.slides.common.slide_base import SlideBase


class Box(VGroup):
class BoxWithIcons(VGroup):
rectangle: Rectangle

def __init__(self, *mobjects, **kwargs):
super().__init__(*mobjects, **kwargs)
self.arrange_in_grid(cols=2, cell_alignment=LEFT + UP)
self.arrange_in_grid(cols=2, cell_alignment=LEFT)
self.rectangle = SurroundingRectangle(self, buff=0.2, corner_radius=0.1)
self.add(self.rectangle)
self.rectangle.set_center(self.get_center())
Expand All @@ -27,26 +27,23 @@ def morph_to(self, scene: Scene, index: int, new_mobject: Mobject):
scene.remove(self.rectangle)
self.rectangle = new_rect

@staticmethod
def create_one_row(text1, math1, color1):
return BoxWithIcons(
Text(text1, color=color1),
MathTex(math1, color=color1))

class KeyBox(Box):
def __init__(self):
super().__init__(
Text("⚿", color=RED),
MathTex("K_{Priv} = k (random)", color=RED),
Text("⚿", color=GREEN),
MathTex("K_{Pub} = k \cdot G", color=GREEN),
)

@staticmethod
def create_two_rows(text1, math1, color1, text2, math2, color2):
return BoxWithIcons(
Text(text1, color=color1),
MathTex(math1, color=color1),
Text(text2, color=color2),
MathTex(math2, color=color2))

class MsgBox(Box):
def __init__(self):
super().__init__(
Text("✉", color=GREEN),
MathTex('msg = hash("...")', color=GREEN),
)


class SignatureBox(Box):
class SignatureBox(BoxWithIcons):
def __init__(self):
super().__init__(
Text("⚂", color=RED),
Expand All @@ -60,7 +57,7 @@ def __init__(self):
)


class VerifyBox(Box):
class VerifyBox(BoxWithIcons):
def __init__(self, *mobjects, **kwargs):
super().__init__(
Text(""),
Expand All @@ -74,7 +71,7 @@ def __init__(self, *mobjects, **kwargs):
)


class ExpansionBox(Box):
class ExpansionBox(BoxWithIcons):
def __init__(self, *mobjects, **kwargs):
super().__init__(
Text(""),
Expand All @@ -101,9 +98,7 @@ def __init__(self):
super().__init__("Signature")

def construct(self):
self.key_box = KeyBox()
self.signature_box = SignatureBox()
self.msg_box = MsgBox()
self.verify_box = VerifyBox()
self.expansion_box = ExpansionBox()
self.title = "Signature"
Expand All @@ -122,6 +117,44 @@ def fade_in_board(self, scene):
scene.play(Create(self.h_line))

def animate_in(self, scene):
self.fade_in_board(scene)
key_box1 = BoxWithIcons.create_two_rows(
"⚿", "Private\ key", RED,
"⚿", "Public", GREEN
).next_to(self.sender_label, DOWN, buff=0.5)


key_box2 = BoxWithIcons.create_two_rows(
"⚿", "K_{Priv} = k\ (random)", RED,
"⚿", "K_{Pub} = k \cdot G", GREEN
).next_to(self.sender_label, DOWN, buff=0.5)

msg_box1 = BoxWithIcons.create_one_row(
"✉", "Lorem\ ipsum\ dolor\ sit\ amet...", GREEN
).next_to(key_box2, DOWN, buff=0.5)

msg_box2 = BoxWithIcons.create_one_row(
"✉", "hash(\"Lorem\ ipsum\ dolor\ sit\ amet...\")", GREEN
).next_to(key_box2, DOWN, buff=0.5)

msg_box3 = BoxWithIcons.create_one_row(
"✉", "hash(\"...\")", GREEN
).next_to(key_box2, DOWN, buff=0.5)

signature = SignatureBoxFront(height=1).next_to(
msg_box3, DOWN, buff=0.5
)

scene.play(FadeIn(key_box1))
scene.play(FadeIn(msg_box1))
signature.animate_in(scene)
scene.play(Transform(msg_box1, msg_box2))
scene.remove(msg_box1)
scene.play(Transform(msg_box2, msg_box3))
scene.play(Transform(key_box1, key_box2))


def animate_in2(self, scene):
self.fade_in_board(scene)
self.key_box.next_to(self.sender_label, DOWN, buff=1)
scene.play(FadeIn(self.key_box))
Expand All @@ -137,7 +170,7 @@ def animate_in(self, scene):
self.expansion_box.next_to(self.verify_box, DOWN, buff=0.5)
scene.play(FadeIn(self.expansion_box))

def animate_out(self, scene):
def animate_out2(self, scene):
scene.play(
FadeOut(self.expansion_box),
FadeOut(self.verify_box),
Expand Down

0 comments on commit 5d9a20c

Please sign in to comment.