manimvox 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- manimvox/__init__.py +11 -0
- manimvox/_blocks/bar-ranking/block.json +18 -0
- manimvox/_blocks/bar-ranking/block.py +44 -0
- manimvox/_blocks/bar-ranking/demo.py +18 -0
- manimvox/_blocks/bar-ranking/preview.png +0 -0
- manimvox/_blocks/bug-grid/block.json +16 -0
- manimvox/_blocks/bug-grid/block.py +18 -0
- manimvox/_blocks/bug-grid/demo.py +14 -0
- manimvox/_blocks/bug-grid/preview.png +0 -0
- manimvox/_blocks/code-diff/block.json +16 -0
- manimvox/_blocks/code-diff/block.py +51 -0
- manimvox/_blocks/code-diff/demo.py +26 -0
- manimvox/_blocks/code-diff/preview.png +0 -0
- manimvox/_blocks/line-by-level/block.json +17 -0
- manimvox/_blocks/line-by-level/block.py +51 -0
- manimvox/_blocks/line-by-level/demo.py +17 -0
- manimvox/_blocks/line-by-level/preview.png +0 -0
- manimvox/_blocks/log-scatter/block.json +18 -0
- manimvox/_blocks/log-scatter/block.py +49 -0
- manimvox/_blocks/log-scatter/demo.py +18 -0
- manimvox/_blocks/log-scatter/preview.png +0 -0
- manimvox/_blocks/mesh-model/block.json +16 -0
- manimvox/_blocks/mesh-model/block.py +48 -0
- manimvox/_blocks/mesh-model/demo.py +32 -0
- manimvox/_blocks/mesh-model/preview.png +0 -0
- manimvox/_blocks/request-flow/block.json +16 -0
- manimvox/_blocks/request-flow/block.py +24 -0
- manimvox/_blocks/request-flow/demo.py +17 -0
- manimvox/_blocks/request-flow/preview.png +0 -0
- manimvox/_blocks/sequence-diagram/block.json +17 -0
- manimvox/_blocks/sequence-diagram/block.py +31 -0
- manimvox/_blocks/sequence-diagram/demo.py +15 -0
- manimvox/_blocks/sequence-diagram/preview.png +0 -0
- manimvox/_blocks/surface-plot/block.json +18 -0
- manimvox/_blocks/surface-plot/block.py +68 -0
- manimvox/_blocks/surface-plot/demo.py +23 -0
- manimvox/_blocks/surface-plot/preview.png +0 -0
- manimvox/_blocks/token-panel/block.json +14 -0
- manimvox/_blocks/token-panel/block.py +29 -0
- manimvox/_blocks/token-panel/demo.py +15 -0
- manimvox/_blocks/token-panel/preview.png +0 -0
- manimvox/_blocks/venn/block.json +17 -0
- manimvox/_blocks/venn/block.py +21 -0
- manimvox/_blocks/venn/demo.py +14 -0
- manimvox/_blocks/venn/preview.png +0 -0
- manimvox/_cairo.py +45 -0
- manimvox/_skills/manimvox/SKILL.md +61 -0
- manimvox/_skills/manimvox-animation/SKILL.md +40 -0
- manimvox/_skills/manimvox-animation/references/adapters.md +89 -0
- manimvox/_skills/manimvox-animation/references/patterns.md +236 -0
- manimvox/_skills/manimvox-animation/references/three-d.md +111 -0
- manimvox/_skills/manimvox-blocks/SKILL.md +53 -0
- manimvox/_skills/manimvox-blocks/references/writing-a-block.md +41 -0
- manimvox/_skills/manimvox-cli/SKILL.md +142 -0
- manimvox/_skills/manimvox-concept/SKILL.md +89 -0
- manimvox/_skills/manimvox-core/SKILL.md +76 -0
- manimvox/_skills/manimvox-core/references/author-guide.md +121 -0
- manimvox/_skills/manimvox-creative/SKILL.md +31 -0
- manimvox/_skills/manimvox-creative/references/facts.md +32 -0
- manimvox/_skills/manimvox-creative/references/narration.md +27 -0
- manimvox/_skills/manimvox-creative/references/script.md +119 -0
- manimvox/_skills/manimvox-creative/references/story.md +78 -0
- manimvox/_skills/manimvox-creative/references/theming.md +98 -0
- manimvox/_skills/manimvox-paper/SKILL.md +97 -0
- manimvox/_skills/manimvox-playlist/SKILL.md +77 -0
- manimvox/_skills/manimvox-playlist/references/series-design.md +48 -0
- manimvox/_skills/manimvox-playlist/sub-agents/episode-author.md +42 -0
- manimvox/_skills/manimvox-pr/SKILL.md +96 -0
- manimvox/_skills/manimvox-voice/SKILL.md +135 -0
- manimvox/blocks.py +191 -0
- manimvox/checks/__init__.py +15 -0
- manimvox/checks/audio.py +86 -0
- manimvox/checks/layout.py +70 -0
- manimvox/checks/sheets.py +52 -0
- manimvox/checks/theme.py +77 -0
- manimvox/cli.py +430 -0
- manimvox/confirm.py +15 -0
- manimvox/integrations/__init__.py +5 -0
- manimvox/integrations/agno.py +30 -0
- manimvox/integrations/common.py +280 -0
- manimvox/integrations/crewai.py +30 -0
- manimvox/integrations/google_adk.py +58 -0
- manimvox/integrations/haystack.py +42 -0
- manimvox/integrations/langchain.py +53 -0
- manimvox/integrations/llamaindex.py +28 -0
- manimvox/integrations/openai_agents.py +30 -0
- manimvox/integrations/pydantic_ai.py +28 -0
- manimvox/kit/__init__.py +59 -0
- manimvox/kit/_context.py +30 -0
- manimvox/kit/colours.py +37 -0
- manimvox/kit/components.py +259 -0
- manimvox/kit/episode.py +411 -0
- manimvox/kit/icons.py +85 -0
- manimvox/kit/mesh.py +138 -0
- manimvox/kit/text.py +78 -0
- manimvox/kit/theme.py +73 -0
- manimvox/playlist.py +210 -0
- manimvox/post/__init__.py +2 -0
- manimvox/post/audio.py +70 -0
- manimvox/post/draw.py +111 -0
- manimvox/post/encode.py +124 -0
- manimvox/post/finish.py +109 -0
- manimvox/post/options.py +68 -0
- manimvox/project.py +174 -0
- manimvox/runner.py +51 -0
- manimvox/scaffold.py +58 -0
- manimvox/scenes/__init__.py +10 -0
- manimvox/scenes/charts.py +142 -0
- manimvox/scenes/clip.py +112 -0
- manimvox/scenes/model.py +161 -0
- manimvox/scenes/raster.py +42 -0
- manimvox/skills.py +143 -0
- manimvox/skills_admin.py +251 -0
- manimvox/templates/FACTS.md +17 -0
- manimvox/templates/SERIES.md +55 -0
- manimvox/templates/__init__.py +0 -0
- manimvox/templates/gitignore +6 -0
- manimvox/tools.py +619 -0
- manimvox/voice/__init__.py +79 -0
- manimvox/voice/base.py +114 -0
- manimvox/voice/cache.py +30 -0
- manimvox/voice/convert.py +42 -0
- manimvox/voice/download.py +114 -0
- manimvox/voice/engines/__init__.py +1 -0
- manimvox/voice/engines/edge.py +80 -0
- manimvox/voice/engines/elevenlabs.py +134 -0
- manimvox/voice/engines/f5.py +117 -0
- manimvox/voice/engines/fake.py +39 -0
- manimvox/voice/engines/kokoro.py +92 -0
- manimvox/voice/engines/openai.py +94 -0
- manimvox/voice/engines/piper.py +128 -0
- manimvox/voice/engines/say.py +78 -0
- manimvox/voice/engines/xtts.py +112 -0
- manimvox/voice/http.py +99 -0
- manimvox/voice/pron.py +55 -0
- manimvox/voice/registry.py +26 -0
- manimvox-0.1.0.dist-info/METADATA +570 -0
- manimvox-0.1.0.dist-info/RECORD +141 -0
- manimvox-0.1.0.dist-info/WHEEL +4 -0
- manimvox-0.1.0.dist-info/entry_points.txt +2 -0
- manimvox-0.1.0.dist-info/licenses/LICENSE +21 -0
manimvox/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bar-ranking",
|
|
3
|
+
"function": "bar_ranking",
|
|
4
|
+
"helpers": ["grow", "value_x"],
|
|
5
|
+
"description": "Horizontal bars ranked by value with labels and values; highlight the leaders, mark a threshold.",
|
|
6
|
+
"tags": ["chart", "ranking", "bars"],
|
|
7
|
+
"parameters": [
|
|
8
|
+
{"name": "rows", "description": "list of (label, value), top to bottom"},
|
|
9
|
+
{"name": "max_value", "description": "the value of a full-width bar; default the largest value"},
|
|
10
|
+
{"name": "width", "description": "full bar width in scene units"},
|
|
11
|
+
{"name": "row_h", "description": "row height in scene units"},
|
|
12
|
+
{"name": "colors", "description": "row index → colour; other rows are muted; default {0: ACCENT}"},
|
|
13
|
+
{"name": "size", "description": "font size"},
|
|
14
|
+
{"name": "fmt", "description": "format of the value text, e.g. \"{:.1f}\" or \"{:,.0f}\""},
|
|
15
|
+
{"name": "label_w", "description": "widest a label may be before it shrinks"}
|
|
16
|
+
],
|
|
17
|
+
"returns": "VGroup with .rows (each VGroup(label, bar, value)); grow(chart) reveals them; value_x(chart, v) gives a value's x"
|
|
18
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Horizontal bars ranked by value, one row per item, each with its value at the bar's end."""
|
|
2
|
+
from manimvox.kit import *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def bar_ranking(rows, max_value=None, width=7.4, row_h=0.36, colors=None, size=16, fmt="{:.1f}", label_w=4.2):
|
|
6
|
+
"""Bars for `rows`, a list of (label, value), drawn top to bottom in the order given; bar length is value /
|
|
7
|
+
`max_value` (default: the largest value) of `width`. `colors` maps a row index to a colour; other rows are
|
|
8
|
+
MUTED with dimmed text (default: the first row in ACCENT). Returns a VGroup with .rows (each
|
|
9
|
+
VGroup(label, bar, value)) and .axis (hidden points at value 0 and `max_value`, used by `value_x`).
|
|
10
|
+
Raises ValueError for empty `rows`, a negative value, or a `max_value` that is not above 0."""
|
|
11
|
+
if not rows:
|
|
12
|
+
raise ValueError("rows must not be empty")
|
|
13
|
+
if any(v < 0 for _, v in rows):
|
|
14
|
+
raise ValueError("rows must not hold a negative value")
|
|
15
|
+
top = max(v for _, v in rows) if max_value is None else max_value
|
|
16
|
+
if not top > 0:
|
|
17
|
+
raise ValueError("max_value (or the largest value) must be above 0")
|
|
18
|
+
colors = {0: ACCENT} if colors is None else colors
|
|
19
|
+
out = VGroup()
|
|
20
|
+
for i, (name, v) in enumerate(rows):
|
|
21
|
+
y = -i * row_h
|
|
22
|
+
c = colors.get(i)
|
|
23
|
+
lab = T(name, size, INK if c else MUTED, BOLD if c else NORMAL, max_w=label_w)
|
|
24
|
+
lab.move_to([-0.2 - lab.width / 2, y, 0])
|
|
25
|
+
bar = Rectangle(width=max(0.03, width * v / top), height=row_h * 0.66)
|
|
26
|
+
bar.set_fill(c or MUTED, 1 if c else 0.55).set_stroke(width=0).move_to([bar.width / 2, y, 0])
|
|
27
|
+
val = T(fmt.format(v), size, INK, BOLD if c else NORMAL).next_to(bar, RIGHT, buff=0.1)
|
|
28
|
+
out.add(VGroup(lab, bar, val))
|
|
29
|
+
axis = VGroup(VectorizedPoint([0, 0, 0]), VectorizedPoint([width, 0, 0]))
|
|
30
|
+
g = VGroup(out, axis)
|
|
31
|
+
g.rows, g.axis, g.top = out, axis, top
|
|
32
|
+
return g
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def grow(chart, lag_ratio=0.08):
|
|
36
|
+
"""The animation that brings the rows in one after another, each bar growing from the left."""
|
|
37
|
+
return LaggedStart(*[AnimationGroup(FadeIn(r[0]), GrowFromEdge(r[1], LEFT), FadeIn(r[2])) for r in chart.rows],
|
|
38
|
+
lag_ratio=lag_ratio)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def value_x(chart, v):
|
|
42
|
+
"""The x coordinate of value `v` on the chart as it now stands (for a reference line)."""
|
|
43
|
+
a, b = chart.axis[0].get_center()[0], chart.axis[1].get_center()[0]
|
|
44
|
+
return a + (b - a) * v / chart.top
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from manimvox.kit import *
|
|
2
|
+
from blocks.bar_ranking import bar_ranking, grow, value_x
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Demo(Episode):
|
|
6
|
+
def build(self):
|
|
7
|
+
h = heading("Best score for each model", sub="Share of the hidden bugs found, %")
|
|
8
|
+
data = [("Model A · max", 85.5), ("Model B · max", 67.7), ("Model C · ultra", 51.6),
|
|
9
|
+
("Model D · xhigh", 43.5), ("Model E · ultra", 27.4), ("Model F · high", 21.0),
|
|
10
|
+
("Model G · high", 12.9), ("Model H · low", 3.2)]
|
|
11
|
+
chart = bar_ranking(data, max_value=100, colors={0: ACCENT, 1: TEAL, 2: BLUE}, row_h=0.5, size=18, fmt="{:.0f}")
|
|
12
|
+
chart.move_to(DOWN * 0.45)
|
|
13
|
+
x = value_x(chart, 50)
|
|
14
|
+
fifty = DashedLine([x, chart.get_top()[1] + 0.15, 0], [x, chart.get_bottom()[1] - 0.1, 0],
|
|
15
|
+
dash_length=0.1).set_stroke(WARN, 2)
|
|
16
|
+
self.say("Here is the best score for each model.", FadeIn(h, shift=DOWN * 0.2), grow(chart), run_time=2.4)
|
|
17
|
+
self.say("Only three passed fifty percent.", Create(fifty))
|
|
18
|
+
self.wait(1)
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bug-grid",
|
|
3
|
+
"function": "bug_grid",
|
|
4
|
+
"helpers": ["light"],
|
|
5
|
+
"description": "One square per item (bugs, tests, files) in a grid; light a slice of it as they are counted.",
|
|
6
|
+
"tags": ["count", "grid", "proportion"],
|
|
7
|
+
"parameters": [
|
|
8
|
+
{"name": "n", "description": "how many squares"},
|
|
9
|
+
{"name": "cols", "description": "squares per row"},
|
|
10
|
+
{"name": "size", "description": "square width in scene units"},
|
|
11
|
+
{"name": "gap", "description": "space between squares"},
|
|
12
|
+
{"name": "fill", "description": "fill colour before lighting; default PANEL"},
|
|
13
|
+
{"name": "stroke", "description": "outline colour before lighting; default LINE"}
|
|
14
|
+
],
|
|
15
|
+
"returns": "VGroup of squares in reading order; light(grid[:k], colour) fills the first k"
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""One square per item (bugs, tests, files, requests) in a grid, lit up in turn as they are counted."""
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
from manimvox.kit import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def bug_grid(n, cols=16, size=0.36, gap=0.1, fill=PANEL, stroke=LINE):
|
|
8
|
+
"""`n` rounded squares in rows of `cols`, `size` scene units wide with `gap` between them.
|
|
9
|
+
Returns a VGroup of the squares in reading order; slice it to light some (`light(grid[:53], ACCENT)`)."""
|
|
10
|
+
squares = VGroup(*[RoundedRectangle(corner_radius=0.05, width=size, height=size).set_fill(fill, 1)
|
|
11
|
+
.set_stroke(stroke, 1.5) for _ in range(n)])
|
|
12
|
+
squares.arrange_in_grid(rows=math.ceil(n / cols), cols=cols, buff=gap)
|
|
13
|
+
return squares
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def light(squares, color=ACCENT, lag_ratio=0.03):
|
|
17
|
+
"""The animation that fills `squares` (a slice of the grid) one after another in `color`."""
|
|
18
|
+
return LaggedStart(*[s.animate.set_fill(color, 1).set_stroke(color, 1.5) for s in squares], lag_ratio=lag_ratio)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from manimvox.kit import *
|
|
2
|
+
from blocks.bug_grid import bug_grid, light
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Demo(Episode):
|
|
6
|
+
def build(self):
|
|
7
|
+
h = heading("Recall", sub="Of 62 hidden bugs, how many were found?")
|
|
8
|
+
g = bug_grid(62).move_to(UP * 0.2)
|
|
9
|
+
result = T("53 of 62 = 85.5%", 30, ACCENT, BOLD).move_to(DOWN * 2.4)
|
|
10
|
+
self.say("Here are sixty-two hidden bugs, one square each.",
|
|
11
|
+
FadeIn(h, shift=DOWN * 0.2), FadeIn(g, lag_ratio=0.02), run_time=1.6)
|
|
12
|
+
self.say("The model found fifty-three of them.", light(g[:53]), FadeIn(result, shift=UP * 0.2),
|
|
13
|
+
run_time=2.4)
|
|
14
|
+
self.wait(1)
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "code-diff",
|
|
3
|
+
"function": "code_diff",
|
|
4
|
+
"helpers": [],
|
|
5
|
+
"description": "Code before and after a change, side by side, with removed and added lines banded in colour.",
|
|
6
|
+
"tags": ["code", "diff", "change"],
|
|
7
|
+
"parameters": [
|
|
8
|
+
{"name": "before", "description": "source text before the change"},
|
|
9
|
+
{"name": "after", "description": "source text after the change"},
|
|
10
|
+
{"name": "title_before", "description": "label of the left panel"},
|
|
11
|
+
{"name": "title_after", "description": "label of the right panel"},
|
|
12
|
+
{"name": "size", "description": "font size of the code"},
|
|
13
|
+
{"name": "w", "description": "width of each panel in scene units"}
|
|
14
|
+
],
|
|
15
|
+
"returns": "VGroup with .left and .right panels (.bg, .title, .rows) and .removed and .added bands"
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Before and after, side by side: removed lines banded on the left, added lines banded on the right."""
|
|
2
|
+
import difflib
|
|
3
|
+
|
|
4
|
+
from manimvox.kit import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _panel(lines, title, size, w):
|
|
8
|
+
char_w = T("M" * 10, size, INK, font=MONO).width / 10
|
|
9
|
+
row_h = T("Ag", size, INK, font=MONO).height * 1.6
|
|
10
|
+
rows = VGroup()
|
|
11
|
+
for k, s in enumerate(lines or [""]):
|
|
12
|
+
t = T(s.strip(), size, INK, font=MONO) if s.strip() else VectorizedPoint()
|
|
13
|
+
t.move_to([(len(s) - len(s.lstrip())) * char_w + t.width / 2, -k * row_h, 0])
|
|
14
|
+
rows.add(t)
|
|
15
|
+
scale = min(1.0, (w - 0.7) / max(rows.width, 0.01))
|
|
16
|
+
rows.scale(scale, about_point=rows.get_corner(UL))
|
|
17
|
+
ttl = T(title, 15, MUTED, font=MONO)
|
|
18
|
+
bg = box(w, rows.height + ttl.height + 1.0, fill=CODE_BG, stroke=LINE).set_z_index(-2)
|
|
19
|
+
ttl.move_to(bg.get_corner(UL) + RIGHT * (0.35 + ttl.width / 2) + DOWN * (0.3 + ttl.height / 2))
|
|
20
|
+
rows.shift(ttl.get_corner(DL) + DOWN * 0.35 - rows.get_corner(UL))
|
|
21
|
+
p = VGroup(bg, ttl, rows)
|
|
22
|
+
p.bg, p.title, p.rows, p.row_h = bg, ttl, rows, row_h * scale
|
|
23
|
+
return p
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _band(panel, k, color):
|
|
27
|
+
band = Rectangle(width=panel.bg.width - 0.2, height=panel.row_h * 0.95).set_fill(color, 0.22).set_stroke(width=0)
|
|
28
|
+
return band.move_to([panel.bg.get_center()[0], panel.rows[k].get_center()[1], 0]).set_z_index(-1)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def code_diff(before, after, title_before="before", title_after="after", size=16, w=6.2):
|
|
32
|
+
"""`before` and `after` are source text, compared line by line with difflib: removed lines get an ERROR band
|
|
33
|
+
in the left panel, added lines an OK band in the right one; indentation is kept. Returns a VGroup with .left
|
|
34
|
+
and .right (each with .bg, .title, .rows) and .removed and .added (the bands, to FadeIn after the panels).
|
|
35
|
+
Limits: `before` and `after` must not both be empty (ValueError)."""
|
|
36
|
+
a, b = before.strip("\n").splitlines(), after.strip("\n").splitlines()
|
|
37
|
+
if not a and not b:
|
|
38
|
+
raise ValueError("before and after must not both be empty")
|
|
39
|
+
gone, new = set(), set()
|
|
40
|
+
for tag, i1, i2, j1, j2 in difflib.SequenceMatcher(a=a, b=b, autojunk=False).get_opcodes():
|
|
41
|
+
if tag in ("replace", "delete"):
|
|
42
|
+
gone.update(range(i1, i2))
|
|
43
|
+
if tag in ("replace", "insert"):
|
|
44
|
+
new.update(range(j1, j2))
|
|
45
|
+
left, right = _panel(a, title_before, size, w), _panel(b, title_after, size, w)
|
|
46
|
+
VGroup(left, right).arrange(RIGHT, buff=0.4, aligned_edge=UP)
|
|
47
|
+
removed = VGroup(*[_band(left, i, ERROR) for i in sorted(gone)])
|
|
48
|
+
added = VGroup(*[_band(right, j, OK) for j in sorted(new)])
|
|
49
|
+
g = VGroup(left, right, removed, added)
|
|
50
|
+
g.left, g.right, g.removed, g.added = left, right, removed, added
|
|
51
|
+
return g
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from manimvox.kit import *
|
|
2
|
+
from blocks.code_diff import code_diff
|
|
3
|
+
|
|
4
|
+
BEFORE = """
|
|
5
|
+
def total(items):
|
|
6
|
+
sum = 0
|
|
7
|
+
for i in items:
|
|
8
|
+
sum += i.price
|
|
9
|
+
return sum
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
AFTER = """
|
|
13
|
+
def total(items):
|
|
14
|
+
return sum(i.price * i.qty for i in items)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Demo(Episode):
|
|
19
|
+
def build(self):
|
|
20
|
+
h = heading("One loop becomes one line")
|
|
21
|
+
d = code_diff(BEFORE, AFTER).move_to(DOWN * 0.4)
|
|
22
|
+
self.say("Here is the function before and after the change.",
|
|
23
|
+
FadeIn(h, shift=DOWN * 0.2), FadeIn(d.left), FadeIn(d.right))
|
|
24
|
+
self.steps("Four lines of loop go, and one line that also counts quantity takes their place.",
|
|
25
|
+
[FadeIn(d.removed), FadeIn(d.added)])
|
|
26
|
+
self.wait(1)
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "line-by-level",
|
|
3
|
+
"function": "line_by_level",
|
|
4
|
+
"helpers": ["point"],
|
|
5
|
+
"description": "A line chart over named steps (effort levels, versions, weeks), one labelled line per series.",
|
|
6
|
+
"tags": ["chart", "line", "trend"],
|
|
7
|
+
"parameters": [
|
|
8
|
+
{"name": "levels", "description": "names of the x steps, left to right"},
|
|
9
|
+
{"name": "series", "description": "list of (name, values, colour), one value per level"},
|
|
10
|
+
{"name": "y_max", "description": "top of the y axis"},
|
|
11
|
+
{"name": "y_ticks", "description": "values that get a gridline; default quarters of y_max"},
|
|
12
|
+
{"name": "width", "description": "plot width in scene units"},
|
|
13
|
+
{"name": "height", "description": "plot height in scene units"},
|
|
14
|
+
{"name": "size", "description": "font size"}
|
|
15
|
+
],
|
|
16
|
+
"returns": "VGroup with .grid, .xlabels, .lines (VGroup(line, dots, labels) per series), .legend; point(chart, i, v) gives a position"
|
|
17
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""A line chart over named steps (effort levels, versions, weeks): one line per series, each point labelled."""
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from manimvox.kit import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def line_by_level(levels, series, y_max, y_ticks=None, width=7.0, height=4.2, size=16):
|
|
8
|
+
"""`levels` names the x steps; `series` is a list of (name, values, colour) with one value per level;
|
|
9
|
+
the y axis runs from 0 to `y_max` with gridlines at `y_ticks` (default: quarters). Returns a VGroup with
|
|
10
|
+
.grid (gridlines and their numbers), .xlabels, .lines (one VGroup(line, dots, value labels) per series),
|
|
11
|
+
.legend (one entry per series) and .frame (hidden corner points used by `point`).
|
|
12
|
+
Raises ValueError for empty `levels`, a series with a value count other than len(levels), or `y_max` not above 0."""
|
|
13
|
+
if not levels:
|
|
14
|
+
raise ValueError("levels must not be empty")
|
|
15
|
+
if not y_max > 0:
|
|
16
|
+
raise ValueError("y_max must be above 0")
|
|
17
|
+
for name, vals, _col in series:
|
|
18
|
+
if len(vals) != len(levels):
|
|
19
|
+
raise ValueError(f"series {name!r} must have one value per level ({len(levels)})")
|
|
20
|
+
ticks = y_ticks or [y_max * k / 4 for k in range(5)]
|
|
21
|
+
n = len(levels)
|
|
22
|
+
|
|
23
|
+
def at(i, v):
|
|
24
|
+
return np.array([width * i / max(1, n - 1), height * v / y_max, 0.0])
|
|
25
|
+
|
|
26
|
+
grid = VGroup()
|
|
27
|
+
for v in ticks:
|
|
28
|
+
grid.add(Line(at(0, v) + LEFT * 0.3, at(n - 1, v) + RIGHT * 0.3).set_stroke(LINE, 1.5))
|
|
29
|
+
grid.add(T(f"{v:g}", size - 1, MUTED).next_to(at(0, v) + LEFT * 0.3, LEFT, buff=0.12))
|
|
30
|
+
xlabels = VGroup(*[T(name, size + 1, MUTED).move_to(at(i, 0) + DOWN * 0.32) for i, name in enumerate(levels)])
|
|
31
|
+
lines = VGroup()
|
|
32
|
+
for _name, vals, col in series:
|
|
33
|
+
line = VMobject().set_points_as_corners([at(i, v) for i, v in enumerate(vals)]).set_stroke(col, 4)
|
|
34
|
+
dots = VGroup(*[Dot(at(i, v), radius=0.08, color=col) for i, v in enumerate(vals)])
|
|
35
|
+
labels = VGroup(*[T(str(v), size, col, BOLD).next_to(d, UP, buff=0.1) for v, d in zip(vals, dots)])
|
|
36
|
+
lines.add(VGroup(line, dots, labels))
|
|
37
|
+
legend = VGroup(*[VGroup(Line(LEFT * 0.25, RIGHT * 0.25).set_stroke(col, 4), T(name, size + 2, col, BOLD))
|
|
38
|
+
.arrange(RIGHT, buff=0.15) for name, _vals, col in series])
|
|
39
|
+
legend.arrange(DOWN, aligned_edge=LEFT, buff=0.2)
|
|
40
|
+
legend.next_to(at(n - 1, y_max) + RIGHT * 0.3, RIGHT, buff=0.5).align_to(at(0, y_max), UP)
|
|
41
|
+
frame = VGroup(VectorizedPoint(at(0, 0)), VectorizedPoint(at(n - 1, y_max)))
|
|
42
|
+
g = VGroup(grid, xlabels, lines, legend, frame)
|
|
43
|
+
g.grid, g.xlabels, g.lines, g.legend, g.frame = grid, xlabels, lines, legend, frame
|
|
44
|
+
g.n, g.y_max = n, y_max
|
|
45
|
+
return g
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def point(chart, i, v):
|
|
49
|
+
"""Where level `i`, value `v` sits on the chart as it now stands (for a callout)."""
|
|
50
|
+
a, b = chart.frame[0].get_center(), chart.frame[1].get_center()
|
|
51
|
+
return a + (b - a) * np.array([i / max(1, chart.n - 1), v / chart.y_max, 0.0])
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from manimvox.kit import *
|
|
2
|
+
from blocks.line_by_level import line_by_level
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Demo(Episode):
|
|
6
|
+
def build(self):
|
|
7
|
+
h = heading("Did more effort help?", sub="Bugs found (of 62) at each effort level")
|
|
8
|
+
chart = line_by_level(["low", "medium", "high", "xhigh", "max"],
|
|
9
|
+
[("Model A", [25, 30, 32, 43, 53], ACCENT), ("Model B", [1, 17, 41, 28, 42], TEAL)],
|
|
10
|
+
y_max=62, y_ticks=[0, 20, 40, 60]).move_to(DOWN * 0.55)
|
|
11
|
+
a, b = chart.lines
|
|
12
|
+
self.steps("Model A climbed steadily, from twenty-five at low effort to fifty-three at max.",
|
|
13
|
+
[[FadeIn(h, shift=DOWN * 0.2), FadeIn(chart.grid), FadeIn(chart.xlabels)],
|
|
14
|
+
FadeIn(chart.legend[0]), [Create(a[0]), FadeIn(a[1]), FadeIn(a[2])]])
|
|
15
|
+
self.steps("Model B jumped around: forty-one at high, then twenty-eight.",
|
|
16
|
+
[[FadeIn(chart.legend[1]), Create(b[0]), FadeIn(b[1]), FadeIn(b[2])]])
|
|
17
|
+
self.wait(1)
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "log-scatter",
|
|
3
|
+
"function": "log_scatter",
|
|
4
|
+
"helpers": ["place"],
|
|
5
|
+
"description": "A labelled scatter chart on a log-scale x axis (cost, size, time) against a linear y axis.",
|
|
6
|
+
"tags": ["chart", "scatter", "log-scale"],
|
|
7
|
+
"parameters": [
|
|
8
|
+
{"name": "points", "description": "list of (label, x, y, colour), x above 0"},
|
|
9
|
+
{"name": "x_range", "description": "(low, high) of the log x axis"},
|
|
10
|
+
{"name": "y_range", "description": "(low, high) of the y axis"},
|
|
11
|
+
{"name": "x_ticks", "description": "list of (value, text) under the x axis"},
|
|
12
|
+
{"name": "y_ticks", "description": "list of (value, text) left of the y axis"},
|
|
13
|
+
{"name": "width", "description": "plot width in scene units"},
|
|
14
|
+
{"name": "height", "description": "plot height in scene units"},
|
|
15
|
+
{"name": "size", "description": "font size"}
|
|
16
|
+
],
|
|
17
|
+
"returns": "VGroup with .axes and .marks (VGroup(dot, label) per point); place(chart, x, y) gives a position"
|
|
18
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""A scatter chart with a log-scale x axis (cost, size, time) and a linear y axis, every point labelled."""
|
|
2
|
+
import math
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from manimvox.kit import *
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def log_scatter(points, x_range, y_range=(0, 100), x_ticks=(), y_ticks=(), width=8.0, height=4.3, size=16):
|
|
10
|
+
"""`points` is a list of (label, x, y, colour) with x > 0. `x_range` (low, high) sets the log axis and
|
|
11
|
+
`y_range` the linear one; `x_ticks` and `y_ticks` are lists of (value, text). Each label sits up and to the
|
|
12
|
+
left of its point, or to the right in the left third of the plot. Returns a VGroup with .axes (axis lines and
|
|
13
|
+
tick text), .marks (one VGroup(dot, label) per point, in order) and .frame (hidden corners used by `place`).
|
|
14
|
+
Raises ValueError unless 0 < x_range[0] < x_range[1] and every point has x > 0."""
|
|
15
|
+
if not 0 < x_range[0] < x_range[1]:
|
|
16
|
+
raise ValueError("x_range must be (low, high) with 0 < low < high")
|
|
17
|
+
if any(x <= 0 for _, x, _, _ in points):
|
|
18
|
+
raise ValueError("every point needs x above 0")
|
|
19
|
+
lo, hi = math.log10(x_range[0]), math.log10(x_range[1])
|
|
20
|
+
y0, y1 = y_range
|
|
21
|
+
|
|
22
|
+
def at(x, y):
|
|
23
|
+
return np.array([width * (math.log10(x) - lo) / (hi - lo), height * (y - y0) / (y1 - y0), 0.0])
|
|
24
|
+
|
|
25
|
+
axes = VGroup(Line(at(x_range[0], y0), at(x_range[1], y0)).set_stroke(LINE, 2),
|
|
26
|
+
Line(at(x_range[0], y0), at(x_range[0], y1)).set_stroke(LINE, 2))
|
|
27
|
+
for v, text in x_ticks:
|
|
28
|
+
axes.add(T(text, size - 1, MUTED).move_to(at(v, y0) + DOWN * 0.3))
|
|
29
|
+
for v, text in y_ticks:
|
|
30
|
+
axes.add(T(text, size - 1, MUTED).next_to(at(x_range[0], v), LEFT, buff=0.12))
|
|
31
|
+
marks = VGroup()
|
|
32
|
+
for label, x, y, col in points:
|
|
33
|
+
d = Dot(at(x, y), radius=0.11, color=col)
|
|
34
|
+
lab = T(label, size, INK if col == MUTED else col, BOLD)
|
|
35
|
+
lab.next_to(d, UR if at(x, y)[0] < width / 3 else UL, buff=0.1)
|
|
36
|
+
marks.add(VGroup(d, lab))
|
|
37
|
+
frame = VGroup(VectorizedPoint(at(x_range[0], y0)), VectorizedPoint(at(x_range[1], y1)))
|
|
38
|
+
g = VGroup(axes, marks, frame)
|
|
39
|
+
g.axes, g.marks, g.frame = axes, marks, frame
|
|
40
|
+
g.x_log, g.y_range = (lo, hi), (y0, y1)
|
|
41
|
+
return g
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def place(chart, x, y):
|
|
45
|
+
"""Where (x, y) sits on the chart as it now stands."""
|
|
46
|
+
a, b = chart.frame[0].get_center(), chart.frame[1].get_center()
|
|
47
|
+
lo, hi = chart.x_log
|
|
48
|
+
y0, y1 = chart.y_range
|
|
49
|
+
return a + (b - a) * np.array([(math.log10(x) - lo) / (hi - lo), (y - y0) / (y1 - y0), 0.0])
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from manimvox.kit import *
|
|
2
|
+
from blocks.log_scatter import log_scatter
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Demo(Episode):
|
|
6
|
+
def build(self):
|
|
7
|
+
h = heading("What does a run cost?", sub="Score against the cost of one run, log scale")
|
|
8
|
+
chart = log_scatter(
|
|
9
|
+
[("Model A · max $24", 24.45, 85.5, ACCENT), ("Model B · high $9.80", 9.79, 66.1, TEAL),
|
|
10
|
+
("Model C · max $1.54", 1.54, 25.8, MUTED), ("Model D · high $0.05", 0.054, 11.3, MUTED)],
|
|
11
|
+
x_range=(0.03, 30), x_ticks=[(0.03, "$0.03"), (0.3, "$0.30"), (3, "$3"), (30, "$30")],
|
|
12
|
+
y_ticks=[(0, "0"), (50, "50"), (100, "100")]).move_to(DOWN * 0.5)
|
|
13
|
+
m = chart.marks
|
|
14
|
+
self.steps("The strongest model cost about twenty-four dollars a run. The runner-up cost under ten.",
|
|
15
|
+
[[FadeIn(h, shift=DOWN * 0.2), FadeIn(chart.axes)], FadeIn(m[0], scale=0.8),
|
|
16
|
+
FadeIn(m[1], scale=0.8)])
|
|
17
|
+
self.steps("The cheapest cost pennies, and found far less.", [FadeIn(m[2], scale=0.8), FadeIn(m[3], scale=0.8)])
|
|
18
|
+
self.wait(1)
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mesh-model",
|
|
3
|
+
"function": "mesh_model",
|
|
4
|
+
"helpers": ["mesh_part"],
|
|
5
|
+
"description": "A 3D model from a glTF, OBJ or STL file (Blender exports glTF) as shaded faces the 3D camera orbits. Use in an Episode3D.",
|
|
6
|
+
"tags": ["3d", "model", "mesh", "gltf", "blender"],
|
|
7
|
+
"parameters": [
|
|
8
|
+
{"name": "source", "description": "a .glb, .gltf, .obj, .stl or .ply file, or (vertices, faces) arrays"},
|
|
9
|
+
{"name": "size", "description": "the model's largest side in scene units"},
|
|
10
|
+
{"name": "color", "description": "theme colour for faces the model gives no colour"},
|
|
11
|
+
{"name": "max_faces", "description": "simplify to at most this many triangles, 4 to 5000; fewer renders faster"},
|
|
12
|
+
{"name": "up", "description": "the source's up axis: \"y\" for glTF and OBJ, \"z\" for STL and CAD"},
|
|
13
|
+
{"name": "wire", "description": "draw face edges in the background colour, for a low-poly look"}
|
|
14
|
+
],
|
|
15
|
+
"returns": "VGroup of faces with .mesh, .parts and .centres; mesh_part(model, name, inside) picks the faces of one part"
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""A 3D model from a glTF, OBJ or STL file (or arrays) as shaded faces the 3D camera can orbit. For an Episode3D."""
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from manimvox.kit import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def mesh_model(source, size=4.0, color=ACCENT, max_faces=1500, up="y", wire=False):
|
|
8
|
+
"""The model in `source` (a .glb, .gltf, .obj, .stl or .ply file, or (vertices, faces) arrays) as one
|
|
9
|
+
flat-shaded triangle per face, centred on the origin and scaled so its largest side is `size` scene
|
|
10
|
+
units. Faces take the model's own colours; faces without one, and models without any, are `color`.
|
|
11
|
+
`up` is the source's up axis: "y" for glTF and OBJ (Blender's glTF export), "z" for STL and CAD.
|
|
12
|
+
Models over `max_faces` triangles (at most 5000) are simplified first: each face costs render time.
|
|
13
|
+
`wire` draws every face's edges in the background colour, for a low-poly look.
|
|
14
|
+
Draw it in an Episode3D: the camera sorts the faces by depth as it moves. Reveal it with FadeIn (Create
|
|
15
|
+
draws every edge, slowly). Returns a VGroup of the faces with .mesh, .parts (the names of its parts)
|
|
16
|
+
and .centres (each face's centre in scene units from the model's middle, before you move it).
|
|
17
|
+
Files need the trimesh extra. Raises ValueError for a file or arrays it cannot draw."""
|
|
18
|
+
mesh = load_mesh(source, max_faces=max_faces, up=up)
|
|
19
|
+
lo, hi = mesh.vertices.min(axis=0), mesh.vertices.max(axis=0)
|
|
20
|
+
span = float((hi - lo).max())
|
|
21
|
+
if span <= 0:
|
|
22
|
+
raise ValueError("the model has no size: every vertex is at one point")
|
|
23
|
+
pts = (mesh.vertices - (lo + hi) / 2) * (size / span)
|
|
24
|
+
faces = VGroup()
|
|
25
|
+
for i, tri in enumerate(mesh.faces):
|
|
26
|
+
c = (mesh.colors and mesh.colors[i]) or color
|
|
27
|
+
# a stroke of the face's own colour closes the hairline gaps antialiasing leaves between faces
|
|
28
|
+
stroke = (BG, 0.6) if wire else (c, 0.8)
|
|
29
|
+
faces.add(Polygon(*pts[tri], fill_color=c, fill_opacity=1, stroke_color=stroke[0],
|
|
30
|
+
stroke_width=stroke[1], shade_in_3d=True))
|
|
31
|
+
faces.mesh, faces.parts = mesh, tuple(sorted(set(mesh.parts)))
|
|
32
|
+
faces.centres = pts[mesh.faces].mean(axis=1)
|
|
33
|
+
return faces
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def mesh_part(model, name=None, inside=None):
|
|
37
|
+
"""The faces of `model` in a part whose name contains `name` (any case; see model.parts), and/or whose
|
|
38
|
+
centre (x, y, z), in scene units from the model's middle before it moved, makes `inside(x, y, z)` true.
|
|
39
|
+
Returns a VGroup of those faces, which stay on the model: recolour them, or place a label by them.
|
|
40
|
+
Raises ValueError when no face matches."""
|
|
41
|
+
keep = np.ones(len(model.submobjects), bool)
|
|
42
|
+
if name is not None:
|
|
43
|
+
keep &= np.array([name.lower() in p.lower() for p in model.mesh.parts])
|
|
44
|
+
if inside is not None:
|
|
45
|
+
keep &= np.array([bool(inside(*c)) for c in model.centres])
|
|
46
|
+
if not keep.any():
|
|
47
|
+
raise ValueError(f"no face matches name={name!r} and inside; the parts are {', '.join(model.parts)}")
|
|
48
|
+
return VGroup(*[f for f, k in zip(model.submobjects, keep) if k])
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from manimvox.kit import *
|
|
2
|
+
from blocks.mesh_model import mesh_model, mesh_part
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def torus(n=20, m=8, big=1.0, small=0.4):
|
|
6
|
+
"""A low-poly ring as (vertices, faces), z up: a model file goes in the same place."""
|
|
7
|
+
u, v = np.meshgrid(np.linspace(0, TAU, n, endpoint=False), np.linspace(0, TAU, m, endpoint=False))
|
|
8
|
+
r = big + small * np.cos(v)
|
|
9
|
+
verts = np.stack([r * np.cos(u), r * np.sin(u), small * np.sin(v)], axis=-1).reshape(-1, 3)
|
|
10
|
+
faces = []
|
|
11
|
+
for j in range(m):
|
|
12
|
+
for i in range(n):
|
|
13
|
+
a, b = j * n + i, j * n + (i + 1) % n
|
|
14
|
+
c, d = ((j + 1) % m) * n + i, ((j + 1) % m) * n + (i + 1) % n
|
|
15
|
+
faces += [(a, b, d), (a, d, c)]
|
|
16
|
+
return verts, np.array(faces)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Demo(Episode3D):
|
|
20
|
+
def build(self):
|
|
21
|
+
h = heading("A ring has one hole", sub="Any model from a file works the same way")
|
|
22
|
+
self.pin(h)
|
|
23
|
+
ring = mesh_model(torus(), size=4.6, color=TEAL, up="z", wire=True).move_to(DOWN * 0.6)
|
|
24
|
+
top = mesh_part(ring, inside=lambda x, y, z: z > 0.05 and y < 0)
|
|
25
|
+
label = T("the near half of the top", 22, WARN, BOLD).move_to([4.4, -2.6, 0])
|
|
26
|
+
self.pin(label)
|
|
27
|
+
self.say("Seen from above, a ring is a flat loop.", FadeIn(h, shift=DOWN * 0.2), FadeIn(ring))
|
|
28
|
+
with self.narrate("Tilt it, and it has depth all the way round."):
|
|
29
|
+
self.move_camera(phi=62 * DEGREES, theta=-50 * DEGREES, run_time=2)
|
|
30
|
+
self.say("Any part of it can be picked out.", top.animate.set_fill(WARN), FadeIn(label))
|
|
31
|
+
self.begin_ambient_camera_rotation(rate=0.15)
|
|
32
|
+
self.wait(1.5)
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "request-flow",
|
|
3
|
+
"function": "request_flow",
|
|
4
|
+
"helpers": ["hop"],
|
|
5
|
+
"description": "A value travelling through a chain of stages, boxes joined by arrows, with a token that hops along.",
|
|
6
|
+
"tags": ["flow", "pipeline", "request"],
|
|
7
|
+
"parameters": [
|
|
8
|
+
{"name": "stages", "description": "box labels, left to right"},
|
|
9
|
+
{"name": "w", "description": "box width in scene units"},
|
|
10
|
+
{"name": "color", "description": "box outline colour"},
|
|
11
|
+
{"name": "gap", "description": "space between boxes"},
|
|
12
|
+
{"name": "size", "description": "font size"},
|
|
13
|
+
{"name": "token_color", "description": "the token's starting colour"}
|
|
14
|
+
],
|
|
15
|
+
"returns": "VGroup with .nodes, .arrows, .token; hop(flow, i, colour) moves the token above stage i"
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""A value passing through a chain of stages: boxes joined by arrows, and a token that hops from box to box."""
|
|
2
|
+
from manimvox.kit import *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def request_flow(stages, w=2.4, color=BLUE, gap=0.9, size=19, token_color=ACCENT):
|
|
6
|
+
"""`stages` are the box labels, left to right. Returns a VGroup with .nodes, .arrows and .token (a dot above
|
|
7
|
+
the first stage). Reveal the stages one by one; move the token with `hop(flow, i)`.
|
|
8
|
+
Limits: `stages` must not be empty (ValueError)."""
|
|
9
|
+
if not stages:
|
|
10
|
+
raise ValueError("stages must not be empty")
|
|
11
|
+
nodes, arrows = flow(stages, w=w, color=color, gap=gap, size=size)
|
|
12
|
+
token = Dot(radius=0.13, color=token_color).move_to(nodes[0].get_top() + UP * 0.3)
|
|
13
|
+
g = VGroup(nodes, arrows, token)
|
|
14
|
+
g.nodes, g.arrows, g.token = nodes, arrows, token
|
|
15
|
+
return g
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def hop(chart, i, color=None):
|
|
19
|
+
"""The animation that moves the token above stage `i`, recolouring it when `color` is given.
|
|
20
|
+
Limits: `i` must be a stage index of the flow (ValueError)."""
|
|
21
|
+
if not 0 <= i < len(chart.nodes):
|
|
22
|
+
raise ValueError(f"stage {i} is not within the flow's {len(chart.nodes)} stages")
|
|
23
|
+
anim = chart.token.animate.move_to(chart.nodes[i].get_top() + UP * 0.3)
|
|
24
|
+
return anim.set_color(color) if color else anim
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from manimvox.kit import *
|
|
2
|
+
from blocks.request_flow import hop, request_flow
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Demo(Episode):
|
|
6
|
+
def build(self):
|
|
7
|
+
h = heading("Safe at every step, dangerous at the end")
|
|
8
|
+
f = request_flow(["Input", "Parser", "Cache", "Browser"]).move_to(UP * 0.2)
|
|
9
|
+
oks = VGroup(*[chip("looks safe", OK, 16).next_to(n, DOWN, buff=0.35) for n in f.nodes[:3]])
|
|
10
|
+
bad = chip("dangerous", ERROR, 16, filled=True).next_to(f.nodes[3], DOWN, buff=0.35)
|
|
11
|
+
self.steps("A value passes through a parser, then a cache, and looks safe each time.",
|
|
12
|
+
[[FadeIn(h, shift=DOWN * 0.2), FadeIn(f.nodes[0]), FadeIn(f.token), FadeIn(oks[0])],
|
|
13
|
+
[FadeIn(f.arrows[0]), FadeIn(f.nodes[1]), hop(f, 1), FadeIn(oks[1])],
|
|
14
|
+
[FadeIn(f.arrows[1]), FadeIn(f.nodes[2]), hop(f, 2), FadeIn(oks[2])]])
|
|
15
|
+
self.say("Then the browser reads it differently, and it becomes dangerous.",
|
|
16
|
+
FadeIn(f.arrows[2]), FadeIn(f.nodes[3]), hop(f, 3, ERROR), FadeIn(bad), run_time=1.4)
|
|
17
|
+
self.wait(1)
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sequence-diagram",
|
|
3
|
+
"function": "sequence_diagram",
|
|
4
|
+
"helpers": [],
|
|
5
|
+
"description": "Actors as lifelines and the messages between them in order, replies dashed: who calls whom.",
|
|
6
|
+
"tags": ["sequence", "protocol", "api"],
|
|
7
|
+
"parameters": [
|
|
8
|
+
{"name": "actors", "description": "column names, left to right"},
|
|
9
|
+
{"name": "messages", "description": "list of (from, to, label) or (from, to, label, \"reply\")"},
|
|
10
|
+
{"name": "top", "description": "y of the actor boxes"},
|
|
11
|
+
{"name": "bottom", "description": "y where the lifelines end"},
|
|
12
|
+
{"name": "width", "description": "distance from the first actor to the last"},
|
|
13
|
+
{"name": "colors", "description": "one colour per actor; default BLUE"},
|
|
14
|
+
{"name": "size", "description": "font size of message labels"}
|
|
15
|
+
],
|
|
16
|
+
"returns": "VGroup with .lifelines and .messages (in order)"
|
|
17
|
+
}
|