コード例 #1
0
    def get_bezier_curve_edgematrix(p1, i1, i2, p2, step=30):
        """
        Generates an EdgeMatrix of lines representing a bezier curve.

        Parameters:
        p1: list, the first endpoint of the bezier curve
        i1: list, the first influence point of the bezier curve
        i2: list, the second influence point of the bezier curve
        p2: list, the second endpoint of the bezier curve
        step: int (optional), the number of steps to use when drawing splines
            for the hermite curve
        """
        def x(t):
            return Generator.get_bezier_function(p1[0], i1[0], i2[0], p2[0])(t)

        def y(t):
            return Generator.get_bezier_function(p1[1], i1[1], i2[1], p2[1])(t)

        def z(t):
            return 0

        parametric = Parametric(x, y, z)
        edgematrix = EdgeMatrix()
        step_range = Generator.get_step_range(0, 1, step)
        for i in range(len(step_range) - 1):
            edgematrix.add_edge(parametric.get_point(step_range[i]),
                                parametric.get_point(step_range[i + 1]))
        return edgematrix
コード例 #2
0
    def get_polygon_edgematrix(center_x, center_y, radius, sides):
        """
        Generates an EdgeMatrix of lines representing a regular polygon
        centered at the given points inscribed within a circle of the
        given radius.

        Parameters:
        center_x: int, the x coordinate of the center of the polygon
        center_y: int, the y coordinate of the center of the polygon
        radius: int, the radius of the circle
        sides: int, the number of sides in the polygon
        """
        def x(t):
            return cos(t) * radius + center_x

        def y(t):
            return sin(t) * radius + center_y

        def z(t):
            return 0

        parametric = Parametric(x, y, z)
        edgematrix = EdgeMatrix()
        step_range = Generator.get_step_range(0, 2 * pi, sides)
        for i in range(len(step_range) - 1):
            edgematrix.add_edge(parametric.get_point(step_range[i]),
                                parametric.get_point(step_range[i + 1]))
        return edgematrix
コード例 #3
0
    def get_hermite_curve_edgematrix(p1, r1, p2, r2, step=30):
        """
        Generates an EdgeMatrix of lines representing a hermite curve.

        Parameters:
        p1: list, the first point of the hermite curve
        r1: list, the rate of change at p1
        p2: list, the second point of the hermite curve
        r2: list, the rate of change at p2
        step: int (optional), the number of steps to use when drawing splines
            for the hermite curve
        """
        points = Matrix(matrix=[p1, p2, r1, r2])
        inverse = Matrix([[2, -2, 1, 1], [-3, 3, -2, -1], [0, 0, 1, 0],
                          [1, 0, 0, 0]])
        c = inverse * points

        def x(t):
            return Generator.get_hermite_function(c[0][0], c[1][0], c[2][0],
                                                  c[3][0])(t)

        def y(t):
            return Generator.get_hermite_function(c[0][1], c[1][1], c[2][1],
                                                  c[3][1])(t)

        def z(t):
            return 0

        parametric = Parametric(x, y, z)
        edgematrix = EdgeMatrix()
        step_range = Generator.get_step_range(0, 1, step)
        for i in range(len(step_range) - 1):
            edgematrix.add_edge(parametric.get_point(step_range[i]),
                                parametric.get_point(step_range[i + 1]))
        return edgematrix
コード例 #4
0
ファイル: generator.py プロジェクト: omgimanerd/graphics
    def get_hermite_curve_edgematrix(p1, r1, p2, r2, step=30):
        """
        Generates an EdgeMatrix of lines representing a hermite curve.

        Parameters:
        p1: list, the first point of the hermite curve
        r1: list, the rate of change at p1
        p2: list, the second point of the hermite curve
        r2: list, the rate of change at p2
        step: int (optional), the number of steps to use when drawing splines
            for the hermite curve
        """
        points = Matrix(matrix=[p1, p2, r1, r2])
        inverse = Matrix([
            [2, -2, 1, 1],
            [-3, 3, -2, -1],
            [0, 0, 1, 0],
            [1, 0, 0, 0]])
        c = inverse * points
        def x(t): return Generator.get_hermite_function(
            c[0][0], c[1][0], c[2][0], c[3][0])(t)
        def y(t): return Generator.get_hermite_function(
            c[0][1], c[1][1], c[2][1], c[3][1])(t)
        def z(t): return 0
        parametric = Parametric(x, y, z)
        edgematrix = EdgeMatrix()
        step_range = Generator.get_step_range(0, 1, step)
        for i in range(len(step_range) - 1):
            edgematrix.add_edge(parametric.get_point(step_range[i]),
                                parametric.get_point(step_range[i + 1]))
        return edgematrix
コード例 #5
0
ファイル: generator.py プロジェクト: omgimanerd/graphics
    def get_polygon_edgematrix(center_x, center_y, radius, sides):
        """
        Generates an EdgeMatrix of lines representing a regular polygon
        centered at the given points inscribed within a circle of the
        given radius.

        Parameters:
        center_x: int, the x coordinate of the center of the polygon
        center_y: int, the y coordinate of the center of the polygon
        radius: int, the radius of the circle
        sides: int, the number of sides in the polygon
        """
        def x(t): return cos(t) * radius + center_x
        def y(t): return sin(t) * radius + center_y
        def z(t): return 0
        parametric = Parametric(x, y, z)
        edgematrix = EdgeMatrix()
        step_range = Generator.get_step_range(0, 2 * pi, sides)
        for i in range(len(step_range) - 1):
            edgematrix.add_edge(parametric.get_point(step_range[i]),
                                parametric.get_point(step_range[i + 1]))
        return edgematrix
コード例 #6
0
ファイル: generator.py プロジェクト: omgimanerd/graphics
    def get_bezier_curve_edgematrix(p1, i1, i2, p2, step=30):
        """
        Generates an EdgeMatrix of lines representing a bezier curve.

        Parameters:
        p1: list, the first endpoint of the bezier curve
        i1: list, the first influence point of the bezier curve
        i2: list, the second influence point of the bezier curve
        p2: list, the second endpoint of the bezier curve
        step: int (optional), the number of steps to use when drawing splines
            for the hermite curve
        """
        def x(t): return Generator.get_bezier_function(
            p1[0], i1[0], i2[0], p2[0])(t)
        def y(t): return Generator.get_bezier_function(
            p1[1], i1[1], i2[1], p2[1])(t)
        def z(t): return 0
        parametric = Parametric(x, y, z)
        edgematrix = EdgeMatrix()
        step_range = Generator.get_step_range(0, 1, step)
        for i in range(len(step_range) - 1):
            edgematrix.add_edge(parametric.get_point(step_range[i]),
                                parametric.get_point(step_range[i + 1]))
        return edgematrix
コード例 #7
0
    def draw_line(self, x1, y1, z1, x2, y2, z2, color=Color.BLACK()):
        """
        Draws the a line onto the internal raster after applying the current
        TransformationMatrix on the stack.

        Parameters:
        x1: int, the x coordinate of the first endpoint of the line
        y1: int, the y coordinate of the first endpoint of the line
        z1: int, the z coordinate of the first endpoint of the line
        x1: int, the x coordinate of the second endpoint of the line
        y1: int, the y coordinate of the second endpoint of the line
        z1: int, the z coordinate of the second endpoint of the line
        color: Color (optional), the color of the line
        """
        self.draw_edgematrix(EdgeMatrix([[x1, y1, z1, 1], [x2, y2, z2, 1]]),
                             color)