我正在尝试从视频教程中编译以下示例:
from manim import *
from colour import Color
class BasicAnimations(Scene):`
def construct(self):
polys = VGroup(
*[RegularPolygon(5, radius=1, fill_opacity=0.5,
color=Color(hue=j/5, saturation=1,
luminance=0.5)) for j in range(5)]
).arrange(RIGHT)
self.play(DrawBorderThenFill(polys), run_time=2)
self.play(
Rotate(polys[0], PI, rate_func=lambda t: t), # rate_func=linear
Rotate(polys[1], PI, rate_func=smooth), # default behavior
Rotate(polys[2], PI, rate_func=lambda t: np.sin(t*PI)),
Rotate(polys[3], PI, rate_func=there_and_back),
Rotate(polys[4], PI, rate_func=lambda t: 1 - abs(1-2*t)),
run_time=2
)
self.wait()
但是,我遇到了如下错误:
C:\tools\Manim\Lib\site-packages\manim\utils\color\core.py:147 in __init__ |
`| 144 elif hasattr(value, "get_hex") and callable(value.get_hex): ` |
|
| 145 result = re_hex.search(value.get_hex()) |
| 146 if result is None: |
| > 147 raise ValueError(f"Failed to parse a color from {val |
| 148 |
| 149 self._internal_value = ManimColor._internal_from_hex_str |
| 150 result.group(), alpha
ValueError: Failed to parse a color from red
大家好,我也遇到了这个问题,我猜这些模块在一些小细节上相互冲突,所以我们需要等待作者修复这些错误。我认为较低的版本可能没有这个错误,但我还没有尝试过这种方法。
因为我们看的是同一个manim教程,所以我也碰巧遇到了同样的问题。已经尝试安装较低版本的颜色模块,但问题仍然没有解决。
所以这个配色方法很适合我。
# Set colors based on j size
polys.set_color_by_gradient(*color_gradient([RED, YELLOW, GREEN, BLUE,], len(polys)))