Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyglet
- from pyglet.gl import *
- from pyglet.window import key
- import math
- import numpy as np
- from pyglet.window import mouse
- from random import randint
- window = pyglet.window.Window(900, 900, resizable = True)
- window.set_minimum_size(256, 144)
- t = 100
- x = 50
- def PointsInCircum(r, n = 100, pi = 3.14):
- return [(450 + math.cos(2 * pi / n * x) * r, 450 + math.sin(2 * pi / n * x) * r) for x in range(0, n + 1)]
- pts = np.array(PointsInCircum(t))
- frame = 0
- def update_frame(x, y):
- global frame
- if frame == None or frame == pts.shape[0] - 1:
- frame = 0
- else:
- frame += 1
- @window.event
- def on_draw():
- offset = [[randint(0, x), randint(0, x)], [randint(0, x), randint(0, x)], [randint(0, x), randint(0, x)],
- [randint(0, x), randint(0, x)],
- [randint(0, x), randint(0, x)], [randint(0, x), randint(0, x)], [randint(0, x), randint(0, x)],
- [randint(0, x), randint(0, x)]]
- glClear(GL_COLOR_BUFFER_BIT)
- glColor3f(randint(0, 255), randint(0, 255), randint(0, 255))
- glBegin(GL_LINES)
- glVertex2f(300 + offset[0][0] + pts[frame][0], 300 + offset[0][1] + pts[frame][1])
- glVertex2f(250 + offset[1][0] + pts[frame][0], 450 + offset[1][1] + pts[frame][1])
- glVertex2f(250 + offset[1][0] + pts[frame][0], 450 + offset[1][1] + pts[frame][1])
- glVertex2f(300 + offset[2][0] + pts[frame][0], 600 + offset[2][1] + pts[frame][1])
- glVertex2f(300 + offset[2][0] + pts[frame][0], 600 + offset[2][1] + pts[frame][1])
- glVertex2f(450 + offset[3][0] + pts[frame][0], 650 + offset[3][1] + pts[frame][1])
- glVertex2f(450 + offset[3][0] + pts[frame][0], 650 + offset[3][1] + pts[frame][1])
- glVertex2f(600 + offset[4][0] + pts[frame][0], 600 + offset[4][1] + pts[frame][1])
- glVertex2f(600 + offset[4][0] + pts[frame][0], 600 + offset[4][1] + pts[frame][1])
- glVertex2f(650 + offset[5][0] + pts[frame][0], 450 + offset[5][1] + pts[frame][1])
- glVertex2f(650 + offset[5][0] + pts[frame][0], 450 + offset[5][1] + pts[frame][1])
- glVertex2f(600 + offset[6][0] + pts[frame][0], 300 + offset[6][1] + pts[frame][1])
- glVertex2f(600 + offset[6][0] + pts[frame][0], 300 + offset[6][1] + pts[frame][1])
- glVertex2f(450 + offset[7][0] + pts[frame][0], 250 + offset[7][1] + pts[frame][1])
- glVertex2f(450 + offset[7][0] + pts[frame][0], 250 + offset[7][1] + pts[frame][1])
- glVertex2f(300 + offset[0][0] + pts[frame][0], 300 + offset[0][1] + pts[frame][1])
- glEnd()
- @window.event
- def on_resize(width, height):
- glViewport(0, 0, width, height)
- @window.event
- def on_mouse_press(x, y, button, modifiers):
- global t
- global pts
- if button == mouse.LEFT:
- if t <= 200:
- t += 10
- pts = np.array(PointsInCircum(t))
- elif button == mouse.RIGHT:
- if t >= 10:
- t -= 10
- pts = np.array(PointsInCircum(t))
- @window.event
- def on_key_press(symbol, modifiers):
- global x
- if symbol == key.S:
- glTranslatef(0, -64, 0)
- elif symbol == key.W:
- glTranslatef(0, 64, 0)
- elif symbol == key.D:
- glTranslatef(64, 0, 0)
- elif symbol == key.A:
- glTranslatef(-64, 0, 0)
- elif symbol == key.LEFT:
- if x >= 10:
- x -= 10
- elif symbol == key.RIGHT:
- if x <= 150:
- x += 10
- pyglet.clock.schedule(update_frame, 1 / 10.0)
- pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement