def draw_polygon_outline(point_list: PointList, color: Color, line_width: float = 1): """ Draw a polygon outline. Also known as a "line loop." :param PointList point_list: List of points making up the lines. Each point is in a list. So it is a list of lists. :param Color color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :param int line_width: Width of the line in pixels. """ new_point_list = [point for point in point_list] new_point_list.append(point_list[0]) triangle_point_list = [] # This needs a lot of improvement last_point = None for point in new_point_list: if last_point is not None: points = get_points_for_thick_line(last_point[0], last_point[1], point[0], point[1], line_width) reordered_points = points[1], points[0], points[2], points[3] triangle_point_list.extend(reordered_points) last_point = point points = get_points_for_thick_line(new_point_list[0][0], new_point_list[0][1], new_point_list[1][0], new_point_list[1][1], line_width) triangle_point_list.append(points[1]) _generic_draw_line_strip(triangle_point_list, color, gl.GL_TRIANGLE_STRIP)
def create_line(start_x: float, start_y: float, end_x: float, end_y: float, color: Color, line_width: float = 1) -> Shape: """ Create a line to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame. :param float start_x: :param float start_y: :param float end_x: :param float end_y: :param Color color: :param float line_width: :Returns Shape: """ points = get_points_for_thick_line(start_x, start_y, end_x, end_y, line_width) color_list = [color, color, color, color] triangle_point_list = points[1], points[0], points[2], points[3] shape = create_triangles_filled_with_colors(triangle_point_list, color_list) return shape
def create_lines_with_colors(point_list: PointList, color_list: Sequence[Color], line_width: float = 1): if line_width == 1: return create_line_generic_with_colors(point_list, color_list, gl.GL_LINES, line_width) else: triangle_point_list: List[Point] = [] new_color_list: List[Color] = [] for i in range(1, len(point_list), 2): start_x = point_list[i - 1][0] start_y = point_list[i - 1][1] end_x = point_list[i][0] end_y = point_list[i][1] color1 = color_list[i - 1] color2 = color_list[i] points = get_points_for_thick_line(start_x, start_y, end_x, end_y, line_width) new_color_list += color1, color1, color2, color2 triangle_point_list += points[1], points[0], points[2], points[3] shape = create_triangles_filled_with_colors( triangle_point_list, new_color_list) return shape
def draw_lines(point_list: PointList, color: Color, line_width: float = 1): """ Draw a set of lines. Draw a line between each pair of points specified. :param PointList point_list: List of points making up the lines. Each point is in a list. So it is a list of lists. :param Color color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :param float line_width: Width of the line in pixels. """ triangle_point_list: PointList = [] last_point = None for point in point_list: if last_point is not None: points = get_points_for_thick_line(last_point[0], last_point[1], point[0], point[1], line_width) reordered_points = points[1], points[0], points[2], points[ 0], points[2], points[3] # noinspection PyUnresolvedReferences triangle_point_list.extend(reordered_points) _generic_draw_line_strip(triangle_point_list, color, gl.GL_TRIANGLES) last_point = None else: last_point = point
def draw_line_strip(point_list: PointList, color: Color, line_width: float = 1): """ Draw a multi-point line. :param PointList point_list: List of x, y points that make up this strip :param Color color: Color of line strip :param float line_width: Width of the line """ if line_width == 1: _generic_draw_line_strip(point_list, color, gl.GL_LINE_STRIP) else: triangle_point_list: PointList = [] # This needs a lot of improvement last_point = None for point in point_list: if last_point is not None: points = get_points_for_thick_line(last_point[0], last_point[1], point[0], point[1], line_width) reordered_points = points[1], points[0], points[2], points[3] # noinspection PyUnresolvedReferences triangle_point_list.extend(reordered_points) last_point = point _generic_draw_line_strip(triangle_point_list, color, gl.GL_TRIANGLE_STRIP)
def create_line_strip(point_list: PointList, color: Color, line_width: float = 1): """ Create a multi-point line to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame. Internally, thick lines are created by two triangles. :param PointList point_list: :param Color color: :param PointList line_width: :Returns Shape: """ if line_width == 1: return create_line_generic(point_list, color, gl.GL_LINE_STRIP, line_width) else: triangle_point_list: List[Point] = [] new_color_list: List[Color] = [] for i in range(1, len(point_list)): start_x = point_list[i - 1][0] start_y = point_list[i - 1][1] end_x = point_list[i][0] end_y = point_list[i][1] color1 = color color2 = color points = get_points_for_thick_line(start_x, start_y, end_x, end_y, line_width) new_color_list += color1, color2, color1, color2 triangle_point_list += points[1], points[0], points[2], points[3] shape = create_triangles_filled_with_colors(triangle_point_list, new_color_list) return shape
def draw_line(start_x: float, start_y: float, end_x: float, end_y: float, color: Color, line_width: float = 1): """ Draw a line. :param float start_x: x position of line starting point. :param float start_y: y position of line starting point. :param float end_x: x position of line ending point. :param float end_y: y position of line ending point. :param Color color: color, specified in a list of 3 or 4 bytes in RGB or RGBA format. :param float line_width: Width of the line in pixels. """ # points = (start_x, start_y), (end_x, end_y) points = get_points_for_thick_line(start_x, start_y, end_x, end_y, line_width) triangle_point_list = points[1], points[0], points[2], points[3] _generic_draw_line_strip(triangle_point_list, color, gl.GL_TRIANGLE_STRIP)