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
- from pyglet.window import mouse
- from random import randint
- window = pyglet.window.Window(900, 600, resizable=True)
- window.set_minimum_size(200, 100)
- colorStatus = 0
- #batch = pyglet.graphics.Batch()
- #hexo = batch.add(6, pyglet.gl.GL_POLYGON, None, ('v2i', (300, 300, 375, 175, 525, 175, 600, 300, 525, 425, 375, 425)),
- #('c3B', (0, 0, 20, 11, 107, 85, 50, 0, 115, 127, 4, 4, 20, 1, 1, 0, 12, 17)))
- @window.event
- def on_draw():
- #window.clear()
- #batch.draw()
- if colorStatus == 0:
- glColor3b(randint(0, 255), randint(0, 255), randint(0, 255))
- elif colorStatus != 0:
- glColor3b(randint(0, 255), randint(0, 255), randint(0, 255))
- glClear(GL_COLOR_BUFFER_BIT)
- glBegin(GL_POLYGON)
- glVertex2f(300, 300)
- glVertex2f(375, 175)
- glVertex2f(525, 175)
- glVertex2f(600, 300)
- glVertex2f(525, 425)
- glVertex2f(375, 425)
- glEnd()
- @window.event
- def on_resize(width, height):
- glViewport(0, 0, width, height)
- #@window.event
- #def on_mouse_press(x, y, button, modifiers):
- #if button == mouse.LEFT:
- #hexo.delete()
- #batch.add(6, pyglet.gl.GL_POLYGON, None, ('v2i', (300, 300, 375, 175, 525, 175, 600, 300, 525, 425, 375, 425)),
- #('c3B', (0, 0, 25, 11, 107, 85, 50, 0, 15, 127, 4, 4, 20, 130, 1, 0, 12, 17)))
- @window.event
- def on_mouse_press(x, y, button, modifiers):
- global colorStatus
- if button == mouse.LEFT:
- colorStatus += 1
- @window.event
- def on_key_press(symbol, modifiers):
- if (symbol == key.RIGHT) | (symbol == key.D):
- glTranslatef(100, 0, 0)
- elif (symbol == key.LEFT) | (symbol == key.A):
- glTranslatef(-100, 0, 0)
- elif (symbol == key.UP) | (symbol == key.W):
- glTranslatef(0, 100, 0)
- elif (symbol == key.DOWN) | (symbol == key.S):
- glTranslatef(0, - 100, 0)
- pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement