Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply_complex_function HELP #3920

Closed
guiwenfeng opened this issue Aug 29, 2024 · 3 comments
Closed

apply_complex_function HELP #3920

guiwenfeng opened this issue Aug 29, 2024 · 3 comments

Comments

@guiwenfeng
Copy link

I wanted to turn the circle into an irregular shape by random scaling, as shown in Figure 1, but it didn't turn out what I wanted. Anyone can help me?

from manim import *
import random

class Test(Scene):

    def construct(self):
        circle = Circle()

        # circle.apply_complex_function(
        #     lambda z: z*2
        # )

        circle.apply_complex_function(
            lambda z: z*2*random.uniform(0.75, 1.25)
        )

        self.add(circle)

Figure 1
WechatIMG266

Result
Test3_ManimCE_v0 17 3

@uwezi
Copy link
Contributor

uwezi commented Aug 29, 2024

I don't completely understand what happens here, but if you scale down the amplitude of your randomness it gets better. Also a parametric curve for your circle seems to be a better choice, since a circle object in Manim does not contain many points.

class Test(Scene):

    def construct(self):
        #circle = Circle()
        circle = ParametricFunction(
            lambda t: np.array([np.cos(t),np.sin(t),0]),
            t_range=[0,2*PI,0.2]
        )
        # circle.apply_complex_function(
        #     lambda z: z*2
        # )

        circle.apply_complex_function(
            lambda z: z*np.random.uniform(1.975, 2.025)
        )

        self.add(circle)

image

@guiwenfeng
Copy link
Author

Thanks @uwezi ,My purpose is to generate an irregular shape, and now I've found a way.

from manim import *
import random


class IrregularShapeDemo(Scene):
    stroke_color = TEAL
    fill_color = BLUE_E
    fill_opacity = 1
    height = 2

    def construct(self):
        plane = NumberPlane()

        blob = VMobject()
        blob.set_points_as_corners([
            (1 + 0.3 * random.random()) * p
            for p in compass_directions(12)
        ])
        blob.close_path()
        blob.set_fill(self.fill_color, self.fill_opacity)
        blob.set_stroke(self.stroke_color)
        blob.set(height=self.height)
        blob.make_smooth()
        blob.center().shift(UP+RIGHT)

        self.add(plane, blob)

IrregularShapeDemo_ManimCE_v0 17 3

@uwezi
Copy link
Contributor

uwezi commented Sep 2, 2024

looks nice!

I didn't know that already VMobject() had the method .make_smooth()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants