Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve class naming #28

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/powermanim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from .components import (
AutoHighlightable,
Activable,
AutoActivable,
ChartBars,
DirectionalArrow,
Highlightable,
Invariance,
NumberSlider,
PowerManim,
VGroupHighlight,
VGroupActivable,
)
from .layouts import ArrangedBullets, Bullet, MathBullet, SwitchPalette
from .templates import BulletList, Reference, SectionTitle

__all__ = [
"AutoHighlightable",
"AutoActivable",
"ChartBars",
"DirectionalArrow",
"Highlightable",
"Activable",
"Invariance",
"NumberSlider",
"PowerManim",
"VGroupHighlight",
"VGroupActivable",
"ArrangedBullets",
"SwitchPalette",
"Bullet",
Expand Down
8 changes: 4 additions & 4 deletions src/powermanim/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from .invariance import Invariance
from .logo import PowerManim
from .numberslider import NumberSlider
from .vgrouphighlight import AutoHighlightable, Highlightable, VGroupHighlight
from .vgroupactivable import Activable, AutoActivable, VGroupActivable

__all__ = [
"AutoHighlightable",
"AutoActivable",
"ChartBars",
"DirectionalArrow",
"Highlightable",
"Activable",
"Invariance",
"NumberSlider",
"PowerManim",
"VGroupHighlight",
"VGroupActivable",
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from manim import *


class Highlightable(VGroup):
class Activable(VGroup):
def __init__(
self,
inactive_vmobject: VMobject,
Expand Down Expand Up @@ -67,7 +67,7 @@ def get_deactivation_anim(self) -> Animation:
return Transform(self.obj, target, run_time=self.deactivation_anim_run_time)


class AutoHighlightable(Highlightable):
class AutoActivable(Activable):
def __init__(
self,
vmobject: VMobject,
Expand All @@ -80,7 +80,7 @@ def __init__(
scale_about_edge=LEFT,
group: T.Optional[int] = None,
) -> None:
"""Highlightable component that automatically creates the active and inactive VMobjects.
"""Activable component that automatically creates the active and inactive VMobjects.

Args:
vmobject (VMobject): The object to activate or deactivate VMobject.
Expand Down Expand Up @@ -117,27 +117,27 @@ def __init__(
super().__init__(inactive_vmobject=inactive_obj, active_vmobject=active_obj, start_active=False, group=group)


class VGroupHighlight(VGroup):
class VGroupActivable(VGroup):
def __init__(
self,
*args: VMobject,
anim_lag_ratio: float = 0,
**kwargs: VMobject,
) -> None:
"""Group component that can highlight a subset of its submobjects.
"""Group component that can activate a subset of its submobjects.

Args:
*args: Submobjects to be added to the VGroup.
anim_lag_ratio (float): The lag ratio of the animation.
**kwargs: Keyword arguments to be passed to the VGroup.
"""
args_highlightable = (AutoHighlightable(x) if not isinstance(x, Highlightable) else x for x in args)
super().__init__(*args_highlightable, **kwargs)
args_activable = (AutoActivable(x) if not isinstance(x, Activable) else x for x in args)
super().__init__(*args_activable, **kwargs)

self.anim_lag_ratio = anim_lag_ratio

self.previously_active_idxs = []
self.highlighted = 0
self.actived = 0

# Resolve groups
groups = [item.group for item in self.submobjects]
Expand All @@ -146,7 +146,7 @@ def __init__(
if (None in groups) and len(set(groups)) != 1:
raise ValueError("The groups must be specified for all or no bullets at all.")

self.group2items: Dict[int, T.Set[Highlightable]] = defaultdict(set)
self.group2items: Dict[int, T.Set[Activable]] = defaultdict(set)
for i, obj in enumerate(self.submobjects):
group = obj.group
if group is None:
Expand All @@ -157,27 +157,27 @@ def __init__(
def ngroups(self) -> int:
return len(self.group2items)

def highlight(self, indices: T.Union[int, T.Sequence[int]]) -> AnimationGroup:
"""Highlights the submobjects in the given indices in the scene.
def activate(self, indices: T.Union[int, T.Sequence[int]]) -> AnimationGroup:
"""Activates the submobjects in the given indices in the scene.

Args:
scene:
The scene in which the animation is played.

indices:
The indices to highlight. If a single integer is given, only that index is highlighted.
If a sequence of integers is given, all indices in the sequence are highlighted. The
previously highlighted indices are dehighlighted smoothly.
The indices to activate. If a single integer is given, only that index is activated.
If a sequence of integers is given, all indices in the sequence are activated. The
previously activated indices are deactivated smoothly.
"""
anims = []

if not isinstance(indices, T.Sequence):
indices = [indices]

for to_highlight in indices:
if to_highlight in self.previously_active_idxs:
for to_activate in indices:
if to_activate in self.previously_active_idxs:
continue
anims.append(AnimationGroup(*(x.get_activation_anim() for x in self.group2items[to_highlight])))
anims.append(AnimationGroup(*(x.get_activation_anim() for x in self.group2items[to_activate])))

if self.previously_active_idxs:
for previously_active_idx in self.previously_active_idxs:
Expand All @@ -192,27 +192,27 @@ def highlight(self, indices: T.Union[int, T.Sequence[int]]) -> AnimationGroup:

def also_next(self) -> Animation:
"""Highlights also the next item in the VGroup."""
self.highlighted += 1
self.actived += 1

if self.highlighted > len(self):
raise StopIteration("No more elements to highlight.")
if self.actived > len(self):
raise StopIteration("No more elements to activate.")

return self.highlight(indices=list(range(self.highlighted)))
return self.activate(indices=list(range(self.actived)))

def only_next(self) -> Animation:
"""Highlights only the next item in the VGroup."""
if self.highlighted > len(self):
raise StopIteration("No more elements to highlight.")
anims = self.highlight(indices=self.highlighted)
self.highlighted += 1
if self.actived > len(self):
raise StopIteration("No more elements to activate.")
anims = self.activate(indices=self.actived)
self.actived += 1
return anims

def clear(self) -> Animation:
"""Clears the VGroup hightlighting."""
anims = self.highlight(indices=[])
self.highlighted = 0
anims = self.activate(indices=[])
self.actived = 0
return anims

def all(self) -> Animation:
"""Highlights all the VGroup."""
return self.highlight(indices=list(range(len(self))))
return self.activate(indices=list(range(len(self))))
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from manim import *

from powermanim import VGroupHighlight
from powermanim.components.vgrouphighlight import AutoHighlightable
from powermanim import VGroupActivable
from powermanim.components.vgroupactivable import AutoActivable
from powermanim.showcase.showcasescene import ShowcaseScene


class VGroupHighlightShowcase(ShowcaseScene):
class VGroupActivableShowcase(ShowcaseScene):
def showcasing():
return VGroupHighlight
return VGroupActivable

def construct(self):
dots = [
Expand All @@ -24,9 +24,9 @@ def construct(self):
)
]

group = VGroupHighlight(
group = VGroupActivable(
*map(
lambda x: AutoHighlightable(
lambda x: AutoActivable(
x,
active_fill_opacity=1,
active_stroke_opacity=1,
Expand All @@ -40,13 +40,13 @@ def construct(self):
anim_lag_ratio=0.1
)
self.add(group)
self.play(group.highlight(0))
self.play(group.highlight(1))
self.play(group.highlight([2, 3]))
self.play(group.highlight([1, 3]))
self.play(group.highlight([]))
self.play(group.highlight([2, 4]))
self.play(group.highlight([]))
self.play(group.activate(0))
self.play(group.activate(1))
self.play(group.activate([2, 3]))
self.play(group.activate([1, 3]))
self.play(group.activate([]))
self.play(group.activate([2, 4]))
self.play(group.activate([]))
self.play(group.clear())
for _ in range(len(group)):
self.play(group.only_next(), run_time=0.5)
Expand Down
6 changes: 3 additions & 3 deletions src/powermanim/templates/bulletlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from manim import *

from powermanim import ArrangedBullets, AutoHighlightable, MathBullet, VGroupHighlight
from powermanim import ArrangedBullets, AutoActivable, MathBullet, VGroupActivable


class BulletList(VGroupHighlight):
class BulletList(VGroupActivable):
def __init__(
self,
*rows: T.Union[MathBullet, Tex, Text],
Expand Down Expand Up @@ -41,7 +41,7 @@ def __init__(

super().__init__(
*(
AutoHighlightable(
AutoActivable(
x,
active_fill_opacity=active_opacity,
active_stroke_opacity=active_opacity,
Expand Down
Loading