# Path: p5/core/p5.py

# 
# Path: p5/core/constants.py
# class SType(Enum):
#     POINTS = 'POINTS'
#     LINES = 'LINES'
#     LINE_STRIP = 'LINE_STRIP'
#     TRIANGLES = 'TRIANGLES'
#     TRIANGLE_FAN = 'TRIANGLE_FAN'
#     TRIANGLE_STRIP = 'TRIANGLE_STRIP'
#     QUADS = 'QUADS'
#     QUAD_STRIP = 'QUAD_STRIP'
#     TESS = 'TESS'
# 
# ROUND = "ROUND"
# 
# MITER = "MITER"
# 
# Path: p5/sketch/Vispy2DRenderer/shape.py
# class Arc(PShape):
#     def __init__(self, center, radii, start_angle, stop_angle,
#                  mode=None, fill_color='auto',
#                  stroke_color='auto', stroke_weight="auto",
#                  stroke_join="auto", stroke_cap="auto", **kwargs):
#         self._center = center
#         self._radii = radii
#         self._start_angle = start_angle
#         self._stop_angle = stop_angle
#         self.arc_mode = mode
# 
#         gl_type = SType.TESS if mode in [
#             'OPEN', 'CHORD'] else SType.TRIANGLE_FAN
#         super().__init__(fill_color=fill_color,
#                          stroke_color=stroke_color, stroke_weight=stroke_weight,
#                          stroke_join=stroke_join, stroke_cap=stroke_cap, shape_type=gl_type, **kwargs)
#         self._tessellate()
# 
#     def _tessellate(self):
#         """Generate vertex and face data using radii.
#         """
#         rx = self._radii[0]
#         ry = self._radii[1]
# 
#         c1x = self._center[0]
#         c1y = self._center[1]
#         s1 = p5.renderer.transform_matrix.dot(np.array([c1x, c1y, 0, 1]))
# 
#         c2x = c1x + rx
#         c2y = c1y + ry
#         s2 = p5.renderer.transform_matrix.dot(np.array([c2x, c2y, 0, 1]))
# 
#         sdiff = (s2 - s1)
#         size_acc = (np.sqrt(np.sum(sdiff * sdiff)) *
#                     math.pi * 2) / POINT_ACCURACY_FACTOR
# 
#         acc = min(MAX_POINT_ACCURACY, max(MIN_POINT_ACCURACY, int(size_acc)))
#         inc = int(len(SINCOS) / acc)
# 
#         sclen = len(SINCOS)
#         start_index = int((self._start_angle / (math.pi * 2)) * sclen)
#         end_index = int((self._stop_angle / (math.pi * 2)) * sclen)
# 
#         vertices = [(c1x, c1y, 0)] if self.arc_mode in ['PIE', None] else []
#         for idx in range(start_index, end_index, inc):
#             i = idx % sclen
#             vertices.append((
#                 c1x + rx * SINCOS[i][1],
#                 c1y + ry * SINCOS[i][0],
#                 0
#             ))
#         vertices.append((
#             c1x + rx * SINCOS[end_index % sclen][1],
#             c1y + ry * SINCOS[end_index % sclen][0],
#             0
#         ))
#         if self.arc_mode == 'CHORD' or self.arc_mode == 'PIE':
#             vertices.append(vertices[0])
#         self.vertices = vertices


from abc import ABC
from p5.core import p5
from p5.core.constants import SType, ROUND, MITER
from .shape import Arc
from dataclasses import dataclass
from vispy.gloo import Program, VertexBuffer, FrameBuffer, IndexBuffer
from OpenGL.GLU import gluTessBeginPolygon, gluTessBeginContour, gluTessEndPolygon, gluTessEndContour, gluTessVertex
import numpy as np
    elif shape.shape_type == SType.QUAD_STRIP:
        start = np.concatenate(
            (np.arange(
                0, n_vert, 2), np.arange(
                n_vert - 2)))
        end = np.concatenate((np.arange(1, n_vert, 2), np.arange(2, n_vert)))
        _add_edges_to_primitive_list(
            render_primitives, shape.vertices, start, end)
    elif shape.shape_type == SType.LINES:
        start = np.arange(0, n_vert, 2)
        end = np.arange(1, n_vert, 2)
        _add_edges_to_primitive_list(
            render_primitives, shape.vertices, start, end)
    elif shape.shape_type == SType.LINE_STRIP:
        render_primitives.append(_get_line_from_verts(shape.vertices))
    elif shape.shape_type == SType.TESS:
        render_primitives.append(_get_line_from_verts(shape.vertices))
        for contour in shape.contours:
            render_primitives.append(_get_line_from_verts(contour))
    return render_primitives


def _get_meshes(shape):
    """Generates the rendering primitives for the meshes of a given shape

    :returns: [shape_type, vertices, idx]
    """
    render_primitives = []
    n_vert = len(shape.vertices)
    if shape.shape_type in [

# Path: p5/core/p5.py

# 
# Path: p5/core/constants.py
# class SType(Enum):
#     POINTS = 'POINTS'
#     LINES = 'LINES'
#     LINE_STRIP = 'LINE_STRIP'
#     TRIANGLES = 'TRIANGLES'
#     TRIANGLE_FAN = 'TRIANGLE_FAN'
#     TRIANGLE_STRIP = 'TRIANGLE_STRIP'
#     QUADS = 'QUADS'
#     QUAD_STRIP = 'QUAD_STRIP'
#     TESS = 'TESS'
# 
# ROUND = "ROUND"
# 
# MITER = "MITER"
# 
# Path: p5/sketch/Vispy2DRenderer/shape.py
# class Arc(PShape):
#     def __init__(self, center, radii, start_angle, stop_angle,
#                  mode=None, fill_color='auto',
#                  stroke_color='auto', stroke_weight="auto",
#                  stroke_join="auto", stroke_cap="auto", **kwargs):
#         self._center = center
#         self._radii = radii
#         self._start_angle = start_angle
#         self._stop_angle = stop_angle
#         self.arc_mode = mode
# 
#         gl_type = SType.TESS if mode in [
#             'OPEN', 'CHORD'] else SType.TRIANGLE_FAN
#         super().__init__(fill_color=fill_color,
#                          stroke_color=stroke_color, stroke_weight=stroke_weight,
#                          stroke_join=stroke_join, stroke_cap=stroke_cap, shape_type=gl_type, **kwargs)
#         self._tessellate()
# 
#     def _tessellate(self):
#         """Generate vertex and face data using radii.
#         """
#         rx = self._radii[0]
#         ry = self._radii[1]
# 
#         c1x = self._center[0]
#         c1y = self._center[1]
#         s1 = p5.renderer.transform_matrix.dot(np.array([c1x, c1y, 0, 1]))
# 
#         c2x = c1x + rx
#         c2y = c1y + ry
#         s2 = p5.renderer.transform_matrix.dot(np.array([c2x, c2y, 0, 1]))
# 
#         sdiff = (s2 - s1)
#         size_acc = (np.sqrt(np.sum(sdiff * sdiff)) *
#                     math.pi * 2) / POINT_ACCURACY_FACTOR
# 
#         acc = min(MAX_POINT_ACCURACY, max(MIN_POINT_ACCURACY, int(size_acc)))
#         inc = int(len(SINCOS) / acc)
# 
#         sclen = len(SINCOS)
#         start_index = int((self._start_angle / (math.pi * 2)) * sclen)
#         end_index = int((self._stop_angle / (math.pi * 2)) * sclen)
# 
#         vertices = [(c1x, c1y, 0)] if self.arc_mode in ['PIE', None] else []
#         for idx in range(start_index, end_index, inc):
#             i = idx % sclen
#             vertices.append((
#                 c1x + rx * SINCOS[i][1],
#                 c1y + ry * SINCOS[i][0],
#                 0
#             ))
#         vertices.append((
#             c1x + rx * SINCOS[end_index % sclen][1],
#             c1y + ry * SINCOS[end_index % sclen][0],
#             0
#         ))
#         if self.arc_mode == 'CHORD' or self.arc_mode == 'PIE':
#             vertices.append(vertices[0])
#         self.vertices = vertices


# Path: p5/sketch/Vispy2DRenderer/openglrenderer.py
from abc import ABC
from p5.core import p5
from p5.core.constants import SType, ROUND, MITER
from .shape import Arc
from dataclasses import dataclass
from vispy.gloo import Program, VertexBuffer, FrameBuffer, IndexBuffer
from OpenGL.GLU import gluTessBeginPolygon, gluTessBeginContour, gluTessEndPolygon, gluTessEndContour, gluTessVertex
import numpy as np

    elif shape.shape_type == SType.QUAD_STRIP:
        start = np.concatenate(
            (np.arange(
                0, n_vert, 2), np.arange(
                n_vert - 2)))
        end = np.concatenate((np.arange(1, n_vert, 2), np.arange(2, n_vert)))
        _add_edges_to_primitive_list(
            render_primitives, shape.vertices, start, end)
    elif shape.shape_type == SType.LINES:
        start = np.arange(0, n_vert, 2)
        end = np.arange(1, n_vert, 2)
        _add_edges_to_primitive_list(
            render_primitives, shape.vertices, start, end)
    elif shape.shape_type == SType.LINE_STRIP:
        render_primitives.append(_get_line_from_verts(shape.vertices))
    elif shape.shape_type == SType.TESS:
        render_primitives.append(_get_line_from_verts(shape.vertices))
        for contour in shape.contours:
            render_primitives.append(_get_line_from_verts(contour))
    return render_primitives


def _get_meshes(shape):
    """Generates the rendering primitives for the meshes of a given shape

    :returns: [shape_type, vertices, idx]
    """
    render_primitives = []
    n_vert = len(shape.vertices)
    if shape.shape_type in [

            SType.TRIANGLES, SType.TRIANGLE_STRIP, SType.TRIANGLE_FAN, SType.QUAD_STRIP]: