Koch Curve¶
In mathematics, the intriguing concept of self-similarity emerges, wherein an object bears resemblance, either entirety or partially, to a smaller iteration of itself. A remarkable illustration of this phenomenon is the Koch Curve, showcasing the beauty of complexity inherent in self-similar geometric patterns. A fractal formed from the Koch Curve is the Koch Snowflake. It is created by repeatedly dividing each side of an equilateral triangle into three segments and replacing the middle segment with a smaller equilateral triangle. This process leads to a shape with an infinite perimeter enclosing a finite area. Koch Curve: The Beauty of Fractal Geometry
Setup¶
Review the documentation before exploring the scenes; plugins are required to render them. Docs
Create a new Colab notebook at colab.new and run the cells below.
The session will restart to apply changes.
%pip install mscene
import mscene
%mscene -l manim plugins
from mscene.manim import *
from mscene.plugins import *
Scenes¶
Example Scene¶
%%manim -qm ExampleScene
class ExampleScene(Scene):
def construct(self):
kc = KochCurve(level=2, stroke_width=6)
self.add(kc)
self.play(kc.animate.next_level())
self.wait()
self.play(kc.animate.prev_level())
self.wait()
Koch Curve¶
%%manim -qm KochCurveScene
class KochCurveScene(Scene):
def construct(self):
color = [ManimColor(hex) for hex in ("#0A68EF", "#0ADBEF", "#0A68EF")]
kc = KochCurve(level=0, stroke_width=8, stroke_color=color)
title = Text("Koch Curve\nLevel 0").to_corner(UL, buff=0.75)
self.add(title, kc)
self.wait()
levels = (1, 2, 3, 2, 1, 0)
for level in levels:
self.play(
kc.animate(run_time=1.5).new_level(level, stroke_width=8 - level),
Transform(title[-1], Text(str(level)).move_to(title[-1])),
)
self.wait()
Koch Snowflake¶
%%manim -qm KochSnowflakeScene
class KochSnowflakeScene(Scene):
def construct(self):
color = [ManimColor(hex) for hex in ("#0ADBEF", "#0A68EF", "#1F0AEF")]
ks = KochSnowflake(level=0, fill_color=color)
title = Text("Koch Snowflake\nLevel 0").to_corner(UL, buff=0.75)
self.add(title, ks)
self.wait()
levels = (1, 2, 3, 2, 1, 0)
for level in levels:
self.play(
ks.animate(run_time=1.5).new_level(level),
Transform(title[-1], Text(str(level)).move_to(title[-1])),
)
self.wait()
Koch Antisnowflake¶
%%manim -qm KochAntisnowflakeScene
class KochAntisnowflakeScene(Scene):
def construct(self):
color = [ManimColor(hex) for hex in ("#1F0AEF", "#0A68EF", "#0ADBEF")]
ks = KochSnowflake(level=0, invert=True, fill_color=color)
title = Text("Koch Anti-\nsnowflake\nLevel 0").to_corner(UL, buff=0.75)
self.add(title, ks)
self.wait()
levels = (1, 2, 3, 2, 1, 0)
for level in levels:
self.play(
ks.animate(run_time=1.5).new_level(level),
Transform(title[-1], Text(str(level)).move_to(title[-1])),
)
self.wait()
Two Flakes¶
%%manim -qm TwoFlakesScene
class TwoFlakesScene(Scene):
def construct(self):
ks1 = KochSnowflake(level=1, fill_color=ManimColor("#5d06e9"))
ks2 = KochSnowflake(
level=1, invert=True, fill_color=ManimColor("#9e0168")
).align_to(ks1, UP)
self.add(ks1, ks2)
self.wait()
levels = (2, 3, 2, 1)
for level in levels:
self.play(
ks1.animate.new_level(level), ks2.animate.new_level(level), run_time=1.5
)
self.wait()