Skip to content

Instantly share code, notes, and snippets.

@ncolyer11
Last active July 15, 2022 14:03
Show Gist options
  • Save ncolyer11/25466622f32a5c6eebe30b3e7af12595 to your computer and use it in GitHub Desktop.
Save ncolyer11/25466622f32a5c6eebe30b3e7af12595 to your computer and use it in GitHub Desktop.
Shroomlight Farm Manim Rendering Code
from manim import *
class BarCharExam(Scene):
def construct(self):
colors = [BLUE, ORANGE, BLUE, ORANGE, BLUE, ORANGE, BLUE, ORANGE]
values = [18, 10, 97.951, 0.05, 69.3, 1, 27.1125, 0]
yr = [0, 100, 25]
barct = BarChart(values, y_range = yr, bar_colors = colors)
bar = barct.get_bar_labels(font_size = 20)
txt = Text("(%)", font_size=24).shift(LEFT * 5)
txt1 = Text("Internal", font_size=24).shift(LEFT * 3 + DOWN * 2.4)
txt2 = Text("External", font_size=24).shift(LEFT * 1 + DOWN * 2.4)
txt3 = Text("Corners", font_size=24).shift(RIGHT * 1 + DOWN * 2.4)
txt4 = Text("Vines", font_size=24).shift(RIGHT * 3 + DOWN * 2.4)
lbl1 = Text("Wart Blocks", color = WHITE, font_size = 18).shift(RIGHT * 2.6 + UP * 1.7)
box1 = SurroundingRectangle(
lbl1, color = BLUE, fill_opacity = 0.7, buff = 0.18
)
lbl2 = Text("Shroomlights",color = WHITE, font_size = 17,disable_ligatures=True).shift(RIGHT * 2.6 + UP * 0.9)
box2 = SurroundingRectangle(
lbl2, color = ORANGE, fill_opacity = 0.7, buff = 0.14
)
all = VGroup(bar, barct, box1, box2, lbl1, lbl2, txt, txt1, txt2, txt3, txt4)
self.wait(1)
self.play(DrawBorderThenFill(all), rate_func = smooth, run_time = 2.5, )
self.wait(2)
from manim import*
class shot2(Scene):
def construct(self):
txt1 = MathTex(
r"T(x)",
r"=",
r"\text{Random}",
r"(4\rightarrow13)"
)
txt1[0].set_color(RED)
txt1[2].set_color(ORANGE)
txt2 = MathTex(
r"\text{if }",
r"\text{Random}",
r"(0\rightarrow1)<\frac{1}{12}"
)
txt2[1].set_color(ORANGE)
txt3 = MathTex(
r"T(x)",
r" = 2 \times",
r"T(x)"
)
txt3[0].set_color(RED)
txt3[2].set_color(RED)
txt3.shift(DOWN * 0.1)
ln1 = Line(UP * 0, UP * 1)
ln2 = Line(UP * 0.375, UP * 1.5)
self.wait(0.4)
self.play(Write(txt1), run_time = 0.75)
self.wait(1)
self.play(MoveAlongPath(txt1, ln1), Write(txt2), run_time = 1)
all = VGroup(txt1,txt2)
self.wait(1)
self.play(MoveAlongPath(all, ln2), Write(txt3))
import random
from manim import*
class shot3(Scene):
def construct(self):
#showing relationship between hat H(x) and trunk height T(x) with min()
txt1 = MathTex(
r"H(x)=",
r"\text{Min}(",
"T(x)",
")"
)
txt1[0][0].set_color("#00EEFF")
txt1[0][1].set_color("#00EEFF")
txt1[0][2].set_color("#00EEFF")
txt1[0][3].set_color("#00EEFF")
txt1[2][0].set_color(RED)
txt1[2][1].set_color(RED)
txt1[2][2].set_color(RED)
txt1[2][3].set_color(RED)
#introducing a random value with relation to trunk height T(x)
T = str("T(x)")
txt2 = MathTex(
r"H(x)=",
r"\text{Min}(",
T,
",\ ",
r"\text{Random}(0\rightarrow1+",
fr"\frac{{{T}}}{3})+5",
")"
)
txt2[0][0].set_color("#00EEFF")
txt2[0][1].set_color("#00EEFF")
txt2[0][2].set_color("#00EEFF")
txt2[0][3].set_color("#00EEFF")
txt2[4][0].set_color(ORANGE)
txt2[4][1].set_color(ORANGE)
txt2[4][2].set_color(ORANGE)
txt2[4][3].set_color(ORANGE)
txt2[4][4].set_color(ORANGE)
txt2[4][5].set_color(ORANGE)
txt2[2][0].set_color(RED)
txt2[2][1].set_color(RED)
txt2[2][2].set_color(RED)
txt2[2][3].set_color(RED)
txt2[5][0].set_color(RED)
txt2[5][1].set_color(RED)
txt2[5][2].set_color(RED)
txt2[5][3].set_color(RED)
#example scenario
T = str(7)
txt3 = MathTex(
r"H(x)=",
r"\text{Min}(",
T,
",\ ",
"6",
")=6"
).to_edge(DOWN,buff=2.2)
txt3[0][0].set_color("#00EEFF")
txt3[0][1].set_color("#00EEFF")
txt3[0][2].set_color("#00EEFF")
txt3[0][3].set_color("#00EEFF")
txt3[5][2].set_color("#00EEFF")
txt3[4][0].set_color(ORANGE)
txt3[2][0].set_color(RED)
txt4 = MathTex(
r"\text{Random}(0\rightarrow1+",
fr"\frac{{{T}}}{3})+5",
"=",
"6"
)
txt4[0][0].set_color(ORANGE)
txt4[0][1].set_color(ORANGE)
txt4[0][2].set_color(ORANGE)
txt4[0][3].set_color(ORANGE)
txt4[0][4].set_color(ORANGE)
txt4[0][5].set_color(ORANGE)
txt4[3][0].set_color(ORANGE)
txt4[1][0].set_color(RED)
T = str("T(x)")
txt5 = MathTex(
T,
"=7"
).to_edge(UP,buff=2.24)
txt5[0][0].set_color(RED)
txt5[0][1].set_color(RED)
txt5[0][2].set_color(RED)
txt5[0][3].set_color(RED)
txt5[1][1].set_color(RED)
#general animations
self.play(Write(txt1),run_time=0.9)
self.wait(0.5)
self.play(TransformMatchingTex(txt1,txt2))
self.wait(1)
self.play(TransformMatchingTex(txt2,txt4),Write(txt3), Write(txt5), run_time=1)
self.wait(1.5)
#looping through example values by iterating trunk height 't'
t = 7
while(t<=20):
self.remove(txt3,txt4,txt5)
i = random.randint(0,1+t//3)+5
h = min(t,i)
print(str(h)+" "+str(t))
txt3 = MathTex(
r"H(x)=\text{Min}(",
str(t),
",\ ",
str(h),
")=",
str(min(t,h))
).to_edge(DOWN,buff=2.2)
txt3[0][0].set_color("#00EEFF")
txt3[0][1].set_color("#00EEFF")
txt3[0][2].set_color("#00EEFF")
txt3[0][3].set_color("#00EEFF")
txt3[5][0].set_color("#00EEFF")
if (h >= 10):
txt3[5][1].set_color("#00EEFF")
txt3[3][0].set_color(ORANGE)
if (h >= 10):
txt3[3][1].set_color(ORANGE)
txt3[1][0].set_color(RED)
if (t >= 10):
txt3[1][1].set_color(RED)
txt4 = MathTex(
r"\text{Random}(0\rightarrow1+",
fr"\frac{{{t}}}{3})",
"+5=",
str(i)
)
txt4[0][0].set_color(ORANGE)
txt4[0][1].set_color(ORANGE)
txt4[0][2].set_color(ORANGE)
txt4[0][3].set_color(ORANGE)
txt4[0][4].set_color(ORANGE)
txt4[0][5].set_color(ORANGE)
txt4[3][0].set_color(ORANGE)
if (h >= 10):
txt4[3][1].set_color(ORANGE)
txt4[1][0].set_color(RED)
if (t >= 10):
txt4[1][1].set_color(RED)
txt5 = MathTex(
"T(x)="+" "+str(t)
).to_edge(UP,buff=2.24)
txt5[0][0].set_color(RED)
txt5[0][1].set_color(RED)
txt5[0][2].set_color(RED)
txt5[0][3].set_color(RED)
txt5[0][5].set_color(RED)
if (t >= 10):
txt5[0][6].set_color(RED)
self.play(TransformMatchingTex(txt3,txt3),TransformMatchingTex(txt4,txt4),TransformMatchingTex(txt5,txt5),run_time=0.5)
t+=1
self.wait(2)
import textwrap
from manim import*
import random
class shot4(ThreeDScene):
def construct(self):
t = random.randint(4,13)
if random.randint(0,12) == 0:
t*=2
h = min(t,random.randint(0,1+t//3)+5)
j = t - h
k = j
print("t =", str(t), "h =", str(h), "j =", str(j))
self.set_camera_orientation(phi = 91 * DEGREES, theta = 0 * DEGREES,zoom=0.26)
T = str("T(x)")
txt1 = MathTex(
r"&\text{if layer} <",
T,
r"\text{ - Random(}0\rightarrow3)\text{:}\\",
r"&\qquad\text{radius} = 2\\",
r"&\text{else:}\\",
r"&\qquad\text{radius} = 1\\",
r"&\text{if } H(x) > 8\ \text{\& layer} < T(x)-H(x) + 4\text{:}\\",
r"&\qquad\text{radius} = 3"
)
txt1[0][2].set_color(YELLOW_E)
txt1[0][3].set_color(YELLOW_E)
txt1[0][4].set_color(YELLOW_E)
txt1[0][5].set_color(YELLOW_E)
txt1[0][6].set_color(YELLOW_E)
txt1[6][9].set_color(YELLOW_E)
txt1[6][10].set_color(YELLOW_E)
txt1[6][11].set_color(YELLOW_E)
txt1[6][12].set_color(YELLOW_E)
txt1[6][13].set_color(YELLOW_E)
txt1[1].set_color(RED)
txt1[2][1].set_color(ORANGE)
txt1[2][2].set_color(ORANGE)
txt1[2][3].set_color(ORANGE)
txt1[2][4].set_color(ORANGE)
txt1[2][5].set_color(ORANGE)
txt1[2][6].set_color(ORANGE)
txt1[6][15].set_color(RED)
txt1[6][16].set_color(RED)
txt1[6][17].set_color(RED)
txt1[6][18].set_color(RED)
txt1[6][2].set_color("#00EEFF")
txt1[6][3].set_color("#00EEFF")
txt1[6][4].set_color("#00EEFF")
txt1[6][5].set_color("#00EEFF")
txt1[6][20].set_color("#00EEFF")
txt1[6][21].set_color("#00EEFF")
txt1[6][22].set_color("#00EEFF")
txt1[6][23].set_color("#00EEFF")
txt2 = MathTex(
r"&\text{if layer} <",
T,
r"\text{ - Random(}0\rightarrow3)\text{:}\\",
r"&\qquad\text{radius} = 2\\",
r"&\text{else:}\\",
r"&\qquad\text{radius} = 1\\",
r"&\text{if } H(x) > 8\ \text{\& layer} < T(x)-H(x) + 4\text{:}\\",
r"&\qquad\text{radius} = 3"
)
txt2.rotate(90 * DEGREES, axis=X_AXIS)
txt2.rotate(90 * DEGREES, axis=Z_AXIS)
txt2.shift(DOWN * 14)
txt2.scale(2.5)
txt2[0][2].set_color(YELLOW_E)
txt2[0][3].set_color(YELLOW_E)
txt2[0][4].set_color(YELLOW_E)
txt2[0][5].set_color(YELLOW_E)
txt2[0][6].set_color(YELLOW_E)
txt2[6][9].set_color(YELLOW_E)
txt2[6][10].set_color(YELLOW_E)
txt2[6][11].set_color(YELLOW_E)
txt2[6][12].set_color(YELLOW_E)
txt2[6][13].set_color(YELLOW_E)
txt2[2][1].set_color(ORANGE)
txt2[2][2].set_color(ORANGE)
txt2[2][3].set_color(ORANGE)
txt2[2][4].set_color(ORANGE)
txt2[2][5].set_color(ORANGE)
txt2[2][6].set_color(ORANGE)
txt2[1].set_color(RED)
txt2[6][15].set_color(RED)
txt2[6][16].set_color(RED)
txt2[6][17].set_color(RED)
txt2[6][18].set_color(RED)
txt2[6][2].set_color("#00EEFF")
txt2[6][3].set_color("#00EEFF")
txt2[6][4].set_color("#00EEFF")
txt2[6][5].set_color("#00EEFF")
txt2[6][20].set_color("#00EEFF")
txt2[6][21].set_color("#00EEFF")
txt2[6][22].set_color("#00EEFF")
txt2[6][23].set_color("#00EEFF")
txt1.rotate(90 * DEGREES, axis=X_AXIS)
txt1.rotate(90 * DEGREES, axis=Z_AXIS)
txt1.shift(DOWN * 14)
txt1.scale(2.5)
self.play(Write(txt1))
self.play(ReplacementTransform(txt1, txt2, run_time=0.5))
trunk = Prism(dimensions=[1,1,t], fill_color="#1f7ecc", fill_opacity=1).shift(IN * 0.5)
self.play(Create(trunk), run_time=0.3)
self.wait(0.5)
#loop
while(k<=t):
self.remove(txt2)
i = random.randint(0,3)
if k < t - i:
l = 2
else:
l = 1
if h > 8 and k < j + 4:
l = 3
print("l =", str(l), "k =", str(k), "i =", str(i))
if k < j + 3:
layer1 = Prism(dimensions=[2*l+1,2*l+1,1], fill_color="#55A7FA", fill_opacity=0.1).shift(IN * ((t+1)/2) + OUT * (k))
else:
layer1 = Prism(dimensions=[2*l+1,2*l+1,1], fill_color="#084678", fill_opacity=1).shift(IN * ((t+1)/2) + OUT * (k))
txt = MathTex(r"R(" + str(k) + ") = "+ str(l))
T = str(t)
txt2 = MathTex(
r"&\text{if }",
k,
r"<",
T,
r"\text{ - }",
str(i),
r"\text{:}\\",
r"&\qquad\text{radius} = 2\\",
r"&\text{else:}\\",
r"&\qquad\text{radius} = 1\\",
r"&\text{if }",
h,
r" > 8 \text{ \& }",
k,
r"<",
T,
r"-",
h,
r"+4\text{:}\\",
r"&\qquad\text{radius} = 3"
)
txt2.rotate(90 * DEGREES, axis=X_AXIS)
txt2.rotate(90 * DEGREES, axis=Z_AXIS)
txt2.shift(DOWN * 17.890, IN * 0.025)
txt2.scale(2.5)
txt2[3].set_color(RED)
txt2[15].set_color(RED)
txt2[1].set_color(YELLOW_E)
txt2[13].set_color(YELLOW_E)
txt2[5][0].set_color(ORANGE)
txt2[11].set_color("#00EEFF")
txt2[17].set_color("#00EEFF")
if l == 1:
txt.next_to(layer1, UP * 16)
txt2[9].set_color("#00EE77")
elif l == 2:
txt.next_to(layer1, UP * 12)
txt2[7].set_color("#00EE77")
else:
txt.next_to(layer1, UP * 8)
txt2[19].set_color("#00EE77")
txt.rotate(90 * DEGREES, axis=X_AXIS)
txt.rotate(90 * DEGREES, axis=Z_AXIS)
self.play(Create(layer1), Write(txt), ReplacementTransform(txt2, txt2), run_time=0.5)
k+=1
self.move_camera(theta = 90 * DEGREES)
self.wait(1)
from manim import*
class shot5(Scene):
def construct(self):
txt1 = MathTex(
r"A &=",
r"\text{Amount of cycles/h}\\",
r"P &=",
r"\text{Chance of bonemeal attempt failing}\\",
r"n &=",
r"\text{Number of Dispensers}")
txt1.shift(UP * 2)
txt1[0][0].set_color(YELLOW_E)
txt1[1].set_color(YELLOW_E)
txt1[2][0].set_color(ORANGE)
txt1[3].set_color(ORANGE)
txt1[4][0].set_color(BLUE_D)
txt1[5].set_color(BLUE_D)
txt5 = MathTex(
r"A &=",
r"18,000\\",
r"P &=",
r"0.6\\",
r"n &=",
r"3")
txt5.shift(UP * 2 + LEFT * 1.82)
txt5[0][0].set_color(YELLOW_E)
txt5[1].set_color(YELLOW_E)
txt5[2][0].set_color(ORANGE)
txt5[3].set_color(ORANGE)
txt5[4][0].set_color(BLUE_D)
txt5[5].set_color(BLUE_D)
txt6 = MathTex(
r"A &=",
r"18,000\\",
r"P &=",
r"0.6\\",
r"n &=",
r"4")
txt6.shift(UP * 2 + LEFT * 1.82)
txt6[0][0].set_color(YELLOW_E)
txt6[1].set_color(YELLOW_E)
txt6[2][0].set_color(ORANGE)
txt6[3].set_color(ORANGE)
txt6[4][0].set_color(BLUE_D)
txt6[5].set_color(BLUE_D)
txt2 = MathTex(
r"A",
r"(1-",
r"P^n",
r")\ =\ ",
r"\text{Tree's Grown/h}"
)
txt2[0].set_color(YELLOW_E)
txt2[2][0].set_color(ORANGE)
txt2[2][1].set_color(BLUE_D)
txt2[4].set_color(GREEN)
txt3 = MathTex(
r"18,000",
r"(1-",
r"0.6^3",
r")\ =\ ",
r"14,112"
)
txt3[0].set_color(YELLOW_E)
txt3[2][0].set_color(ORANGE)
txt3[2][1].set_color(ORANGE)
txt3[2][2].set_color(ORANGE)
txt3[2][3].set_color(BLUE_D)
txt3[4].set_color(GREEN)
txt4 = MathTex(
r"18,000",
r"(1-",
r"0.6^4",
r")\ =\ ",
r"15,667"
)
txt4[0].set_color(YELLOW_E)
txt4[2][0].set_color(ORANGE)
txt4[2][1].set_color(ORANGE)
txt4[2][2].set_color(ORANGE)
txt4[2][3].set_color(BLUE_D)
txt4[4].set_color(GREEN)
self.wait(0.5)
self.play(Write(txt1), Write(txt2), run_time = 1.5)
self.wait(2)
self.play(TransformMatchingTex(txt2, txt3), TransformMatchingTex(txt1, txt5), run_time = 1)
self.wait(2)
self.play(TransformMatchingTex(txt3, txt4), TransformMatchingTex(txt5, txt6), run_time = 0.6)
self.wait(2)
from manim import*
class shot6(Scene):
def construct(self):
txt1 = Text("External: 0.05%",color="#DD4400")
txt1.shift(1.3 * DOWN)
txt2 = Text("Internal: 10%", fill_opacity=0.4)
txt2.shift(2.5 * UP + 3 * RIGHT)
txt3 = Text("Corners: 1%",color="#00DD44")
txt3.shift(2.5 * UP + 3 * LEFT)
box = Rectangle(WHITE,1.2,5)
box.shift(1.3 * DOWN)
txt4 = Text("Selection:").shift(1.3 * DOWN + 4.1 * LEFT)
self.wait(0.3)
self.play(DrawBorderThenFill(box), Write(txt1), Write(txt2), Write(txt3), Write(txt4), run_time=2)
self.wait(0.5)
self.play(CyclicReplace(txt1, txt2, txt3), rate_functions=smooth)
self.wait(1)
from manim import*
class shot7(Scene):
def construct(self):
txt1 = MathTex("Basalt").shift(UP * 1)
box1 = SurroundingRectangle(
txt1, color=GRAY, fill_opacity=0.7, buff=0.25
)
txt1_1 = MathTex(r"\text{Blast\ res:\ }", "4.2").next_to(box1, DOWN, buff=0.25)
txt2 = MathTex("Slime").shift(DOWN * 0.705)
box2 = SurroundingRectangle(
txt2, color=GREEN, fill_opacity=0.6, buff=0.25
)
txt2_1 = MathTex(r"\text{Blast\ res:\ }", "0.0").next_to(box2, UP, buff=0.25)
self.play(Create(VGroup(box1, txt1, txt1_1)), run_time=1)
self.wait(1)
self.play(TransformMatchingShapes(VGroup(box1, txt1, txt1_1), VGroup(box2, txt2, txt2_1)), run_time=1)
self.wait(1)
from manim import *
class shot8(Scene):
def construct(self):
colors = [BLUE, GREEN]
values = [40, 64, 78.4, 87.04, 92.224]
yr = [0, 100, 25]
barct = BarChart(values, y_range = yr, bar_colors = colors)
bar = barct.get_bar_labels(font_size = 22)
txt = Text("Growth Chance\n per cycle (%)", font_size=24).shift(LEFT * 4.5)
txt1 = Text("Dispensers", font_size=24).shift(DOWN * 2.75)
txt2 = Text("1", font_size = 26).shift(DOWN * 2.3 + LEFT * 2)
txt3 = Text("5", font_size = 22).shift(DOWN * 2.3 + RIGHT * 2)
txt4 = Text("2", font_size = 26).shift(DOWN * 2.3 + LEFT * 1)
txt5 = Text("3", font_size = 22).shift(DOWN * 2.3)
txt6 = Text("4", font_size = 22).shift(DOWN * 2.3 + RIGHT * 1)
all = VGroup(bar, barct, txt, txt1, txt2, txt3, txt4, txt5, txt6)
self.wait(1)
self.play(DrawBorderThenFill(all), rate_func = smooth, run_time = 2.5, )
self.wait(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment