Mercurial > pygame
annotate docs/ref/pixelarray.html @ 1553:ebd545641c8b
merging with python3 branch r 2048
| author | Lenard Lindstrom <len-l@telus.net> |
|---|---|
| date | Sat, 02 May 2009 01:03:14 +0000 |
| parents | 9379bdac652e |
| children | 15abbc81fc58 |
| rev | line source |
|---|---|
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
2 <html> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
3 <title>pixelarray - Pygame Documentation</title> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
4 <body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
5 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
6 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
7 <table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
8 <tr> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
9 <td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
10 <td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
11 || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
12 <a href=http://www.pygame.org>Pygame Home</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
13 <a href=../index.html>Help Contents</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
14 <a href=index.html>Reference Index</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
15 <br> <br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
16 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
17 <a href="camera.html">Camera</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
18 <a href="cdrom.html">Cdrom</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
19 <a href="color.html">Color</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
20 <a href="cursors.html">Cursors</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
21 <a href="display.html">Display</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
22 <a href="draw.html">Draw</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
23 <a href="event.html">Event</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
24 <a href="examples.html">Examples</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
25 <a href="font.html">Font</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
26 <a href="image.html">Image</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
27 <a href="joystick.html">Joystick</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
28 <a href="key.html">Key</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
29 <a href="locals.html">Locals</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
30 <a href="mask.html">Mask</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
31 <a href="midi.html">Midi</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
32 <a href="mixer.html">Mixer</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
33 <a href="mouse.html">Mouse</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
34 <a href="movie.html">Movie</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
35 <a href="music.html">Music</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
36 <a href="overlay.html">Overlay</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
37 <a href="pixelarray.html">Pixelarray</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
38 <a href="pygame.html">Pygame</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
39 <a href="rect.html">Rect</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
40 <a href="scrap.html">Scrap</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
41 <a href="sndarray.html">Sndarray</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
42 <a href="sprite.html">Sprite</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
43 <a href="surface.html">Surface</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
44 <a href="surfarray.html">Surfarray</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
45 <a href="tests.html">Tests</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
46 <a href="time.html">Time</a> || |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
47 <a href="transform.html">Transform</a> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
48 </td></tr></table> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
49 <br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
50 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
51 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
52 <a name="pygame.PixelArray"> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
53 <big><b>pygame.PixelArray</big></b><br><ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
54 <i>pygame object for direct pixel access of surfaces</i><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
55 <tt>pygame.PixelArray(Surface): return PixelArray</tt><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
56 <ul><small><table> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
57 <tr><td><a href="pixelarray.html#PixelArray.surface">PixelArray.surface</a> - <font size=-1>Gets the Surface the PixelArray uses.</font></td><td>Gets the Surface the PixelArray uses.</td></tr> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
58 <tr><td><a href="pixelarray.html#PixelArray.make_surface">PixelArray.make_surface</a> - <font size=-1>Creates a new Surface from the current PixelArray.</font></td><td>Creates a new Surface from the current PixelArray.</td></tr> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
59 <tr><td><a href="pixelarray.html#PixelArray.replace">PixelArray.replace</a> - <font size=-1>Replaces the passed color in the PixelArray with another one.</font></td><td>Replaces the passed color in the PixelArray with another one.</td></tr> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
60 <tr><td><a href="pixelarray.html#PixelArray.extract">PixelArray.extract</a> - <font size=-1>Extracts the passed color from the PixelArray.</font></td><td>Extracts the passed color from the PixelArray.</td></tr> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
61 <tr><td><a href="pixelarray.html#PixelArray.compare">PixelArray.compare</a> - <font size=-1>Compares the PixelArray with another one.</font></td><td>Compares the PixelArray with another one.</td></tr> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
62 </table></small></ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
63 <p>The PixelArray wraps up a Surface and provides a direct <tt>2D</tt> array access to its pixels using the surface its rows as first and its columns as second axis. It supports slicing, row and pixel manipluation, slicing and slice assignments while inplace operations such as addition, subtraction, multiplication, division and so forth are not allowed. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
64 <p>While it is possible to assign both, integer color values and <tt>RGB(A)</tt> color tuples, the PixelArray will only use integers for the color representation. Thus, checking for certain colors has to be done using the <tt><a href="surface.html#Surface.map_rgb">Surface.map_rgb</a> - <font size=-1>convert a color into a mapped color value</font></tt> method of the surface, the PixelArray was created for. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
65 <pre> pxarray = pygame.PixelArray (surface) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
66 # Check, if the first pixel at the topleft corner is blue |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
67 if pxarray[0][0] == surface.map_rgb ((0, 0, 255)): |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
68 ... |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
69 </pre><p>Pixels can be manipulated using integer values or color tuples. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
70 <pre> pxarray[x][y] = 0xFF00FF |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
71 pxarray[x][y] = (255, 0, 255) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
72 </pre><p>If you operate on a slice, you also can use arbitrary sequences or other PixelArray objects to modify the pixels. They have to match the size of the PixelArray however. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
73 <pre> pxarray[a:b] = 0xFF00FF # set all pixels to 0xFF00FF |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
74 pxarray[a:b] = (0xFF00FF, 0xAACCEE, ... ) # first pixel = 0xFF00FF, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
75 # second pixel = 0xAACCEE, ... |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
76 pxarray[a:b] = ((255, 0, 255), (170, 204, 238), ...) # same as above |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
77 pxarray[a:b] = ((255, 0, 255), 0xAACCEE, ...) # same as above |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
78 pxarray[a:b] = otherarray[x:y] # slice sizes must match |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
79 </pre><p>Note, that something like </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
80 <pre> pxarray[2:4][3:5] = ... |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
81 </pre><p>will not cause a rectangular manipulation. Instead it will be first sliced to a two-column array, which then shall be sliced by columns once more, which will fail due an IndexError. This is caused by the slicing mechanisms in python and an absolutely correct behaviour. Create a single columned slice first, which you can manipulate then: </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
82 <pre> pxarray[2][3:5] = ... |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
83 pxarray[3][3:5] = ... |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
84 </pre><p>If you want to make a rectangular manipulation or create a view of a part of the PixelArray, you also can use the subscript abilities. You can easily create different view by creating 'subarrays' using the subscripts. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
85 <pre> # Create some new PixelArray objects providing a different view |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
86 # of the original array/surface. |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
87 newarray = pxarray[2:4,3:5] |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
88 otherarray = pxarray[::2,::2] |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
89 </pre><p>Subscripts also can be used to do fast rectangular pixel manipulations instead of iterating over the x or y axis as above. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
90 <pre> pxarray[::2,:] = (0, 0, 0) # Make each second column black. |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
91 </pre><p>During its lifetime, the PixelArray locks the surface, thus you explicitly have to delete it once its not used anymore and the surface should perform operations in the same scope. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
92 <p>New in pygame <tt>1.8</tt>. Subscript support is new in pygame <tt>1.8.1</tt>. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
93 <!--COMMENTS:pygame.PixelArray--> <br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
94 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
95 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
96 <a name="PixelArray.surface"> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
97 <big><b>PixelArray.surface</big></b><br><ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
98 <i>Gets the Surface the PixelArray uses.</i><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
99 <tt>PixelArray.surface: Return Surface</tt><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
100 <p>The Surface, the PixelArray was created for. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
101 <!--COMMENTS:PixelArray.surface--> <br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
102 <br></ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
103 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
104 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
105 <a name="PixelArray.make_surface"> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
106 <big><b>PixelArray.make_surface</big></b><br><ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
107 <i>Creates a new Surface from the current PixelArray.</i><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
108 <tt>PixelArray.make_surface (): Return Surface</tt><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
109 <p>Creates a new Surface from the current PixelArray. Depending on the current PixelArray the size, pixel order etc. will be different from the original Surface. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
110 <pre> # Create a new surface flipped around the vertical axis. |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
111 sf = pxarray[:,::-1].make_surface () |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
112 </pre><p>New in pygame <tt>1.8.1</tt>. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
113 <!--COMMENTS:PixelArray.make_surface--> <br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
114 <br></ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
115 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
116 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
117 <a name="PixelArray.replace"> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
118 <big><b>PixelArray.replace</big></b><br><ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
119 <i>Replaces the passed color in the PixelArray with another one.</i><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
120 <tt>PixelArray.replace (color, repcolor, distance=0, weights=(0.299, 0.587, 0.114)): Return None</tt><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
121 <p>Replaces the pixels with the passed color in the PixelArray by changing them them to the passed replacement color. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
122 <p>It uses a simple weighted euclidian distance formula to calculate the distance between the colors. The distance space ranges from <tt>0.0</tt> to <tt>1.0</tt> and is used as threshold for the color detection. This causes the replacement to take pixels with a similar, but not exactly identical color, into account as well. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
123 <p>This is an in place operation that directly affects the pixels of the PixelArray. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
124 <p>New in pygame <tt>1.8.1</tt>. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
125 <!--COMMENTS:PixelArray.replace--> <br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
126 <br></ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
127 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
128 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
129 <a name="PixelArray.extract"> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
130 <big><b>PixelArray.extract</big></b><br><ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
131 <i>Extracts the passed color from the PixelArray.</i><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
132 <tt>PixelArray.extract (color, distance=0, weights=(0.299, 0.587, 0.114)): Return PixelArray</tt><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
133 <p>Extracts the passed color by changing all matching pixels to white, while non-matching pixels are changed to black. This returns a new PixelArray with the black/white color mask. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
134 <p>It uses a simple weighted euclidian distance formula to calculate the distance between the colors. The distance space ranges from <tt>0.0</tt> to <tt>1.0</tt> and is used as threshold for the color detection. This causes the extraction to take pixels with a similar, but not exactly identical color, into account as well. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
135 <p>New in pygame <tt>1.8.1</tt>. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
136 <!--COMMENTS:PixelArray.extract--> <br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
137 <br></ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
138 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
139 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
140 <a name="PixelArray.compare"> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
141 <big><b>PixelArray.compare</big></b><br><ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
142 <i>Compares the PixelArray with another one.</i><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
143 <tt>PixelArray.compare (array, distance=0, weights=(0.299, 0.587, 0.114)): Return PixelArray</tt><br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
144 <p>Compares the contents of the PixelArray with those from the passed PixelArray. It returns a new PixelArray with a black/white color mask that indicates the differences (white) of both arrays. Both PixelArray objects must have indentical bit depths and dimensions. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
145 <p>It uses a simple weighted euclidian distance formula to calculate the distance between the colors. The distance space ranges from <tt>0.0</tt> to <tt>1.0</tt> and is used as threshold for the color detection. This causes the comparision to mark pixels with a similar, but not exactly identical color, as black. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
146 <p>New in pygame <tt>1.8.1</tt>. </p> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
147 <!--COMMENTS:PixelArray.compare--> <br> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
148 <br></ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
149 <br></ul> |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
150 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
151 </body></html> |
