~ubuntu-branches/ubuntu/maverick/pygame/maverick

« back to all changes in this revision

Viewing changes to src/mask.doc

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 17:02:11 UTC
  • mfrom: (1.3.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114170211-21eop2ja7mr9vdcr
Tags: 1.9.1release-0ubuntu1
* New upstream version (lp: #433304)
* debian/control:
  - build-depends on libportmidi-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
If the Surface is color keyed, then threshold is not used.
20
20
<END>
21
21
 
 
22
from_threshold
 
23
Creates a mask by thresholding Surfaces
 
24
pygame.mask.from_surface(Surface, color, threshold = (0,0,0,255), othersurface = None, palette_colors = 1) -> Mask
 
25
 
 
26
This is a more featureful method of getting a Mask from a Surface.  If supplied
 
27
with only one Surface, all pixels within the threshold of the supplied color are
 
28
set in the Mask. If given the optional othersurface, all pixels in Surface that
 
29
are within the threshold of the corresponding pixel in othersurface are set in
 
30
the Mask.
 
31
<END>
 
32
 
22
33
Mask
23
34
pygame object for representing 2d bitmasks
24
 
pygame.Mask((width, height): return Mask
 
35
pygame.Mask((width, height)): return Mask
25
36
<SECTION>
26
37
 
27
38
get_size
62
73
 
63
74
You can see how many pixels overlap with the other mask given.  This can
64
75
be used to see in which direction things collide, or to see how much the
65
 
two masks collide.
 
76
two masks collide.  An approximate collision normal can be found by calculating
 
77
the gradient of the overlap area through the finite difference.
 
78
 
 
79
 dx = Mask.overlap_area(othermask,(x+1,y)) - Mask.overlap_area(othermask,(x-1,y))
 
80
 dy = Mask.overlap_area(othermask,(x,y+1)) - Mask.overlap_area(othermask,(x,y-1))
 
81
<END>
 
82
 
 
83
overlap_mask
 
84
Returns a mask of the overlapping pixels
 
85
Mask.overlap_mask(othermask, offset) -> Mask
 
86
 
 
87
Returns a Mask the size of the original Mask containing only the overlapping
 
88
pixels between Mask and othermask.
 
89
<END>
 
90
 
 
91
fill
 
92
Sets all bits to 1
 
93
Mask.fill()
 
94
 
 
95
Sets all bits in a Mask to 1.
 
96
<END>
 
97
 
 
98
clear
 
99
Sets all bits to 0
 
100
Mask.clear()
 
101
 
 
102
Sets all bits in a Mask to 0.
 
103
<END>
 
104
 
 
105
invert
 
106
Flips the bits in a Mask
 
107
Mask.invert()
 
108
 
 
109
Flips all of the bits in a Mask, so that the set pixels turn to unset pixels and
 
110
the unset pixels turn to set pixels.
 
111
<END>
 
112
 
 
113
scale
 
114
Resizes a mask
 
115
Mask.scale((x, y)) -> Mask
 
116
 
 
117
Returns a new Mask of the Mask scaled to the requested size.
 
118
<END>
 
119
 
 
120
draw
 
121
Draws a mask onto another
 
122
Mask.draw(othermask, offset)
 
123
 
 
124
Performs a bitwise OR, drawing othermask onto Mask.
 
125
<END>
 
126
 
 
127
erase
 
128
Erases a mask from another
 
129
Mask.erase(othermask, offset)
 
130
 
 
131
Erases all pixels set in othermask from Mask.
 
132
<END>
 
133
 
 
134
count
 
135
Returns the number of set pixels
 
136
Mask.count() -> pixels
 
137
 
 
138
Returns the number of set pixels in the Mask.
 
139
<END>
 
140
 
 
141
centroid
 
142
Returns the centroid of the pixels in a Mask
 
143
Mask.centroid() -> (x, y)
 
144
 
 
145
Finds the centroid, the center of pixel mass, of a Mask.  Returns a coordinate
 
146
tuple for the centroid of the Mask. In the event the Mask is empty, it will
 
147
return (0,0).
 
148
<END>
 
149
 
 
150
angle
 
151
Returns the orientation of the pixels
 
152
Mask.angle() -> theta
 
153
 
 
154
Finds the approximate orientation of the pixels in the image from -90 to 90
 
155
degrees.  This works best if performed on one connected component of pixels.  It
 
156
will return 0.0 on an empty Mask.
 
157
<END>
 
158
 
 
159
outline
 
160
list of points outlining an object
 
161
Mask.outline(every = 1) -> [(x,y), (x,y) ...]
 
162
 
 
163
Returns a list of points of the outline of the first object it comes across in a
 
164
Mask.  For this to be useful, there should probably only be one connected
 
165
component of pixels in the Mask.  The every option allows you to skip pixels in
 
166
the outline.  For example, setting it to 10 would return a list of every 10th
 
167
pixel in the outline.
 
168
<END>
 
169
 
 
170
convolve
 
171
Return the convolution of self with another mask.
 
172
Mask.convolve(othermask, outputmask = None, offset = (0,0)) -> Mask
 
173
 
 
174
Returns a mask with the (i-offset[0],j-offset[1]) bit set if shifting othermask
 
175
so that it's lower right corner pixel is at (i,j) would cause it to overlap
 
176
with self.
 
177
 
 
178
If an outputmask is specified, the output is drawn onto outputmask and
 
179
outputmask is returned.  Otherwise a mask of size self.get_size() +
 
180
othermask.get_size() - (1,1) is created.
 
181
<END>
 
182
 
 
183
connected_component
 
184
Returns a mask of a connected region of pixels.
 
185
Mask.connected_component((x,y) = None) -> Mask
 
186
 
 
187
This uses the SAUF algorithm to find a connected component in the
 
188
Mask. It checks 8 point connectivity.  By default, it will return the largest
 
189
connected component in the image.  Optionally, a coordinate pair of a pixel can
 
190
be specified, and the connected component containing it will be returned.  In
 
191
the event the pixel at that location is not set, the returned Mask will be
 
192
empty.  The Mask returned is the same size as the original Mask.
 
193
<END>
 
194
 
 
195
connected_components
 
196
Returns a list of masks of connected regions of pixels.
 
197
Mask.connected_components(min = 0) -> [Masks]
 
198
 
 
199
Returns a list of masks of connected regions of pixels.  An optional minimum
 
200
number of pixels per connected region can be specified to filter out noise.
66
201
<END>
67
202
 
68
203
get_bounding_rects