1 '''Mutations to apply to images'''
3 from pygame.transform import flip, rotate, scale
5 from naja.constants import EIGHT_BIT_SCALE
9 def __init__(self, func, *args):
11 self._args = tuple(args)
13 def __call__(self, image):
14 return self._func(image, *self._args)
17 return hash((self._func, self._args))
19 def __eq__(self, other):
20 if not isinstance(other, Mutator):
22 return (self._func == other._func) and (self._args == other._args)
25 return '<%s %r>' % (self.__class__.__name__, self._args)
29 return Mutator(rotate, angle)
33 return Mutator(scale, size)
36 def scale_multiplier(image, factor):
37 size = image.get_width() * factor, image.get_height() * factor
38 return scale(image, size)
42 NULL = Mutator(lambda x: x)
49 FLIP_H = Mutator(flip, True, False)
50 FLIP_V = Mutator(flip, False, True)
52 EIGHT_BIT = Mutator(scale_multiplier, EIGHT_BIT_SCALE)