Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/devtools/ScaleTypeTest/scaleTest.py~
blob: 76e87e0f1f476f95722a297015db6d0c277abe8f (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
#! /usr/bin/env python
import pygame, time
pygame.init()

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



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

make=input("How many images would you like to load?\n>")
trial=input("How many runs per trial?\n>")
sizeTo=input("What would you like to resize to? Seperate with a comma, eg: x,y\n>" )

img={}
ft="" #filetype
r=0 #frame refreshes
i=1 #cycles images
size = width, height = 600,400 #screen sizes
t=0 #trial number n
colorkey=(255, 152, 0)

ftArr=[ ["bmp","BMP16100/"] , ["bmp","BMP16173/"] , ["bmp","BMP16200/"] , ["bmp","BMP16400/"] ,["bmp","BMP24100/"] , ["bmp","BMP24173/"] , ["bmp","BMP24200/"] , ["bmp","BMP24400/"] , ["gif","GIF100/"] , ["gif","GIF173/"] ,  ["gif","GIF200/"] ,  ["gif","GIF400/"] , ["gif","GIFT100/"] , ["gif","GIFT173/"] ,  ["gif","GIFT200/"] ,  ["gif","GIFT400/"] , ["png","PNG100/"] , ["png","PNG173/"] , ["png","PNG200/"] , ["png","PNG400/"] , ["png","PNGT100/"] , ["png","PNGT173/"] , ["png","PNGT200/"] , ["png","PNGT400/"] ]

screen = pygame.display.set_mode(size) #Screen Set 600x400
background = 152, 251, 152 # pale green


#-------------------------------------------------------------
#The switch function

def chngImg():
    cnt=make
    while cnt>0:
        """switcher = {
            1: pygame.transform.scale( pygame.image.load( "%s2.%s"%( ft[1],ft[0] ) ) ,(sizeTo[0],sizeTo[1] ),
            2: pygame.transform.scale( pygame.image.load("%s3.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] ),
            3: pygame.transform.scale( pygame.image.load("%s4.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] ),
            4: pygame.transform.scale( pygame.image.load("%s5.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] ),
            5: pygame.transform.scale( pygame.image.load("%s6.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] ),
            6: pygame.transform.scale( pygame.image.load("%s7.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] ),
            7: pygame.transform.scale( pygame.image.load("%s8.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] ),
            8: pygame.transform.scale( pygame.image.load("%s9.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] ),
            9: pygame.transform.scale( pygame.image.load("%s1.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] )
        }
        """
        img[cnt,0]=switcher.get(i,pygame.image.load("%s1.%s"%(ft[1],ft[0])))
#        img[cnt,0] = pygame.transform.scale(img[cnt,0],(sizeTo[0], sizeTo[1]))
        cnt=cnt-1

#-----------------------------------------------------------------
#- Collision detection -------------------------------------------

def collision():
    cnt=make
    while cnt>0:
        if img[cnt,1].left < 0 or img[cnt,1].right > width:
            img[cnt,2]=[ -img[cnt,2][0], img[cnt,2][1] ]
        if img[cnt,1].top < 0 or img[cnt,1].bottom > height:
            img[cnt,2]=[ img[cnt,2][0], -img[cnt,2][1] ]
        img[cnt,1] = img[cnt,1].move(img[cnt,2])
        screen.blit(img[cnt,0],img[cnt,1])
        cnt=cnt-1
    pygame.display.flip()


#-----------------------------------------------------------------
#- Number of dashed lined relates to loops -----------------------

while 1:
    cnt=make
    ft=ftArr[t]
    print "Testing: "+ft[1]+" extension "+ft[0]
    trialthis=trial
    start=time.time()
    switcher = {
        1: pygame.transform.scale( pygame.image.load( "%s2.%s"%( ft[1],ft[0] ) ),(sizeTo[0],sizeTo[1] )),
        2: pygame.transform.scale( pygame.image.load("%s3.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] )),
        3: pygame.transform.scale( pygame.image.load("%s4.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] )),
        4: pygame.transform.scale( pygame.image.load("%s5.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] )),
        5: pygame.transform.scale( pygame.image.load("%s6.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] )),
        6: pygame.transform.scale( pygame.image.load("%s7.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] )),
        7: pygame.transform.scale( pygame.image.load("%s8.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] )),
        8: pygame.transform.scale( pygame.image.load("%s9.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] )),
        9: pygame.transform.scale( pygame.image.load("%s1.%s"%(ft[1],ft[0])),(sizeTo[0],sizeTo[1] ))
    }
    print "Time taken to load this test at ",
    print sizeTo
    print " pixels was "
    print time.time()-start
    
#-----------------------------------------------------------------
    while trialthis>0:

    #-------------------------------------------------------------
        while cnt>0:
            img[cnt,0]= pygame.image.load("%s1.%s"%(ft[1],ft[0])) #image.load
            img[cnt,0] = pygame.transform.scale(img[cnt,0],(sizeTo[0], sizeTo[1])) 
            img[cnt,1]=  img[cnt,0].get_rect()
            img[cnt,2]= [2,2] #speed
            m=cnt*40 # named m cause i wanted some m&ms
            img[cnt,1]=img[cnt,1].move(m,m) #see? it wasn't as tastey though
            cnt=cnt-1

    #-------------------------------------------------------------
        r=0
        start=time.time()

    #-------------------------------------------------------------
        while 1:
            chngImg()
            i=i+1
            if i>9: i=1
            
            collision()
            screen.fill(background)
            
            r=r+1
            if r>500: break
         
    #-------------------------------------------------------------
        print 1/((time.time()-start)/r)
        trialthis=trialthis-1

#-----------------------------------------------------------------
    t=t+1
    print ""

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