• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# pygame animation code. don't laugh.

a guest Dec 9th, 2012 304 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import pickle, sys
2. import pygame
3. from pygame.locals import *
4. from time import sleep
5. from math import sin, cos, pi, sqrt
6.
7. vial = open('dat/cash_timeline.dat','r')
9. vial.close()
10.
11. vial = open('dat/flux_timeline.dat','r')
13. vial.close()
14.
15.
16. centerx, centery = 300,300#of the megacircle
17. radius = 175#of the megacircle
18. kay = 85**2/6855.#chips to radius conversion
19.
20. if True:#define colors
21.
22.         red = pygame.Color('#FF486C')
23.         orange = pygame.Color('#FF7148')
24.         yellow = pygame.Color('#FFF748')
25.         green = pygame.Color('#95FF48')
26.         blue = pygame.Color('#48C9FF')
27.         violet = pygame.Color('#486CFF')
28.         grey = pygame.Color('#A3A3A3')
29.         graph = pygame.Color('#3A3A3A')
30.         black = pygame.Color(0,0,0)
31.         white = pygame.Color(255,255,255)#Color definition
32.         colors=[red, orange, yellow, green, blue, violet, grey]
33.
34. allPlayers = ['Brontosaur', 'Mongoose', 'Aardvark', 'FruitBat', 'MantaRay', 'Tapeworm', 'Ebola']#all together now!
35.
36. def arr(x):#given x chips, calculate the radius of the circle;
37.         return int(sqrt(kay*x))#holdings proportional to area
38. def winner():#who wins the tournament?
39.         for player in allPlayers:
40.                 if flux[player][hand] > 0:
41.                         return player
42.
43. color_dict = {}
44. place_dict = {}
45. for i in range(0, len(allPlayers)):#give each player a color and a location.
46.         color_dict[allPlayers[i]] = colors[i]#colors for everyone!
48.
49.
50. pygame.init()
51.
52. windowSurfObj = pygame.display.set_mode([700,700])
53. pygame.display.set_caption('Poker Face')
54. fontObj = pygame.font.Font('freesansbold.ttf', 24)
55.
56.
57. hand=0#slight abuse of notation; counter to iterate thru time series
58. while hand < 675:
59.         windowSurfObj.fill(white)
60.         win = winner()
61.
62.         for playa in allPlayers:#draw your lines in the sand...
63.                 if flux[playa][hand] < 0.0:
64.                         wid = arr(abs(flux[playa][hand]))#does this correctly represent flow? ie, is area ~ flux? oh wellz...
65.                         pygame.draw.line(windowSurfObj, black, place_dict[playa], place_dict[win], wid)
66.
67.         for playa in allPlayers:#circleround.
69.                 pygame.draw.circle(windowSurfObj, color_dict[playa], place_dict[playa], rad)#draw circles.
70.
71.         for playa in allPlayers:#his name was robert paulson.
72.                 msgSurfObj = fontObj.render(playa, False, graph)
73.                 msgRectObj = msgSurfObj.get_rect()
74.                 msgRectObj.topleft = place_dict[playa]
75.                 windowSurfObj.blit(msgSurfObj, msgRectObj)
76.
77.         for event in pygame.event.get():#event.get calls up all the events that have happened since the last time get was called.
78.                 if event.type == QUIT:#GTFO
79.                         pygame.quit()
80.                         sys.exit()
81.                 elif event.type == KEYDOWN:#interact with the keyboard
82.                         if event.key == K_ESCAPE:
83.                                 pygame.event.post(pygame.event.Event(QUIT))#GTFO
84.
85.         pygame.display.update()#update the display!
86.         pygame.image.save(windowSurfObj, 'frm/frame%d.jpeg'%(hand))
87.
88.         hand += 1#animate
89.         #sleep(0.07)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top