Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/devtools/CompleteTestKit/to-do/Animation Styles/AnimTestMod.py
blob: 2626357d7098596e576a684798aaa7d38c9af5e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
from AnimatedSprite import Spritesheet, AnimatedSprite
import sys, pygame, time
pygame.init()

print "Full Test - Authors Dave Silverman and Scott Mengel"
print "Set size to 600 x 400 px"
print "Running..."

#--------------------------------------------------------------
#CONSTANTS AND VARIABLES

make=input("How many instances of each animation would you like to load? ")
img={}
ft="" #filetype
r=0 #frame refreshes
i=1 #cycles images
size = width, height = 600,400 #screen sizes
t=0 #trial number

#These are arrays of file types and paths to the corresponding folders so that later I can just iterate through this array and grab 
#the path my images are in and the file type of the images in that folder. We have one array for each type of sprite sheet that we are testing.
AnimPerLineArr=[ ["bmp","AnimationPerLine/bmp16/"] , ["bmp","AnimationPerLine/bmp24/"] , ["gif","AnimationPerLine/gif/"] , ["gif","AnimationPerLine/gift/"] , ["png","AnimationPerLine/png/"] , ["png","AnimationPerLine/pngt/"] ]
OneSheetArr=[ ["bmp","OneSheetPerAnimation/bmp16/"] , ["bmp","OneSheetPerAnimation/bmp24/"] , ["gif","OneSheetPerAnimation/gif/"] , ["gif","OneSheetPerAnimation/gift/"] , ["png","OneSheetPerAnimation/png/"] , ["png","OneSheetPerAnimation/pngt/"] ]
IndivFrameArr=[ ["bmp","IndividualFrames/bmp16/"] , ["bmp","IndividualFrames/bmp24/"] , ["gif","IndividualFrames/gif/"] , ["gif","IndividualFrames/gift/"] , ["png","IndividualFrames/png/"] , ["png","IndividualFrames/pngt/"] ]

screen = pygame.display.set_mode(size) #Screen Set 600x400
backgroundR = 152
backgroundG = 0
backgroundB = 152
screen.fill((backgroundR, backgroundG, backgroundB))#setting the background color to purple.
#-----------------------------------------------------------------
#Reading Individual Frames

