Ejemplo n.º 1
0
def test_rotate():
    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.rotate(np.pi/2)
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape.rotate(np.pi/4)
    assert shape == Shape.regular_polygon([0, 0], np.sqrt(2), 4)

    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.rotate(np.pi/2, [1, 1])
    assert shape == Shape.rectangle([[1, -1], [3, 1]])
Ejemplo n.º 2
0
Archivo: ui.py Proyecto: dennmat/maern
 def ns_switch_mode(self, new_mode):
     global mode_area, input_area
     self.mode = Modes.NormalSingle
     mode_label.text = 'Py Single'
     mode_label.y = 17
     input_area = Shape.rectangle([[100, 30], [window.width, 0]],
                                  color=(50, 50, 50))
     layout.y = 0
     layout.height = 25
     mode_area = Shape.rectangle([[0, 30], [100, 0]], color=(104, 209, 250))
Ejemplo n.º 3
0
Archivo: ui.py Proyecto: dennmat/maern
 def cm_switch_mode(self, new_node):
     global mode_area, input_area
     self.mode = Modes.CommandMode
     mode_label.text = '<CMD>'
     mode_label.y = 17
     input_area = Shape.rectangle([[100, 30], [window.width, 0]],
                                  color=(50, 50, 50))
     layout.y = 0
     layout.height = 25
     mode_area = Shape.rectangle([[0, 30], [100, 0]], color=(220, 89, 106))
Ejemplo n.º 4
0
def test_rotate():
    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.rotate(np.pi / 2)
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape.rotate(np.pi / 4)
    assert shape == Shape.regular_polygon([0, 0], np.sqrt(2), 4)

    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.rotate(np.pi / 2, [1, 1])
    assert shape == Shape.rectangle([[1, -1], [3, 1]])
Ejemplo n.º 5
0
Archivo: ui.py Proyecto: dennmat/maern
 def nm_switch_mode(self, new_mode):
     global mode_area, input_area
     self.mode = Modes.NormalMulti
     mode_label.text = 'Py Multi'
     mode_area = Shape.rectangle([[0, 130], [100, 100]],
                                 color=(209, 104, 250))
     mode_label.y = 117
     input_area = Shape.rectangle([[100, 130], [window.width, 0]],
                                  color=(50, 50, 50))
     layout.y = 0
     layout.height = 125
Ejemplo n.º 6
0
def test_scale():
    shape = Shape.circle([0, 0], 1)
    shape.scale(10)
    assert shape == Shape.circle([0, 0], 10)

    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.scale([2, 5])
    assert shape == Shape.rectangle([[-2, -5], [2, 5]])

    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.scale(2, center=[1, 1])
    assert shape == Shape.rectangle([[-3, -3], [1, 1]])
Ejemplo n.º 7
0
def test_scale():
    shape = Shape.circle([0, 0], 1)
    shape.scale(10)
    assert shape == Shape.circle([0, 0], 10)

    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.scale([2, 5])
    assert shape == Shape.rectangle([[-2, -5], [2, 5]])

    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.scale(2, center=[1, 1])
    assert shape == Shape.rectangle([[-3, -3], [1, 1]])
Ejemplo n.º 8
0
def test_rectangle():
    rect = Shape.rectangle([[-1, -1], [1, 1]])
    other_rect = Shape.regular_polygon([0, 0],
                                       np.sqrt(2),
                                       4,
                                       start_angle=np.pi / 4)
    assert rect == other_rect
Ejemplo n.º 9
0
Archivo: ui.py Proyecto: dennmat/maern
def on_resize(width, height):
    label.width = width
    label.y = height

    layout.width = width - 10

    input_area = Shape.rectangle([[100, 30], [window.width - 100, 0]],
                                 color=(50, 50, 50))
