gpt4 book ai didi

python - 为复杂方程 manim 的部分着色

转载 作者:行者123 更新时间:2023-12-05 03:37:12 28 4
gpt4 key购买 nike

我想用不同颜色绘制 MathTex 元素的变量,但 Manim 似乎对复杂的 Latex 表达式有问题。

这是我的场景。

from manim import *
config.frame_width = 260

class Find_Path(Scene):
def construct(self):
obj = MathTex(r"minimize \quad \sum_{start}^{end}\frac{d_{i,i+1}}{v_{i,i+1}}",
font_size=1000, substrings_to_isolate="d" and "v")
obj.set_color_by_tex("d", YELLOW)
obj.set_color_by_tex("start", GREEN)
obj.set_color_by_tex("end", GREEN)
obj.set_color_by_tex("v", RED)
self.play(Write(obj))
self.wait(3)

这是结果。

enter image description here

具体来说,我想将 d_{i,i+1} 着色为 YELLOW,将 v_{i,i+1} 着色为REDstartendGREEN

有什么建议吗?坦率地说,我不想创建多个不同颜色的 MathTex 对象然后排列它们。

最佳答案

Manim 在幕后进行了大量的 tex 重写,似乎 over 因为重写而优于 frac

我能够应用您想要的颜色(尽管我怀疑您不希望总和符号着色):

from manim import *

class Find_Path(Scene):
def construct(self):
obj1 = MathTex(r"\text{minimize}", r"\quad \sum_{\text{start}}^{\text{end}}")
obj2 = MathTex(r"d_{i,i+1}", r"\over", r"v_{i,i+1}")
obj1.set_color_by_tex("start", GREEN)
obj1.set_color_by_tex("end", GREEN)
obj2.move_to(obj1, RIGHT)
obj2.shift(1.5 * RIGHT)
obj2[0].set_color(YELLOW)
obj2[2].set_color(RED)
self.play(AnimationGroup(Write(obj1), Write(obj2)))
self.wait(3)

但我不得不求助于单独的对象。更糟糕的是,我用软糖因素手动对齐它们。

result

关于python - 为复杂方程 manim 的部分着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69408013/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com