Skip to content

Commit 11bb85b

Browse files
authored
add meme play_baseball (#268)
1 parent aad955f commit 11bb85b

File tree

7 files changed

+53
-0
lines changed

7 files changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from datetime import datetime
2+
from pathlib import Path
3+
4+
from PIL.Image import Image as IMG
5+
from PIL.Image import Transpose
6+
from pil_utils import BuildImage
7+
8+
from meme_generator import add_meme
9+
from meme_generator.tags import MemeTags
10+
from meme_generator.utils import save_gif
11+
12+
img_dir = Path(__file__).parent / "images"
13+
14+
15+
def play_baseball(images: list[BuildImage], texts, args):
16+
img = images[0].convert("RGBA").circle().resize((150, 150))
17+
ball_x = 0
18+
ball_v = 40
19+
ball_angle = 0
20+
frames: list[IMG] = []
21+
for i in range(20):
22+
frame = BuildImage.new("RGBA", (1000, 300))
23+
ball_x += ball_v
24+
ball_angle += -60 if ball_v > 0 else 60
25+
if ball_x >= 200:
26+
ball_x = 200
27+
ball_v = -ball_v
28+
elif ball_x <= -200:
29+
ball_x = -200
30+
ball_v = -ball_v
31+
frame.paste(img.rotate(ball_angle), (425 + ball_x, 120), alpha=True)
32+
right_index = i - 2 if i in [3, 4, 5, 6, 7] else 0
33+
left_index = i - 12 if i in [13, 14, 15, 16, 17] else 0
34+
right = BuildImage.open(img_dir / f"{right_index}.png")
35+
left = BuildImage.open(img_dir / f"{left_index}.png").transpose(
36+
Transpose.FLIP_LEFT_RIGHT
37+
)
38+
frame.paste(right, (630, 6), alpha=True)
39+
frame.paste(left, (0, 6), alpha=True)
40+
frames.append(frame.image)
41+
return save_gif(frames, 0.08)
42+
43+
44+
add_meme(
45+
"play_baseball",
46+
play_baseball,
47+
min_images=1,
48+
max_images=1,
49+
keywords=["打棒球"],
50+
tags=MemeTags.capoo,
51+
date_created=datetime(2025, 6, 3),
52+
date_modified=datetime(2025, 6, 3),
53+
)
10.5 KB
Loading
15.4 KB
Loading
14.8 KB
Loading
17.3 KB
Loading
11.9 KB
Loading
11.4 KB
Loading

0 commit comments

Comments
 (0)