from manim import *
import numpy as np
from numpy import array
run_time = 1
data = [[1, 2], [3, 4]]
def dot(pos, **kwargs):
    return Dot(pos, **kwargs)
import numpy as np
class BadRoseCurve(Scene):
    def construct(self):
        axes = Axes(x_range=[-3, 3], y_range=[-3, 3])
        self.play(*[FadeIn(_o) for _o in [axes]], run_time=1.0)
        # 用累积密度法生成非均匀 theta：尖端稀疏(快)，中部密集(慢)
        n_points = 500
        t = np.linspace(0, 2 * PI, n_points)
        # 密度函数：在 cos(5t)=0 处(花瓣中部)密度高，在 |cos(5t)|=1 处(尖端)密度低
        density = 1 + 3 * np.sin(5 * t) ** 2
        theta = np.cumsum(density)
        theta = theta / theta[-1] * PI  # 归一化到 [0, π]（k为奇数时只需π即可画完）
        r = np.cos(5 * theta)
        x = r * 2 * np.cos(theta)
        y = r * 2 * np.sin(theta)
        points = [axes.c2p(x[i], y[i]) for i in range(n_points)]
        curve = VMobject(color=PINK, stroke_width=3)
        curve.set_points_as_corners(points)
        # 用 Create 画曲线——速度明显不均匀！
        self.play(Create(curve), run_time=5, rate_func=linear)
        self.wait()