Advertisement
Void-voiD

Untitled

Feb 25th, 2020
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.42 KB | None | 0 0
  1. import pyglet
  2. from pyglet.gl import *
  3. from pyglet.window import key
  4. import math
  5. import numpy as np
  6. from pyglet.window import mouse
  7. from random import randint
  8.  
  9.  
  10. window = pyglet.window.Window(900, 900, resizable = True)
  11. window.set_minimum_size(256, 144)
  12.  
  13. t = 100
  14. x = 50
  15.  
  16.  
  17. def PointsInCircum(r, n = 100, pi = 3.14):
  18.     return [(450 + math.cos(2 * pi / n * x) * r, 450 + math.sin(2 * pi / n * x) * r) for x in range(0, n + 1)]
  19.  
  20.  
  21. pts = np.array(PointsInCircum(t))
  22. frame = 0
  23.  
  24.  
  25. def update_frame(x, y):
  26.     global frame
  27.     if frame == None or frame == pts.shape[0] - 1:
  28.         frame = 0
  29.     else:
  30.         frame += 1
  31.  
  32.  
  33. @window.event
  34. def on_draw():
  35.  
  36.     offset = [[randint(0, x), randint(0, x)], [randint(0, x), randint(0, x)], [randint(0, x), randint(0, x)],
  37.               [randint(0, x), randint(0, x)],
  38.               [randint(0, x), randint(0, x)], [randint(0, x), randint(0, x)], [randint(0, x), randint(0, x)],
  39.               [randint(0, x), randint(0, x)]]
  40.    
  41.     glClear(GL_COLOR_BUFFER_BIT)
  42.  
  43.     glColor3f(randint(0, 255), randint(0, 255), randint(0, 255))
  44.  
  45.     glBegin(GL_LINES)
  46.  
  47.     glVertex2f(300 + offset[0][0] + pts[frame][0], 300 + offset[0][1] + pts[frame][1])
  48.     glVertex2f(250 + offset[1][0] + pts[frame][0], 450 + offset[1][1] + pts[frame][1])
  49.  
  50.     glVertex2f(250 + offset[1][0] + pts[frame][0], 450 + offset[1][1] + pts[frame][1])
  51.     glVertex2f(300 + offset[2][0] + pts[frame][0], 600 + offset[2][1] + pts[frame][1])
  52.  
  53.     glVertex2f(300 + offset[2][0] + pts[frame][0], 600 + offset[2][1] + pts[frame][1])
  54.     glVertex2f(450 + offset[3][0] + pts[frame][0], 650 + offset[3][1] + pts[frame][1])
  55.  
  56.     glVertex2f(450 + offset[3][0] + pts[frame][0], 650 + offset[3][1] + pts[frame][1])
  57.     glVertex2f(600 + offset[4][0] + pts[frame][0], 600 + offset[4][1] + pts[frame][1])
  58.  
  59.     glVertex2f(600 + offset[4][0] + pts[frame][0], 600 + offset[4][1] + pts[frame][1])
  60.     glVertex2f(650 + offset[5][0] + pts[frame][0], 450 + offset[5][1] + pts[frame][1])
  61.  
  62.     glVertex2f(650 + offset[5][0] + pts[frame][0], 450 + offset[5][1] + pts[frame][1])
  63.     glVertex2f(600 + offset[6][0] + pts[frame][0], 300 + offset[6][1] + pts[frame][1])
  64.  
  65.     glVertex2f(600 + offset[6][0] + pts[frame][0], 300 + offset[6][1] + pts[frame][1])
  66.     glVertex2f(450 + offset[7][0] + pts[frame][0], 250 + offset[7][1] + pts[frame][1])
  67.  
  68.     glVertex2f(450 + offset[7][0] + pts[frame][0], 250 + offset[7][1] + pts[frame][1])
  69.     glVertex2f(300 + offset[0][0] + pts[frame][0], 300 + offset[0][1] + pts[frame][1])
  70.  
  71.     glEnd()
  72.  
  73.  
  74. @window.event
  75. def on_resize(width, height):
  76.     glViewport(0, 0, width, height)
  77.  
  78.  
  79. @window.event
  80. def on_mouse_press(x, y, button, modifiers):
  81.     global t
  82.     global pts
  83.     if button == mouse.LEFT:
  84.         if t <= 200:
  85.             t += 10
  86.         pts = np.array(PointsInCircum(t))
  87.     elif button == mouse.RIGHT:
  88.         if t >= 10:
  89.             t -= 10
  90.         pts = np.array(PointsInCircum(t))
  91.  
  92.  
  93. @window.event
  94. def on_key_press(symbol, modifiers):
  95.     global x
  96.     if symbol == key.S:
  97.         glTranslatef(0, -64, 0)
  98.     elif symbol == key.W:
  99.         glTranslatef(0, 64, 0)
  100.     elif symbol == key.D:
  101.         glTranslatef(64, 0, 0)
  102.     elif symbol == key.A:
  103.         glTranslatef(-64, 0, 0)
  104.     elif symbol == key.LEFT:
  105.         if x >= 10:
  106.             x -= 10
  107.     elif symbol == key.RIGHT:
  108.         if x <= 150:
  109.             x += 10
  110.  
  111.  
  112. pyglet.clock.schedule(update_frame, 1 / 10.0)
  113. pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement