Skip to content

Instantly share code, notes, and snippets.

@pydsigner
Created October 10, 2012 02:02
Show Gist options
  • Save pydsigner/3862722 to your computer and use it in GitHub Desktop.
Save pydsigner/3862722 to your computer and use it in GitHub Desktop.
Rotating a Red Box in Pyglet
import pyglet
CYCLE = 30.
def degrees_from_time(t):
"""
Get the degrees to rotate, which is:
percentage_of_cycle_complete = time_elapsed_in_cycle / cycle_length
degrees_to_rotate = percentage_of_cycle_complete * 360
"""
t = t % CYCLE
return t / CYCLE * 360
def main():
global time_elapsed
box_img = pyglet.image.load('red-box-200.png')
box = pyglet.sprite.Sprite(box_img, x=100, y=100)
window = pyglet.window.Window()
pyglet.clock.set_fps_limit(60)
time_elapsed = 0
@window.event
def on_draw():
global time_elapsed
time_elapsed += pyglet.clock.tick()
print time_elapsed
box.rotation = degrees_from_time(time_elapsed)
box.draw()
pyglet.app.run()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment