<commit_before>#coding: utf-8
#-----------------------------------------------------------------------------
# Copyright (c) 2014 <NAME>
# All rights reserved.
#-----------------------------------------------------------------------------

"""This module contains helper classes to draw basic shapes in pyglet"""

from __future__ import division

__docformat__ = 'restructuredtext'
__author__ = '<NAME>'

import pyglet
import math
from math import pi

class Shape(object):
    def __init__(self, color=('c3B', (255,255,255))):
        self.gl_type = None
        self.vertices = None
        self._color = color
        self.vertexlist = None

    def __del__(self):
        if self.vertexlist != None:
            self.vertexlist.delete()

    @property
    def color(self):
        return self._color

    @color.setter
    def color(self, value):
        if self.vertexlist is not None:
            # This will only work if the color is using the same number of
            # components
            self.vertexlist.colors[:] = value[1] * self.vertexlist.get_size()

        self._color = value

    def add_to_batch(self, batch):
        if self.vertexlist == None:
            n = len(self.vertices[1]) // 2
            self.vertexlist = batch.add(n, self.gl_type, None, self.vertices,
                                        (self.color[0], self.color[1] * n))
            return self.vertexlist
        else:
            print("This shape was already added to a Batch, please do not \
                    reuse.")

    def translate(self, tx, ty):
        res = [(v[0] + tx, v[1] + ty) for v in zip(self.vertices[1][::2],
                                                   self.vertices[1][1::2])]
        res = [x for v in res for x in v]
        return res


    
class Rect(Shape):
    def __init__(self, w, h, x=0, y=0, color=('c3B', (255,255,255))):
        Shape.__init__(self, color)
        
        w = w/2
        h = h/2
        x1 = x - w
        y1 = y + h
        x2 = x + w
        y2 = y - h
        
        self.gl_type = pyglet.gl.GL_QUADS
        self.vertices = ('v2f', (x1, y1, x2, y1, x2, y2, x1, y2))
        
class Line(Shape):
    def __init__(self, x1, y1, x2, y2, color = ('c3B', (255,255,255))):
        Shape.__init__(self, color)
        
        self.gl_type = pyglet.gl.GL_LINES
        self.vertices = ('v2f', (x1, y1, x2, y2))
        

class Triangle(Shape):
    def __init__(self, x1, y1, x2, y2, x3, y3, color = ('c3B', (255,255,255))):
        Shape.__init__(self, color)
        
        self.gl_type = pyglet.gl.GL_TRIANGLES
        self.vertices = ('v2f', (x1, y1, x2, y2, x3, y3))
        

class Circle(Shape):
    def __init__(self, r, cx = 0, cy = 0, color = ('c3B', (255,255,255))):
        Shape.__init__(self, color)
        
        self.gl_type = pyglet.gl.GL_TRIANGLES
        sides = int(pi*r)
        dang = 2*pi / sides
        ang = 0
        x = math.cos(ang) * r
        y = math.sin(ang) * r
        vertices = [0,0,r,0,x,y]
        for i in range(sides+1):
            x = math.cos(ang) * r
            y = math.sin(ang) * r
            vertices.extend([0,0,vertices[-2], vertices[-1],x,y])<commit_msg>Allow to change the resolution of the circle shape.<commit_after>#coding: utf-8
#-----------------------------------------------------------------------------
# Copyright (c) 2014 <NAME>
# All rights reserved.
#-----------------------------------------------------------------------------

"""This module contains helper classes to draw basic shapes in pyglet"""

from __future__ import division

__docformat__ = 'restructuredtext'
__author__ = '<NAME>'

import pyglet
import math
from math import pi

class Shape(object):
    def __init__(self, color=('c3B', (255,255,255))):
        self.gl_type = None
        self.vertices = None
        self._color = color
        self.vertexlist = None

    def __del__(self):
        if self.vertexlist != None:
            self.vertexlist.delete()

    @property
    def color(self):
        return self._color

    @color.setter
    def color(self, value):
        if self.vertexlist is not None:
            # This will only work if the color is using the same number of
            # components
            self.vertexlist.colors[:] = value[1] * self.vertexlist.get_size()

        self._color = value

    def add_to_batch(self, batch):
        if self.vertexlist == None:
            n = len(self.vertices[1]) // 2
            self.vertexlist = batch.add(n, self.gl_type, None, self.vertices,
                                        (self.color[0], self.color[1] * n))
            return self.vertexlist
        else:
            print("This shape was already added to a Batch, please do not \
                    reuse.")

    def translate(self, tx, ty):
        res = [(v[0] + tx, v[1] + ty) for v in zip(self.vertices[1][::2],
                                                   self.vertices[1][1::2])]
        res = [x for v in res for x in v]
        return res


    
class Rect(Shape):
    def __init__(self, w, h, x=0, y=0, color=('c3B', (255,255,255))):
        Shape.__init__(self, color)
        
        w = w/2
        h = h/2
        x1 = x - w
        y1 = y + h
        x2 = x + w
        y2 = y - h
        
        self.gl_type = pyglet.gl.GL_QUADS
        self.vertices = ('v2f', (x1, y1, x2, y1, x2, y2, x1, y2))
        
class Line(Shape):
    def __init__(self, x1, y1, x2, y2, color = ('c3B', (255,255,255))):
        Shape.__init__(self, color)
        
        self.gl_type = pyglet.gl.GL_LINES
        self.vertices = ('v2f', (x1, y1, x2, y2))
        

class Triangle(Shape):
    def __init__(self, x1, y1, x2, y2, x3, y3, color = ('c3B', (255,255,255))):
        Shape.__init__(self, color)
        
        self.gl_type = pyglet.gl.GL_TRIANGLES
        self.vertices = ('v2f', (x1, y1, x2, y2, x3, y3))
        

class Circle(Shape):
    def __init__(self, r, cx = 0, cy = 0, color = ('c3B', (255,255,255)),
                 res = 1):
        Shape.__init__(self, color)
        
        self.gl_type = pyglet.gl.GL_TRIANGLES
        sides = int(pi*r*res)
        dang = 2*pi / sides
        ang = 0
        x = math.cos(ang) * r
        y = math.sin(ang) * r
        vertices = [0,0,r,0,x,y]
        for i in range(sides+1):
            x = math.cos(ang) * r
            y = math.sin(ang) * r
            vertices.extend([0,0,vertices[-2], vertices[-1],x,y])
{'fraction_non_alphanumeric': 0.1764522173641474, 'fraction_numerical': 0.037008119925046844, 'mean_word_length': 1.5681635926222934, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2047141', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2105, 'n_words': 561}