19
19
If the Surface is color keyed, then threshold is not used.
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
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
23
34
pygame object for representing 2d bitmasks
24
pygame.Mask((width, height): return Mask
35
pygame.Mask((width, height)): return Mask
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
76
two masks collide. An approximate collision normal can be found by calculating
77
the gradient of the overlap area through the finite difference.
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))
84
Returns a mask of the overlapping pixels
85
Mask.overlap_mask(othermask, offset) -> Mask
87
Returns a Mask the size of the original Mask containing only the overlapping
88
pixels between Mask and othermask.
95
Sets all bits in a Mask to 1.
102
Sets all bits in a Mask to 0.
106
Flips the bits in a Mask
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.
115
Mask.scale((x, y)) -> Mask
117
Returns a new Mask of the Mask scaled to the requested size.
121
Draws a mask onto another
122
Mask.draw(othermask, offset)
124
Performs a bitwise OR, drawing othermask onto Mask.
128
Erases a mask from another
129
Mask.erase(othermask, offset)
131
Erases all pixels set in othermask from Mask.
135
Returns the number of set pixels
136
Mask.count() -> pixels
138
Returns the number of set pixels in the Mask.
142
Returns the centroid of the pixels in a Mask
143
Mask.centroid() -> (x, y)
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
151
Returns the orientation of the pixels
152
Mask.angle() -> theta
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.
160
list of points outlining an object
161
Mask.outline(every = 1) -> [(x,y), (x,y) ...]
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.
171
Return the convolution of self with another mask.
172
Mask.convolve(othermask, outputmask = None, offset = (0,0)) -> Mask
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
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.
184
Returns a mask of a connected region of pixels.
185
Mask.connected_component((x,y) = None) -> Mask
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.
196
Returns a list of masks of connected regions of pixels.
197
Mask.connected_components(min = 0) -> [Masks]
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.
68
203
get_bounding_rects