Ejemplo n.º 10
0
def test_in_place_arithmetic():
    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape += [10, 5]
    assert shape != Shape.rectangle([[-1, -1], [1, 1]])
    assert shape == Shape.rectangle([[9, 4], [11, 6]])
    shape -= [10, 5]
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape *= 10
    assert shape != Shape.rectangle([[-1, -1], [1, 1]])
    assert shape == Shape.rectangle([[-10, -10], [10, 10]])
    shape /= 10
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape *= [1, 5]
    assert shape != Shape.rectangle([[-1, -1], [1, 1]])
    assert shape == Shape.rectangle([[-1, -5], [1, 5]])
    shape /= [10, 1]
    assert shape == Shape.rectangle([[-0.1, -5], [0.1, 5]])
Ejemplo n.º 11
0
def test_in_place_arithmetic():
    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape += [10, 5]
    assert shape != Shape.rectangle([[-1, -1], [1, 1]])
    assert shape == Shape.rectangle([[9, 4], [11, 6]])
    shape -= [10, 5]
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape *= 10
    assert shape != Shape.rectangle([[-1, -1], [1, 1]])
    assert shape == Shape.rectangle([[-10, -10], [10, 10]])
    shape /= 10
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape *= [1, 5]
    assert shape != Shape.rectangle([[-1, -1], [1, 1]])
    assert shape == Shape.rectangle([[-1, -5], [1, 5]])
    shape /= [10, 1]
    assert shape == Shape.rectangle([[-0.1, -5], [0.1, 5]])
    def on_draw(self):
        self.clear()

        self.beatradius = int(self.width * 0.045 * 0.5)
        self.beaty = int(self.height - (self.beatradius * 2.5))

        self.barheight = int(self.height - (self.beatradius * 4))
        self.barwidth = int(self.width * 0.06)
        self.begin = int(self.barwidth * 0.5)

        shapes = []
        x = self.begin
        width = self.barwidth
        for bin in "bass", "mid", "tre":
            d = self.data["bins"][bin]
            level = int(d["level"] * self.barheight)
            flux =  int(d["flux"] * self.barheight)
            trans = int(d["transient"] * 255)

            if not self.data["silence"]:
                shapes.append(Shape.circle([x + self.beatradius, self.beaty],
                    self.beatradius, color=(0, trans, 0)))

            shapes.append(
                Shape.rectangle([(x, 0), (x+width, level)], color=(255, 0, 0)))
            x += width
            shapes.append(
                Shape.rectangle([(x, 0), (x+width, flux)], color=(255, 128, 0)))
            x += int(width * 1.5)

        x += self.barwidth
        width = int((self.width - x) / (len(self.data["spectrum"]) + 1))
        g = 0
        for level in self.data["spectrum"]:
            level = int(level * self.barheight)

            shapes.append(
                Shape.rectangle([(x, 0), (x+width, level)], color=(0, g, 255)))
            g = min(g + 20, 255)
            x += width

        for shape in shapes:
            shape.draw()
Ejemplo n.º 13
0
def test_enable_disable():
    shape = Shape.rectangle([[-1, -1], [1, 1]], color=(100, 100, 100))
    shape.enable(False)
    shape.draw()
    assert not shape._vertex_list.draw.called
    shape.enable(True)
    shape.draw()
    assert shape._vertex_list.draw.call_count == 1
    call_args = shape._vertex_list.draw.call_args
    assert len(call_args[0]) == 1
    gl_triangles = call_args[0][0]
    assert isinstance(gl_triangles, Mock)
Ejemplo n.º 14
0
def test_enable_disable():
    shape = Shape.rectangle([[-1, -1], [1, 1]], color=(100, 100, 100))
    shape.enable(False)
    shape.draw()
    assert not shape._vertex_list.draw.called
    shape.enable(True)
    shape.draw()
    assert shape._vertex_list.draw.call_count == 1
    call_args = shape._vertex_list.draw.call_args
    assert len(call_args[0]) == 1
    gl_triangles = call_args[0][0]
    assert isinstance(gl_triangles, Mock)
