3b1b / manim

Animation engine for explanatory math videos
MIT License
70.79k stars 6.23k forks source link

Generated surface has artifacts #2033

Closed MartensCedric closed 1 year ago

MartensCedric commented 1 year ago

Describe the bug

When i generate a surface, I observe strange artitifacts

Code:

from perlin_noise import PerlinNoise
def perlin_noise(noise, u, v, octaves=8):
    total = 0
    p = [u, v]
    for i in range(octaves):
        total += (1 / (2 ** i)) * noise([(2 ** i) * x for x in p])
    return total / (2 - 1 / (2 ** (octaves - 1)))

class TerrainGen(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        noise = PerlinNoise()
        res = 64
        surface = Surface(
            lambda u, v: axes.c2p(u, v, perlin_noise(noise, u, v)),
            u_range=[-1, 1],
            v_range=[-1, 1],
            resolution=(int(np.sqrt(res)), int(np.sqrt(res)))
        )
        surface.set_style(fill_opacity=1)
        surface.set_fill_by_value(axes=axes, colorscale=[(RED, -0.5), (YELLOW, 0), (GREEN, 0.5)], axis=2)
        surface.scale(5, about_point=ORIGIN)
        three_d_stuff = VGroup(surface)
        self.set_camera_orientation(theta=70 * DEGREES, phi=75 * DEGREES)
        self.begin_ambient_camera_rotation(rate=PI / 20)
        # self.add(axes)
        self.play(Create(surface))
        self.wait(5)

Wrong display or Error traceback:

Additional context

image