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

Code before:
from ...constants import *
from ...mobject.opengl_mobject import OpenGLMobject
from ...utils.bezier import interpolate
from ...utils.color import BLACK, WHITE, YELLOW, color_gradient, color_to_rgba
from ...utils.iterables import resize_with_interpolation


class OpenGLPMObject(OpenGLMobject):
    shader_folder = "true_dot"
    # Scale for consistency with cairo units
    OPENGL_POINT_RADIUS_SCALE_FACTOR = 0.01
    shader_dtype = [
        ("point", np.float32, (3,)),
        ("color", np.float32, (4,)),
    ]

    def __init__(
        self, stroke_width=2.0, color=YELLOW, render_primitive=moderngl.POINTS, **kwargs
    ):
        self.stroke_width = stroke_width
        super().__init__(color=color, render_primitive=render_primitive, **kwargs)

    def reset_points(self):
        self.rgbas = np.zeros((0, 4))
        self.points = np.zeros((0, 3))
        return self

    def init_uniforms(self):
        super().init_uniforms()
        self.uniforms["point_radius"] = (
            self.stroke_width * OpenGLPMObject.OPENGL_POINT_RADIUS_SCALE_FACTOR
        )

    def get_array_attrs(self):
        return ["points", "rgbas"]

    def add_points(self, points, rgbas=None, color=None, opacity=None):
        """
        points must be a Nx3 numpy array, as must rgbas if it is not None
        """
        if rgbas is None and color is None:
            color = YELLOW
        self.append_points(points)
        # rgbas array will have been resized with points
        if color is not None:
            if opacity is None:
                opacity = self.data["rgbas"][-1, 3]
            new_rgbas = np.repeat([color_to_rgba(color, opacity)], len(points), axis=0)
        elif rgbas is not None:
            new_rgbas = rgbas
        elif len(rgbas) != len(points):

Review comment (suggestion):
I'm not entirely sure, but `reset_points` feels a little redundant since `init_data` already defines these attributes. 

Code after:
from ...constants import *
from ...mobject.opengl_mobject import OpenGLMobject
from ...utils.bezier import interpolate
from ...utils.color import BLACK, WHITE, YELLOW, color_gradient, color_to_rgba
from ...utils.config_ops import _Uniforms
from ...utils.iterables import resize_with_interpolation


class OpenGLPMobject(OpenGLMobject):
    shader_folder = "true_dot"
    # Scale for consistency with cairo units
    OPENGL_POINT_RADIUS_SCALE_FACTOR = 0.01
    shader_dtype = [
        ("point", np.float32, (3,)),
        ("color", np.float32, (4,)),
    ]

    point_radius = _Uniforms()

    def __init__(
        self, stroke_width=2.0, color=YELLOW, render_primitive=moderngl.POINTS, **kwargs
    ):
        self.stroke_width = stroke_width
        super().__init__(color=color, render_primitive=render_primitive, **kwargs)
        self.point_radius = (
            self.stroke_width * OpenGLPMobject.OPENGL_POINT_RADIUS_SCALE_FACTOR
        )

    def reset_points(self):
        self.rgbas = np.zeros((1, 4))
        self.points = np.zeros((0, 3))
        return self

    def get_array_attrs(self):
        return ["points", "rgbas"]

    def add_points(self, points, rgbas=None, color=None, opacity=None):
        """
        points must be a Nx3 numpy array, as must rgbas if it is not None
        """
        if rgbas is None and color is None:
            color = YELLOW
        self.append_points(points)
        # rgbas array will have been resized with points
        if color is not None:
            if opacity is None:
                opacity = self.rgbas[-1, 3]
            new_rgbas = np.repeat([color_to_rgba(color, opacity)], len(points), axis=0)
        elif rgbas is not None:
            new_rgbas = rgbas
        elif len(rgbas) != len(points):