@@ -16,11 +16,13 @@ class Effect:
16
16
_fill = rgba ("#ffffff00" )
17
17
18
18
@staticmethod
19
- def shift (img , dt ):
19
+ def shift (img , dt , reverse = False ):
20
20
"Shift effect timing"
21
21
for e in img .effects :
22
22
e ._t0 += dt
23
23
e ._t1 += dt
24
+ if reverse :
25
+ e ._t0 , e ._t1 = e ._t1 , e ._t0
24
26
return img
25
27
26
28
@property
@@ -252,37 +254,30 @@ def apply(self, img, n):
252
254
253
255
class Checkerboard (Effect ):
254
256
grid = 8 , 8
255
- mode = "+Y+Y"
257
+ vel = 0 , 1 , 0 , 1
256
258
257
259
def apply (self , img , n ):
258
260
srf = surface (img , True )
259
261
if n <= 0 or n >= 1 : return self .nofx (srf , n )
260
262
w , h = srf .get_size ()
261
- mode = self .mode .upper ()
262
263
srect = pygame .Rect (0 , 0 , w , h )
263
264
gx , gy = self .grid
264
265
sw = ceil (w / gx )
265
266
sh = ceil (h / gy )
266
- late = n > 0.5
267
- sd = ceil ((1 - 2 * (1 - n if late else n )) * (sh if late else sw ) + 1 )
268
- for c in range (gx ):
269
- for r in range (gy ):
270
- odd = (r + c ) % 2
271
- y = r * sh
272
- x = c * sw
273
- if odd :
274
- if n >= 0.5 : rect = None
275
- else :
276
- if mode [0 ] == "+" :
277
- if mode [1 ] == "X" : x += sw - sd
278
- else : y += sh - sd
279
- rect = (x , y , sw , sd ) if mode [1 ] == "Y" else (x , y , sd , sh )
280
- else :
281
- if n <= 0.5 : rect = (x , y , sw , sh )
282
- else :
283
- if mode [2 ] == "+" :
284
- if mode [3 ] == "X" : x += sd
285
- else : y += sd
286
- rect = (x , y , sw , sh - sd ) if mode [3 ] == "Y" else (x , y , sw - sd , sh )
287
- if rect : srf .subsurface (srect .clip (rect )).fill (self ._fill )
267
+ rects = [[pygame .Rect (c * sw , r * sh , sw , sh ).clip (srect ) for c in range (gx )] for r in range (gy )]
268
+ m = self .vel
269
+ for r in range (gy ):
270
+ for c in range (gx ):
271
+ rect = rects [c ][r ]
272
+ if (r + c ) % 2 : # Odd squares
273
+ if n > 0.5 :
274
+ dx = 2 * (n - 0.5 ) * sw * m [2 ]
275
+ dy = 2 * (n - 0.5 ) * sh * m [3 ]
276
+ rect = rect .clip (rect .move (dx , dy ))
277
+ srf .subsurface (rect ).fill (self ._fill )
278
+ elif n < 0.5 : # Even squares
279
+ dx = 2 * n * sw * m [0 ]
280
+ dy = 2 * n * sh * m [1 ]
281
+ rect = rect .clip (rect .move (dx , dy ))
282
+ srf .subsurface (rect ).fill (self ._fill )
288
283
return srf
0 commit comments