def readIndivFrames(fileType, path):
# This definition is used to read in the images that each only have one frame of animation on them and to display their animations

 #This list holds the frames for the first animation
 images1 = [
  [pygame.image.load("%sa1/1.%s"%(path,fileType))],
  [pygame.image.load("%sa1/2.%s"%(path,fileType))],
  [pygame.image.load("%sa1/3.%s"%(path,fileType))],
  [pygame.image.load("%sa1/4.%s"%(path,fileType))],
  [pygame.image.load("%sa1/5.%s"%(path,fileType))],
  [pygame.image.load("%sa1/6.%s"%(path,fileType))],
  [pygame.image.load("%sa1/7.%s"%(path,fileType))],
  [pygame.image.load("%sa1/8.%s"%(path,fileType))],
  [pygame.image.load("%sa1/9.%s"%(path,fileType))]
 ]

 #This list holds the frames for the second animation.
 images2 = [
  [pygame.image.load("%sa2/1.%s"%(path,fileType))],
  [pygame.image.load("%sa2/2.%s"%(path,fileType))],
  [pygame.image.load("%sa2/3.%s"%(path,fileType))],
  [pygame.image.load("%sa2/4.%s"%(path,fileType))],
  [pygame.image.load("%sa2/5.%s"%(path,fileType))],
  [pygame.image.load("%sa2/6.%s"%(path,fileType))],
  [pygame.image.load("%sa2/7.%s"%(path,fileType))],
  [pygame.image.load("%sa2/8.%s"%(path,fileType))],
  [pygame.image.load("%sa2/9.%s"%(path,fileType))]
 ]
 
 #instances is an array of all the instances of each of the two animations.
 instances = []

 #cnt represents how many times both animations need to be made
 cnt = make
 while cnt > 0:
  #animatedSprites is a list that hads two valuse in it. One for the first animation and one for the second animation.
  animatedSprites = []
  #Each position in animatedSprites contains a list that has an actual animatedSprite object, and a list that contains all of that animatedSprite
  #object's position and speed values
  animatedSprites.append([AnimatedSprite(images1,'',10),[(40*cnt),0,2,2]])

  animatedSprites.append([AnimatedSprite(images2,'',10),[(40*cnt),40,2,2]])

  #Adds the animatedSprites list to the instances list.
  instances.append(animatedSprites)

  #Increments the cnt object
  cnt = cnt - 1

 #trials represents the number of trials that is perfor,ed for each test.
 trials = 0
 while trials < 5:

  #This loop is used to go through to the deepest level of this list and modify the positions of each set of animations so that they
  #are not all directly on top of each other.
  groups = len(instances) - 1
  while groups >= 0:
   instances[groups][0][1][0] = 40 * groups
   instances[groups][0][1][1] = 0
   instances[groups][1][1][0] = 40 * groups
   instances[groups][1][1][1] = 40
   groups = groups - 1

  #changes is a variable that is used to track how many frames have rendered.
  changes = 0
  #start represents the time the test starts
  start = time.time()
  #This is the loop that goes through until 500 frames have passed
  while changes < 500:
   #This loop goes through the first level of the instances list so that every group of animations is updated
   groups = len(instances) - 1
   while groups >= 0:
    instances[groups][0][0].nextFrame()
    instances[groups][1][0].nextFrame()

    #These two ifs are used to check if the first animation is off screen and adjust its velocity if it is so that it will come back
    if instances[groups][0][1][0] < 0 or instances[groups][0][1][0] > width - 40:
       instances[groups][0][1][2] = instances[groups][0][1][2] * -1
       
    if instances[groups][0][1][1] < 0 or instances[groups][0][1][1] > height - 40:
       instances[groups][0][1][3] = instances[groups][0][1][3] * -1
       
    #These two ifs are used to check if the second animation is off screen and adjust its velocity if it is so that it will come back
    if instances[groups][1][1][0] < 0 or instances[groups][1][1][0] > width - 40:
       instances[groups][1][1][2] = instances[groups][1][1][2] * -1
       
    if instances[groups][1][1][1] < 0 or instances[groups][1][1][1] > height - 40:
       instances[groups][1][1][3] = instances[groups][1][1][3] * -1
     

    #These two statements update the position of the first animation based on its velocity
    instances[groups][0][1][0] += instances[groups][0][1][2]
    instances[groups][0][1][1] += instances[groups][0][1][3]

    #These two statements update the position of the second animation based on its velocity
    instances[groups][1][1][0] += instances[groups][1][1][2]
    instances[groups][1][1][1] += instances[groups][1][1][3]

    #blits the new position of both animations
    screen.blit(instances[groups][0][0].image[0], (instances[groups][0][0].image[0].get_rect().move(instances[groups][0][1][0], instances[groups][0][1][1])))
    screen.blit(instances[groups][1][0].image[0], (instances[groups][1][0].image[0].get_rect().move(instances[groups][1][1][0], instances[groups][1][1][1])))

    #iterates group object to next one to update
    groups = groups - 1
   #flips the display so that the new frames show up
   pygame.display.flip()
   #fills the screen with the background coor
   screen.fill((backgroundR,backgroundG,backgroundB))
   #iterates the changes object
   changes = changes + 1
  #iterates the trials object
  trials = trials + 1
  #prints what trial we are on and the frame rate.
  print(trials)
  print(1/((time.time() -start)/500))

#-----------------------------------------------------------------

