annotate examples/arraydemo.py @ 3194:9fcb7abf3185 default tip

Remove some gcc 4.7.2 compiler warnings
author Lenard Lindstrom <len-l@telus.net>
date Tue, 23 Apr 2013 19:53:36 -0700
parents 27991588198b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
498
dc24519e33d1 incorporate openbsd patches
pygame
parents: 352
diff changeset
1 #!/usr/bin/env python
dc24519e33d1 incorporate openbsd patches
pygame
parents: 352
diff changeset
2
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
3 import sys
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
4 import os
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
5 try:
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
6 import pygame
1427
a6e94e964a69 examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents: 977
diff changeset
7 from pygame import surfarray
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
8 from pygame.locals import *
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
9 except ImportError:
1610
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
10 raise ImportError('Error Importing Pygame/surfarray')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
11
1427
a6e94e964a69 examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents: 977
diff changeset
12 main_dir = os.path.split(os.path.abspath(__file__))[0]
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
13
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
14 def main(arraytype=None):
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
15 """show various surfarray effects
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
16
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
17 If arraytype is provided then use that array package. Valid
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
18 values are 'numeric' or 'numpy'. Otherwise default to NumPy,
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
19 or fall back on Numeric if NumPy is not installed.
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
20
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
21 """
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
22
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
23 if arraytype is None:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
24 if 'numpy' in surfarray.get_arraytypes():
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
25 surfarray.use_arraytype('numpy')
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
26 elif 'numeric' in surfarray.get_arraytype():
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
27 surfarray.use_arraytype('numeric')
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
28 else:
1610
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
29 raise ImportError('No array package is installed')
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
30 else:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
31 surfarray.use_arraytype(arraytype)
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
32
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
33 if surfarray.get_arraytype() == 'numpy':
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
34 import numpy as N
2088
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
35 from numpy import int32, uint8, uint
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
36 else:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
37 import Numeric as N
2088
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
38 from Numeric import Int32 as int32, UInt8 as uint8, UInt as uint
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
39
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
40 pygame.init()
1610
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
41 print ('Using %s' % surfarray.get_arraytype().capitalize())
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
42 print ('Press the mouse button to advance image.')
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
43 print ('Press the "s" key to save the current image.')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
44
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
45 def surfdemo_show(array_img, name):
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
46 "displays a surface, waits for user to continue"
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
47 screen = pygame.display.set_mode(array_img.shape[:2], 0, 32)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
48 surfarray.blit_array(screen, array_img)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
49 pygame.display.flip()
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
50 pygame.display.set_caption(name)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
51 while 1:
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
52 e = pygame.event.wait()
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
53 if e.type == MOUSEBUTTONDOWN: break
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
54 elif e.type == KEYDOWN and e.key == K_s:
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
55 #pygame.image.save(screen, name+'.bmp')
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
56 #s = pygame.Surface(screen.get_size(), 0, 32)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
57 #s = s.convert_alpha()
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
58 #s.fill((0,0,0,255))
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
59 #s.blit(screen, (0,0))
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
60 #s.fill((222,0,0,50), (0,0,40,40))
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
61 #pygame.image.save_extended(s, name+'.png')
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
62 #pygame.image.save(s, name+'.png')
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
63 #pygame.image.save(screen, name+'_screen.png')
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
64 #pygame.image.save(s, name+'.tga')
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
65 pygame.image.save(screen, name+'.png')
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
66 elif e.type == QUIT:
1610
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
67 raise SystemExit()
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
68
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
69 #allblack
1452
bb0a85996462 new _arraysurfarray module. blit_array bug 24 fix.
Lenard Lindstrom <len-l@telus.net>
parents: 1451
diff changeset
70 allblack = N.zeros((128, 128), int32)
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
71 surfdemo_show(allblack, 'allblack')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
72
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
73
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
74 #striped
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
75 #the element type is required for N.zeros in NumPy else
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
76 #an array of float is returned.
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
77 striped = N.zeros((128, 128, 3), int32)
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
78 striped[:] = (255, 0, 0)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
79 striped[:,::3] = (0, 255, 255)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
80 surfdemo_show(striped, 'striped')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
81
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
82
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
83 #imgarray
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
84 imagename = os.path.join(main_dir, 'data', 'arraydemo.bmp')
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
85 imgsurface = pygame.image.load(imagename)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
86 imgarray = surfarray.array2d(imgsurface)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
87 surfdemo_show(imgarray, 'imgarray')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
88
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
89
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
90 #flipped
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
91 flipped = imgarray[:,::-1]
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
92 surfdemo_show(flipped, 'flipped')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
93
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
94
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
95 #scaledown
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
96 scaledown = imgarray[::2,::2]
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
97 surfdemo_show(scaledown, 'scaledown')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
98
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
99
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
100 #scaleup
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
101 #the element type is required for N.zeros in NumPy else
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
102 #an #array of floats is returned.
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
103 size = N.array(imgarray.shape)*2
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
104 scaleup = N.zeros(size, int32)
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
105 scaleup[::2,::2] = imgarray
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
106 scaleup[1::2,::2] = imgarray
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
107 scaleup[:,1::2] = scaleup[:,::2]
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
108 surfdemo_show(scaleup, 'scaleup')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
109
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
110
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
111 #redimg
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
112 rgbarray = surfarray.array3d(imgsurface)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
113 redimg = N.array(rgbarray)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
114 redimg[:,:,1:] = 0
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
115 surfdemo_show(redimg, 'redimg')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
116
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
117
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
118 #soften
2088
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
119 #having factor as an array forces integer upgrade during multiplication
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
120 #of rgbarray, even for numpy.
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
121 factor = N.array((8,), int32)
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
122 soften = N.array(rgbarray, int32)
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
123 soften[1:,:] += rgbarray[:-1,:] * factor
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
124 soften[:-1,:] += rgbarray[1:,:] * factor
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
125 soften[:,1:] += rgbarray[:,:-1] * factor
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
126 soften[:,:-1] += rgbarray[:,1:] * factor
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
127 soften //= 33
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
128 surfdemo_show(soften, 'soften')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
129
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
130
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
131 #crossfade (50%)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
132 src = N.array(rgbarray)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
133 dest = N.zeros(rgbarray.shape)
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
134 dest[:] = 20, 50, 100
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
135 diff = (dest - src) * 0.50
2088
27991588198b upgrade numpy handling to Python 3.x
Lenard Lindstrom <len-l@telus.net>
parents: 1610
diff changeset
136 xfade = src + diff.astype(uint)
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
137 surfdemo_show(xfade, 'xfade')
115
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
138
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
139
ab99add14539 surfarray bugfixes
pygame
parents:
diff changeset
140
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
141
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
142 #alldone
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
143 pygame.quit()
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
144
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
145 def usage():
1610
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
146 print ("Usage: command line option [--numpy|--numeric]")
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
147 print (" The default is to use NumPy if installed,")
6c5040262b53 implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents: 1452
diff changeset
148 print (" otherwise Numeric")
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
149
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
150 if __name__ == '__main__':
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
151 if len(sys.argv) == 2:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
152 if '--numpy' in sys.argv:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
153 main('numpy')
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
154 elif '--numeric' in sys.argv:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
155 main('numeric')
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
156 else:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
157 usage()
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
158 elif len(sys.argv) == 1:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
159 main()
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
160 else:
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
161 usage()
1431
0eb69a939a65 updated examples so that they all have a main() and use pygame.quit
Rene Dudfield <renesd@gmail.com>
parents: 1427
diff changeset
162
1451
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
163
d480367ed509 fix NumPy bug in arraydemo.py and add an array choice command line arguemnt
Lenard Lindstrom <len-l@telus.net>
parents: 1431
diff changeset
164