Repository: ManimCommunity/manim
File: manim/mobject/vector_field.py (Python)

Code before:
                or p[0] > self.x_max + self.padding
                or p[1] < self.y_min - self.padding
                or p[1] > self.y_max + self.padding
            )

        max_steps = ceil(virtual_time / dt) + 1
        if not self.single_color:
            self.background_img = self.get_colored_background_image()
            if config["renderer"] == "opengl":
                self.values_to_rgbas = self.get_vectorized_rgba_gradient_function(
                    min_color_scheme_value,
                    max_color_scheme_value,
                    colors,
                )
        for point in start_points:
            points = [point]
            for _ in range(max_steps):
                last_point = points[-1]
                new_point = last_point + dt * func(last_point)
                if outside_box(new_point):
                    break
                points.append(new_point)
            step = max_steps
            if not step:
                continue
            line = Line()
            line.duration = step * dt
            step = max(1, int(len(points) / self.max_anchors_per_line))
            line.set_points_smoothly(points[::step])
            if self.single_color:
                line.set_stroke(self.color)
            else:
                if config["renderer"] == "opengl":
                    # scaled for compatibility with cairo
                    line.set_stroke(width=self.stroke_width / 4.0)
                    norms = [
                        self.get_norm(self.func(point)) for point in line.get_points()
                    ]
                    line.set_rgba_array_direct(self.values_to_rgbas(norms, opacity))
                else:
                    line.color_using_background_image(self.background_img)
                    line.set_stroke(width=self.stroke_width, opacity=opacity)
            self.add(line)
        self.stream_lines = [*self.submobjects]

    def get_norm(self, vect):
        return sum(x ** 2 for x in vect) ** 0.5

    def create(
        self,
        lag_ratio: Optional[float] = None,

Review comment (suggestion):
A `Line` probably initializes some un-needed attributes, so a `VMobject` might be more appropriate. To get around incompatibility, you could use a `VGroup`, or add a check for the OpenGL renderer.

Code after:

        half_noise = self.noise_factor / 2
        np.random.seed(0)
        start_points = np.array(
            [
                (x - half_noise) * RIGHT
                + (y - half_noise) * UP
                + self.noise_factor * np.random.random(3)
                for n in range(self.n_repeats)
                for x in np.arange(self.x_min, self.x_max + self.delta_x, self.delta_x)
                for y in np.arange(self.y_min, self.y_max + self.delta_y, self.delta_y)
            ],
        )

        def outside_box(p):
            return (
                p[0] < self.x_min - self.padding
                or p[0] > self.x_max + self.padding
                or p[1] < self.y_min - self.padding
                or p[1] > self.y_max + self.padding
            )

        max_steps = ceil(virtual_time / dt) + 1
        if not self.single_color:
            self.background_img = self.get_colored_background_image()
            if config["renderer"] == "opengl":
                self.values_to_rgbas = self.get_vectorized_rgba_gradient_function(
                    min_color_scheme_value,
                    max_color_scheme_value,
                    colors,
                )
        for point in start_points:
            points = [point]
            for _ in range(max_steps):
                last_point = points[-1]
                new_point = last_point + dt * func(last_point)
                if outside_box(new_point):
                    break
                points.append(new_point)
            step = max_steps
            if not step:
                continue
            if config["renderer"] == "opengl":
                line = OpenGLVMobject()
            else:
                line = VMobject()
            line.duration = step * dt
            step = max(1, int(len(points) / self.max_anchors_per_line))
            line.set_points_smoothly(points[::step])
            if self.single_color:
                line.set_stroke(self.color)