def readPerLine(fileType, path):

 spriteSheet1 = Spritesheet(("%sButtons.%s"%(path,fileType)))

 instances= []

 cnt = make
 while cnt > 0:
  animatedSprites = []
  animatedSprites.append([AnimatedSprite(spriteSheet1.img_extract(9,2,40,40),("%stext.txt"%(path)),10),[(40*cnt),0,2,2]])

  animatedSprites.append([AnimatedSprite(spriteSheet1.img_extract(9,2,40,40),("%stext.txt"%(path)),10),[(40*cnt),40,2,2]])

  instances.append(animatedSprites)

  cnt = cnt - 1

 #trials represents the number of trials that is perfor,ed for each test.
 trials = 0
 while trials < 5:

  #This loop is used to go through to the deepest level of this list and modify the positions of each set of animations so that they
  #are not all directly on top of each other.
  groups = len(instances) - 1
  while groups >= 0:
   instances[groups][0][1][0] = 40 * groups
   instances[groups][0][1][1] = 0
   instances[groups][1][1][0] = 40 * groups
   instances[groups][1][1][1] = 40
   groups = groups - 1

  #changes is a variable that is used to track how many frames have rendered.
  changes = 0
  #start represents the time the test starts
  start = time.time()
  #This is the loop that goes through until 500 frames have passed
  while changes < 500:
   #This loop goes through the first level of the instances list so that every group of animations is updated
   groups = len(instances) - 1
   while groups >= 0:
    instances[groups][0][0].nextFrame()
    instances[groups][1][0].nextFrame()

    #These two ifs are used to check if the first animation is off screen and adjust its velocity if it is so that it will come back
    if instances[groups][0][1][0] < 0 or instances[groups][0][1][0] > width - 40:
       instances[groups][0][1][2] = instances[groups][0][1][2] * -1
       
    if instances[groups][0][1][1] < 0 or instances[groups][0][1][1] > height - 40:
       instances[groups][0][1][3] = instances[groups][0][1][3] * -1
       
    #These two ifs are used to check if the second animation is off screen and adjust its velocity if it is so that it will come back
    if instances[groups][1][1][0] < 0 or instances[groups][1][1][0] > width - 40:
       instances[groups][1][1][2] = instances[groups][1][1][2] * -1
       
    if instances[groups][1][1][1] < 0 or instances[groups][1][1][1] > height - 40:
       instances[groups][1][1][3] = instances[groups][1][1][3] * -1
     

    #These two statements update the position of the first animation based on its velocity
    instances[groups][0][1][0] += instances[groups][0][1][2]
    instances[groups][0][1][1] += instances[groups][0][1][3]

    #These two statements update the position of the second animation based on its velocity
    instances[groups][1][1][0] += instances[groups][1][1][2]
    instances[groups][1][1][1] += instances[groups][1][1][3]

    #blits the new position of both animations
    screen.blit(instances[groups][0][0].image, (instances[groups][0][0].image.get_rect().move(instances[groups][0][1][0], instances[groups][0][1][1])))
    screen.blit(instances[groups][1][0].image, (instances[groups][1][0].image.get_rect().move(instances[groups][1][1][0], instances[groups][1][1][1])))

    #iterates group object to next one to update
    groups = groups - 1
   #flips the display so that the new frames show up
   pygame.display.flip()
   #fills the screen with the background coor
   screen.fill((backgroundR,backgroundG,backgroundB))
   #iterates the changes object
   changes = changes + 1
  #iterates the trials object
  trials = trials + 1
  #prints what trial we are on and the frame rate.
  print(trials)
  print(1/((time.time() -start)/500))