Ejemplo n.º 15
0
def test_vertex_list():
    shape = Shape.rectangle([[-1, -1], [1, 1]], color=(100, 100, 100))
    indices = [0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 1]
    vertices = [0, 0, -1, -1, 1, -1, 1, 1, -1, 1],
    colors = 5 * [100, 100, 100]

    args = shape._vertex_list.args
    assert len(args) == 4
    assert args[0] == 5
    assert args[1] == indices
    assert args[2][0] == 'v2f'
    assert np.all(np.isclose(args[2][1], vertices))
    assert args[3][0] == 'c3B'
    assert np.all(np.isclose(args[3][1], colors))
Ejemplo n.º 16
0
def test_flip():
    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.flip_x()
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape.flip_y()
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])

    shape.flip_x([1, 0])
    assert shape == Shape.rectangle([[1, -1], [3, 1]])

    shape.flip_y([0, 1])
    assert shape == Shape.rectangle([[1, 1], [3, 3]])

    shape -= [2, 2]
    shape.flip(np.pi / 4)
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape.flip(np.pi / 4, center=[-1, 1])
    assert shape == Shape.rectangle([[-3, 1], [-1, 3]])
Ejemplo n.º 17
0
def test_flip():
    shape = Shape.rectangle([[-1, -1], [1, 1]])
    shape.flip_x()
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape.flip_y()
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])

    shape.flip_x([1, 0])
    assert shape == Shape.rectangle([[1, -1], [3, 1]])

    shape.flip_y([0, 1])
    assert shape == Shape.rectangle([[1, 1], [3, 3]])

    shape -= [2, 2]
    shape.flip(np.pi/4)
    assert shape == Shape.rectangle([[-1, -1], [1, 1]])
    shape.flip(np.pi/4, center=[-1, 1])
    assert shape == Shape.rectangle([[-3, 1], [-1, 3]])
Ejemplo n.º 18
0
def test_vertex_list():
    shape = Shape.rectangle([[-1, -1], [1, 1]], color=(100, 100, 100))
    indices = [0, 1, 2,
               0, 2, 3,
               0, 3, 4,
               0, 4, 1]
    vertices = [0, 0,
                -1, -1,
                1, -1,
                1, 1,
                -1, 1],
    colors = 5 * [100, 100, 100]

    args = shape._vertex_list.args
    assert len(args) == 4
    assert args[0] == 5
    assert args[1] == indices
    assert args[2][0] == 'v2f'
    assert np.all(np.isclose(args[2][1], vertices))
    assert args[3][0] == 'c3B'
    assert np.all(np.isclose(args[3][1], colors))
Ejemplo n.º 19
0
def test_rectangle_from_dict():
    spec = {
        'vertices': [[-1, -1],
                     [1, 1]],
    }
    assert Shape.from_dict(spec) == Shape.rectangle(spec['vertices'])
Ejemplo n.º 20
0
def test_rectangle():
    rect = Shape.rectangle([[-1, -1], [1, 1]])
    other_rect = Shape.regular_polygon([0, 0], np.sqrt(2), 4, start_angle=np.pi/4)
    assert rect == other_rect
Ejemplo n.º 21
0
Archivo: ui.py Proyecto: dennmat/maern
from pyglet2d import Shape

window = pyglet.window.Window(1024, 768, resizable=True)

label = pyglet.text.Label('Hello, world',
                          font_name='Consolas',
                          font_size=12,
                          x=0,
                          y=window.height,
                          multiline=True,
                          width=window.width,
                          anchor_x='left',
                          anchor_y='top')

input_area = Shape.rectangle([[100, 30], [window.width, 0]],
                             color=(50, 50, 50))
mode_area = Shape.rectangle([[0, 30], [100, 0]], color=(104, 209, 250))
text_input = pyglet.text.Label()

