-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.py
More file actions
124 lines (98 loc) · 2.79 KB
/
components.py
File metadata and controls
124 lines (98 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from xml.dom import minidom
from copy import copy
import os
from tempfile import NamedTemporaryFile
from xml.etree import ElementTree
from manim import *
from mobject.geometry import *
from mobject.svg.svg_mobject import *
from animation.animation import *
from animation.creation import *
from animation.indication import *
from animation.transform import *
class SvgBuilder():
"""
Construye la estructura a partir de un svg. Los rect son registros, el
resto son señales combinacinales
"""
def __init__(self, path):
self.registers = None
self.combinational = None
self.all = None
self._cycle_time = 10
self._register_transform_time = 1
if not os.path.isabs(path):
path = SVG_IMAGE_DIR + os.sep + path
if path is None or not os.path.exists(path):
return
self._init_from_file(path)
def _init_from_file(self, path):
with open(path) as f:
self.all = SVGMobject(file_name=f.name)
self.all.set_stroke(width=1,color="White")
self.all.set_fill(opacity=0)
self.registers = \
VMobject(*filter(lambda x: isinstance(x, Rectangle), self.all.submobjects))
self.registers.set_stroke(width=1,color=PINK)
self.registers.set_fill(opacity=0)
self.combinational = \
VMobject(*filter(lambda x: isinstance(x, VMobjectFromSVGPathstring), self.all.submobjects))
self.combinational.set_stroke(width=1,color=WHITE)
self.combinational.set_fill(opacity=0)
def get_animation(self):
retval = []
from_anim = self.registers.copy()
from_anim.set_stroke(width=1,color=BLUE_E)
to_anim = self.registers.copy()
to_anim.set_stroke(width=1,color=RED_E)
return Transform(from_anim, to_anim)
def get_registers(self):
return self.registers
def get_combinational(self):
return self.combinational
def get_all(self):
return self.all
class Signal(Line):
"""
Modela una señal, osea, un “cable”
"""
def __init__(self, points=None):
"""
Crea que recorre cada punto x1, x2...
"""
self.edge_color = LIGHT_GREY
self.edge_stroke_width = 2
self.edge_propogation_color = YELLOW
self.edge_propogation_time = 1
self.points = points if points is not None else []
self.edges = VGroup()
for i in range(0, len(self.points) - 1):
edge = Line(
self.points[i],
self.points[i + 1],
stroke_color=self.edge_color,
stroke_width=self.edge_stroke_width * 10,
name="Line"+str(i)
)
edge.set_stroke(
self.edge_propogation_color,
width = 1.5 * self.edge_stroke_width
)
self.edges.add(edge)
def get_edge_propogation_animations(self):
"""
Animación de color
"""
animations = []
for edge in self.edges:
animations += [ShowCreation(
edge.copy(),
run_time=self.edge_propogation_time,
)]
return [Succession(*animations)]
def getEdges(self):
return self.edges
class Register():
pass