#-----------------------------------------------------------------
def readIndivSheet(fileType, path):

 #creates instances of the spritesheet object witht he given sprite sheet images
 spriteSheet1 = Spritesheet(("%s1.%s"%(path,fileType)))
 spriteSheet2 = Spritesheet(("%s2.%s"%(path,fileType)))
 
 instances= []

 #Increments the cnt object
 cnt = make
 while cnt > 0:
  #animatedSprites is a list that hads two valuse in it. One for the first animation and one for the second animation.
  animatedSprites = []

  animatedSprites.append([AnimatedSprite(spriteSheet1.img_extract(9,1,40,40),("%stext.txt"%(path)),10),[(40*cnt),0,2,2]])
  animatedSprites[0][0].addImages(spriteSheet2.img_extract(9,1,40,40))

  animatedSprites.append([AnimatedSprite(spriteSheet1.img_extract(9,1,40,40),("%stext.txt"%(path)),10),[(40*cnt),40,2,2]])
  animatedSprites[1][0].addImages(spriteSheet2.img_extract(9,1,40,40))

  instances.append(animatedSprites)

  cnt = cnt - 1

 #trials represents the number of trials that is perfor,ed for each test.
 trials = 0
 while trials < 5:

  #This loop is used to go through to the deepest level of this list and modify the positions of each set of animations so that they
  #are not all directly on top of each other.
  groups = len(instances) - 1
  while groups >= 0:
   instances[groups][0][1][0] = 40 * groups
   instances[groups][0][1][1] = 0
   instances[groups][1][1][0] = 40 * groups
   instances[groups][1][1][1] = 40
   groups = groups - 1

  #changes is a variable that is used to track how many frames have rendered.
  changes = 0
  #start represents the time the test starts
  start = time.time()
  #This is the loop that goes through until 500 frames have passed
  while changes < 500:
   #This loop goes through the first level of the instances list so that every group of animations is updated
   groups = len(instances) - 1
   while groups >= 0:
    instances[groups][0][0].nextFrame()
    instances[groups][1][0].nextFrame()

    #These two ifs are used to check if the first animation is off screen and adjust its velocity if it is so that it will come back
    if instances[groups][0][1][0] < 0 or instances[groups][0][1][0] > width - 40:
       instances[groups][0][1][2] = instances[groups][0][1][2] * -1
       
    if instances[groups][0][1][1] < 0 or instances[groups][0][1][1] > height - 40:
       instances[groups][0][1][3] = instances[groups][0][1][3] * -1
       
    #These two ifs are used to check if the second animation is off screen and adjust its velocity if it is so that it will come back
    if instances[groups][1][1][0] < 0 or instances[groups][1][1][0] > width - 40:
       instances[groups][1][1][2] = instances[groups][1][1][2] * -1
       
    if instances[groups][1][1][1] < 0 or instances[groups][1][1][1] > height - 40:
       instances[groups][1][1][3] = instances[groups][1][1][3] * -1
     

    #These two statements update the position of the first animation based on its velocity
    instances[groups][0][1][0] += instances[groups][0][1][2]
    instances[groups][0][1][1] += instances[groups][0][1][3]

    #These two statements update the position of the second animation based on its velocity
    instances[groups][1][1][0] += instances[groups][1][1][2]
    instances[groups][1][1][1] += instances[groups][1][1][3]

    #blits the new position of both animations
    screen.blit(instances[groups][0][0].image, (instances[groups][0][0].image.get_rect().move(instances[groups][0][1][0], instances[groups][0][1][1])))
    screen.blit(instances[groups][1][0].image, (instances[groups][1][0].image.get_rect().move(instances[groups][1][1][0], instances[groups][1][1][1])))

    #iterates group object to next one to update
    groups = groups - 1
   #flips the display so that the new frames show up
   pygame.display.flip()
   #fills the screen with the background coor
   screen.fill((backgroundR,backgroundG,backgroundB))
   #iterates the changes object
   changes = changes + 1
  #iterates the trials object
  trials = trials + 1
  #prints what trial we are on and the frame rate.
  print(trials)
  print(1/((time.time() -start)/500))


#-----------------------------------------------------------------
iterator = 0
print""
print "Testing One Sheet Per Animation"
print "" 
while iterator < len(AnimPerLineArr):

 print""
 print OneSheetArr[iterator][1]
 readIndivSheet(OneSheetArr[iterator][0],OneSheetArr[iterator][1])
 iterator += 1

iterator = 0
print""
print "Testing One Animation Per Line"
print ""
while iterator < len(OneSheetArr):

 print ""
 print AnimPerLineArr[iterator][1]
 readPerLine(AnimPerLineArr[iterator][0],AnimPerLineArr[iterator][1])
 iterator += 1
 
iterator = 0
print ""
print "Testing Individual Frames"
print ""
while iterator < len(IndivFrameArr):

 print ""
 print IndivFrameArr[iterator][1]
 readIndivFrames(IndivFrameArr[iterator][0],IndivFrameArr[iterator][1])
 iterator += 1