mode_label = pyglet.text.Label('Py Mixed',
                               font_name='Consolas',
                               font_size=12,
                               x=50,
                               y=17,
                               anchor_x='center',
                               anchor_y='center',
                               bold=True,
                               color=(20, 40, 150, 255))

cwd_label = pyglet.text.Label('',
                              font_name='Consolas',
Ejemplo n.º 22
0
def test_center():
    shape = Shape.rectangle([[-1, -1], [1, 1]])
    assert np.all(np.isclose(shape.center, [0, 0]))
    shape.center = [1, 1]
    assert shape == Shape.rectangle([[0, 0], [2, 2]])
Ejemplo n.º 23
0
def test_xor():
    assert Shape.rectangle([[-1, 0], [0, 1]]) ^ Shape.rectangle([[0, 0], [1, 1]]) == Shape.rectangle([[-1, 0], [1, 1]])
    assert ((Shape.rectangle([[-1, 0], [0.5, 1]]) ^ Shape.rectangle([[-0.5, 0], [1, 1]])) ==
            (Shape.rectangle([[-1, 0], [1, 1]])) - Shape.rectangle([[-0.5, 0], [0.5, 1]]))
Ejemplo n.º 24
0
def test_difference():
    assert Shape.rectangle([[-1, 0], [1, 3]]) - Shape.rectangle([[0, 0], [2, 3]]) == Shape.rectangle([[-1, 0], [0, 3]])
Ejemplo n.º 25
0
def test_intersection():
    assert Shape.rectangle([[-1, 0], [1, 2]]) & Shape.rectangle([[0, 0], [1, 1]]) == Shape.rectangle([[0, 0], [1, 1]])
Ejemplo n.º 26
0
def test_union():
    assert (Shape.rectangle([[-1, 0], [0, 1]]) | Shape.rectangle([[0, 0], [1, 1]]) ==
            Shape.rectangle([[-1, 0], [0, 1]]) + Shape.rectangle([[0, 0], [1, 1]]) ==
            Shape.rectangle([[-1, 0], [1, 1]]))
Ejemplo n.º 27
0
def test_rectangle_from_dict():
    spec = {
        'vertices': [[-1, -1], [1, 1]],
    }
    assert Shape.from_dict(spec) == Shape.rectangle(spec['vertices'])
Ejemplo n.º 28
0
def test_union():
    assert (
        Shape.rectangle([[-1, 0], [0, 1]]) | Shape.rectangle([[0, 0], [1, 1]])
        ==
        Shape.rectangle([[-1, 0], [0, 1]]) + Shape.rectangle([[0, 0], [1, 1]])
        == Shape.rectangle([[-1, 0], [1, 1]]))
Ejemplo n.º 29
0
def test_intersection():
    assert Shape.rectangle([[-1, 0], [1, 2]]) & Shape.rectangle(
        [[0, 0], [1, 1]]) == Shape.rectangle([[0, 0], [1, 1]])
Ejemplo n.º 30
0
def test_difference():
    assert Shape.rectangle([[-1, 0], [1, 3]]) - Shape.rectangle(
        [[0, 0], [2, 3]]) == Shape.rectangle([[-1, 0], [0, 3]])
Ejemplo n.º 31
0
def test_xor():
    assert Shape.rectangle([[-1, 0], [0, 1]]) ^ Shape.rectangle(
        [[0, 0], [1, 1]]) == Shape.rectangle([[-1, 0], [1, 1]])
    assert ((Shape.rectangle([[-1, 0], [0.5, 1]]) ^ Shape.rectangle(
        [[-0.5, 0], [1, 1]])) == (Shape.rectangle([[-1, 0], [1, 1]])) -
            Shape.rectangle([[-0.5, 0], [0.5, 1]]))
Ejemplo n.º 32
0
def test_center():
    shape = Shape.rectangle([[-1, -1], [1, 1]])
    assert np.all(np.isclose(shape.center, [0, 0]))
    shape.center = [1, 1]
    assert shape == Shape.rectangle([[0, 0], [2, 2]])