@auscera/cleoedits 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/cli.mjs +149 -0
- package/lib/dependencies.mjs +384 -0
- package/lib/run.mjs +114 -0
- package/lib/workspace.mjs +167 -0
- package/package.json +240 -3
- package/workspace/.agents/skills/cleoedits/SKILL.md +29 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/audiogram.json +41 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/facebook.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/linkedin.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/podcast.json +23 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/reels.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/shorts.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/tiktok.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/x.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube-shorts.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/LICENSE-SimpleIcons +30 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/logos.json +1 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Anton-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/ArchivoBlack-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/InstrumentSerif-Italic.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Inter.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/LICENSE-PermanentMarker.txt +202 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Montserrat.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Anton.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-ArchivoBlack.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-InstrumentSerif.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Inter.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Montserrat.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-PlayfairDisplay.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Poppins.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-SpaceMono.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PermanentMarker-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay-Italic.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Black.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Bold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-ExtraBold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/SpaceMono-Bold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-MediaPipe +218 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-YuNet +21 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/NOTICE.md +4 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/selfie_segmenter.tflite +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/yunet.onnx +0 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/LICENSE +21 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/audio-app-ui/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/STYLE.md +53 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/index.html +328 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/index.html +575 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/design-app-ui/STYLE.md +68 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editor-ui/STYLE.md +73 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/STYLE.md +54 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/index.html +189 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/STYLE.md +64 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/index.html +620 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/STYLE.md +55 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/index.html +238 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/STYLE.md +66 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/index.html +602 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/STYLE.md +66 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/index.html +777 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/STYLE.md +56 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/index.html +186 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/motion-app-ui/STYLE.md +68 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/STYLE.md +56 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/index.html +244 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/STYLE.md +67 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/index.html +663 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/STYLE.md +59 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/index.html +395 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/STYLE.md +52 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/index.html +194 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/STYLE.md +58 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/index.html +242 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/STYLE.md +53 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/index.html +138 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/STYLE.md +63 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/index.html +599 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/index.html +1297 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/STYLE.md +69 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/index.html +674 -0
- package/workspace/.agents/skills/cleoedits/references/audio-clearervoice-elevenlabs.md +11 -0
- package/workspace/.agents/skills/cleoedits/references/ffmpeg-and-reels.md +15 -0
- package/workspace/.agents/skills/cleoedits/references/hyperframes-workflows.md +13 -0
- package/workspace/.agents/skills/cleoedits/references/kdenlive-cli-and-mcp.md +12 -0
- package/workspace/.agents/skills/cleoedits/references/motion-design-pipeline.md +7 -0
- package/workspace/.agents/skills/cleoedits/references/motion-taste-emil.md +5 -0
- package/workspace/.agents/skills/cleoedits/references/playwright-demo-capture.md +9 -0
- package/workspace/.agents/skills/cleoedits/references/remotion-workflows.md +13 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/LICENSE +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_ass_overlay.py +399 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/__init__.py +235 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/alpha.py +560 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/asr.py +1237 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/color.py +540 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/decision.py +2452 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/drawtext.py +290 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emit.py +1309 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emoji.py +518 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/fonts.py +875 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing.py +263 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing_edit.py +432 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/probe.py +1613 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/runner.py +3994 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/text.py +73 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/timeline.py +721 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/wrap.py +981 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_contract.py +2454 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_platforms.py +258 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.html +754 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.py +258 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_smartcut.py +450 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/audio.py +867 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/background.py +136 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/batch.py +1409 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/broll.py +282 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/caption.py +2207 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/check.py +815 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/color.py +695 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/crop.py +91 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cropdetect.py +214 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cut.py +2076 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/deinterlace.py +90 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/denoise.py +94 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/export.py +1033 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/fit.py +729 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/freeze.py +197 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/graphics.py +920 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/grid.py +235 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/insert.py +142 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/join.py +1083 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/look.py +475 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loop.py +395 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loudness.py +397 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/metadata.py +416 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/multicam.py +414 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/overlay.py +766 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/pad.py +121 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/probe.py +145 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/proxy.py +93 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/redact.py +162 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/render.py +2424 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/report.py +354 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/reverse.py +114 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/scenes.py +439 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sequence.py +285 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/silence.py +945 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/speedramp.py +193 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sphere.py +137 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/stabilize.py +141 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/straighten.py +120 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sync.py +500 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/verify.py +411 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/waveform.py +502 -0
- package/workspace/.agents/skills/cleoedits/scripts/kdenlive_builder.py +284 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-claude-motion +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-motion-design +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/_media.py +43 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/pacing_check.py +90 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/storyboard.py +77 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/LICENSE +26 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/fx.py +2717 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/logos.py +194 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/sfx.py +105 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/trim.py +99 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/words.py +60 -0
- package/workspace/.claude/commands/blender-3d.md +12 -0
- package/workspace/.claude/commands/business-short-form-reels.md +12 -0
- package/workspace/.claude/commands/color-grade.md +12 -0
- package/workspace/.claude/commands/cutout-grid-reel.md +12 -0
- package/workspace/.claude/commands/depth-ui-reel.md +12 -0
- package/workspace/.claude/commands/explainer-panel-reel.md +12 -0
- package/workspace/.claude/commands/freeze-frame.md +12 -0
- package/workspace/.claude/commands/glass-graph.md +12 -0
- package/workspace/.claude/commands/over-the-shoulder.md +12 -0
- package/workspace/.claude/commands/personal-short-form-reels.md +12 -0
- package/workspace/.claude/commands/ranking-format.md +12 -0
- package/workspace/.claude/commands/relight.md +12 -0
- package/workspace/.claude/commands/reverse-engineer.md +12 -0
- package/workspace/.claude/commands/text-behind.md +12 -0
- package/workspace/.claude/commands/tier-list.md +12 -0
- package/workspace/.claude-plugin/plugin.json +8 -0
- package/workspace/.npmignore +15 -0
- package/workspace/AGENTS.md +30 -0
- package/workspace/README.md +63 -0
- package/workspace/assets/fonts/TikTokSans-OFL.txt +93 -0
- package/workspace/assets/fonts/TikTokSans-Variable.ttf +0 -0
- package/workspace/assets/luts/clean_warm.cube +4917 -0
- package/workspace/assets/luts/golden_hour.cube +4917 -0
- package/workspace/assets/luts/moody_dark.cube +4917 -0
- package/workspace/assets/luts/teal_orange.cube +4917 -0
- package/workspace/assets/sfx/NOTICE.txt +1 -0
- package/workspace/assets/sfx/click.wav +0 -0
- package/workspace/assets/sfx/pop.wav +0 -0
- package/workspace/assets/sfx/riser.wav +0 -0
- package/workspace/assets/sfx/whoosh.wav +0 -0
- package/workspace/generators/hyperframes/index.html +39 -0
- package/workspace/generators/hyperframes/package.json +15 -0
- package/workspace/generators/hyperframes/pnpm-lock.yaml +1181 -0
- package/workspace/generators/hyperframes/pnpm-workspace.yaml +10 -0
- package/workspace/generators/remotion/eslint.config.mjs +3 -0
- package/workspace/generators/remotion/package.json +36 -0
- package/workspace/generators/remotion/pnpm-lock.yaml +4179 -0
- package/workspace/generators/remotion/pnpm-workspace.yaml +10 -0
- package/workspace/generators/remotion/remotion.config.ts +13 -0
- package/workspace/generators/remotion/src/Root.tsx +52 -0
- package/workspace/generators/remotion/src/index.css +1 -0
- package/workspace/generators/remotion/src/index.ts +4 -0
- package/workspace/generators/remotion/tsconfig.json +15 -0
- package/workspace/pipeline/scripts/_codec.py +28 -0
- package/workspace/pipeline/scripts/ai_media_api.py +109 -0
- package/workspace/pipeline/scripts/blender_render.py +166 -0
- package/workspace/pipeline/scripts/composite.py +49 -0
- package/workspace/pipeline/scripts/melt.sh +68 -0
- package/workspace/pipeline/scripts/normalize_audio.py +39 -0
- package/workspace/pipeline/scripts/person_matte.py +216 -0
- package/workspace/pipeline/scripts/record_demo.py +69 -0
- package/workspace/pipeline/scripts/whisper_cut.py +98 -0
- package/workspace-manifest.json +908 -0
|
@@ -0,0 +1,2717 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Adam Digital video effects for Claude: 55 effects, word-by-word captions and sound effects.
|
|
3
|
+
|
|
4
|
+
Built on claude-video-effects by Vibha Ramprakash (MIT). Adam Digital adds captions, sound effects,
|
|
5
|
+
pause trimming (trim.py), a name/handle profile and the pop-word, logo-link, card-drop and halftone-paper effects.
|
|
6
|
+
|
|
7
|
+
One effect: python fx.py orbit in.mp4 out.mp4 --start 3.2 --end 6
|
|
8
|
+
Many effects: python fx.py --plan plan.json in.mp4 out.mp4
|
|
9
|
+
Quick check: python fx.py --plan plan.json in.mp4 check.png --still 4.5
|
|
10
|
+
Your name: python fx.py --profile "Your Name" "@yourhandle"
|
|
11
|
+
List them: python fx.py --list
|
|
12
|
+
"""
|
|
13
|
+
import argparse, json, math, os, random, re, subprocess, sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
import numpy as np
|
|
16
|
+
import cv2
|
|
17
|
+
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
|
18
|
+
|
|
19
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[5] / 'pipeline' / 'scripts'))
|
|
20
|
+
from _codec import h264_encode_args
|
|
21
|
+
|
|
22
|
+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'assets', 'reel_effects'))
|
|
23
|
+
FONT = {k: os.path.join(ROOT, 'fonts', v) for k, v in {
|
|
24
|
+
'bold': 'ArchivoBlack-Regular.ttf', 'serif': 'InstrumentSerif-Italic.ttf', 'mono': 'SpaceMono-Bold.ttf',
|
|
25
|
+
'hand': 'PermanentMarker-Regular.ttf', 'ui': 'Inter.ttf', 'uim': 'Inter.ttf', 'uib': 'Inter.ttf', 'ui7': 'Inter.ttf',
|
|
26
|
+
'anton': 'Anton-Regular.ttf', 'mont': 'Montserrat.ttf', 'monts': 'Montserrat.ttf', 'montb': 'Montserrat.ttf',
|
|
27
|
+
'didone': 'PlayfairDisplay.ttf', 'didoneb': 'PlayfairDisplay.ttf', 'didonei': 'PlayfairDisplay-Italic.ttf',
|
|
28
|
+
'didoneib': 'PlayfairDisplay-Italic.ttf', 'pop': 'Poppins-Black.ttf', 'popx': 'Poppins-ExtraBold.ttf', 'popb': 'Poppins-Bold.ttf'}.items()}
|
|
29
|
+
WGHT = {'ui': (24, 640), 'uim': (24, 540), 'uib': (32, 860), 'ui7': (32, 700), 'mont': (700,), 'monts': (600,), 'montb': (800,), 'didone': (500,), 'didoneb': (800,), 'didonei': (500,), 'didoneib': (800,)} # Inter variable: (optical size, weight)
|
|
30
|
+
|
|
31
|
+
# Your name and handle, used by the effects that show a profile card. Saved once with --profile.
|
|
32
|
+
PROFILE_PATH = os.path.join(os.getcwd(), '.cleoedits', 'reel-profile.json')
|
|
33
|
+
def load_profile():
|
|
34
|
+
try: p = json.load(open(PROFILE_PATH))
|
|
35
|
+
except Exception: p = {}
|
|
36
|
+
name = str(p.get('name') or 'Your Name').strip(); handle = str(p.get('handle') or '@yourhandle').strip()
|
|
37
|
+
return {'name': name, 'handle': handle if handle.startswith('@') else '@' + handle}
|
|
38
|
+
PROFILE = load_profile()
|
|
39
|
+
CREAM, INK, PEACH, YELLOW = (244, 233, 216), (22, 22, 24), (255, 183, 165), (255, 214, 10)
|
|
40
|
+
NAMES = ['The Noise', 'The Lineup', 'Locked On', 'Orbit', 'Lean-In', 'Backdrop Word', 'Spotlight', 'The Bill',
|
|
41
|
+
'Moody', 'Swipe', 'The To-Do', 'Comment Box', 'The Tap', 'Pause & Point', 'Uninstall', 'Reel Frame',
|
|
42
|
+
'Shortcut Rain', 'Reject Stamp', 'Countdown Flip', 'Rabbit Hole', 'Cover Star', 'Scribble']
|
|
43
|
+
EFFECTS = {}
|
|
44
|
+
ALIASES = {'the-noise': 'noise', 'the-lineup': 'lineup', 'bill': 'the-bill', 'to-do': 'todo', 'the-todo': 'todo', 'the-to-do': 'todo',
|
|
45
|
+
'the-tap': 'tap', 'follow': 'tap', 'comment': 'comment-box', 'pause': 'pause-point', 'pause-and-point': 'pause-point',
|
|
46
|
+
'backdrop': 'backdrop-word', 'stamp': 'reject-stamp', 'countdown': 'countdown-flip', 'cover': 'cover-star', 'rain': 'shortcut-rain',
|
|
47
|
+
'glass': 'glass-widgets', 'widgets': 'glass-widgets', 'collage': 'red-collage', 'split': 'split-headline', 'pastel': 'pastel-word',
|
|
48
|
+
'pills': 'check-pills', 'auto-edit': 'timeline', 'headline': 'headline-box', 'wall': 'profile-wall', 'tiers': 'tier-list',
|
|
49
|
+
'tier': 'tier-list', 'broll': 'broll-split', 'b-roll': 'broll-split', 'fan': 'phone-fan', 'dots': 'dot-reveal',
|
|
50
|
+
'headlines': 'headline-wall', 'tasks': 'checklist',
|
|
51
|
+
'liquid-glass': 'liquid-glass-graph', 'glass-graph': 'liquid-glass-graph', 'carousel': 'carousel-spin', 'match': 'match-cut',
|
|
52
|
+
'toggles': 'apple-toggles', 'led': 'led-sign', 'push': 'slow-push', 'push-in': 'slow-push',
|
|
53
|
+
'ots': 'over-the-shoulder-zoom', 'shoulder-zoom': 'over-the-shoulder-zoom', 'corner-zoom': 'over-the-shoulder-zoom',
|
|
54
|
+
'tape': 'tape-label', 'select': 'select-resize', 'resize': 'select-resize', 'wave': 'wave-trim', 'strike': 'huge-strike', 'crayon': 'crayon-write', 'deal': 'fan-build', 'imessage': 'messages', 'texts': 'messages', 'notifications': 'messages', 'grid': 'place-in-grid', 'profile-grid': 'place-in-grid',
|
|
55
|
+
'pop': 'pop-word', 'big-word': 'pop-word', 'logo': 'logo-link', 'logos': 'logo-link', 'link': 'logo-link',
|
|
56
|
+
'card': 'card-drop', 'drop': 'card-drop', 'paper': 'halftone-paper', 'halftone': 'halftone-paper',
|
|
57
|
+
'caption': 'captions', 'subtitles': 'captions', 'subs': 'captions'}
|
|
58
|
+
LOOK_NAMES = {'glitter-spotlight': ('spotlight', 'sparkle'), 'glitter': ('spotlight', 'sparkle')} # a named look of another effect
|
|
59
|
+
CARD_FX = ('fan-build', 'noise', 'orbit', 'carousel-spin', 'place-in-grid', 'check-pills', 'profile-wall', 'phone-fan', 'broll-split', 'timeline')
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def effect(name, desc):
|
|
63
|
+
def deco(fn):
|
|
64
|
+
EFFECTS[name] = (fn, desc)
|
|
65
|
+
return fn
|
|
66
|
+
return deco
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# ---------- small helpers ----------
|
|
70
|
+
def clamp(x, a=0.0, b=1.0): return max(a, min(b, x))
|
|
71
|
+
def ease_out(x): x = clamp(x); return 1 - (1 - x) ** 3
|
|
72
|
+
def ease_inout(x): x = clamp(x); return 3 * x * x - 2 * x * x * x
|
|
73
|
+
def ease_back(x): x = clamp(x); s = 1.7; x -= 1; return x * x * ((s + 1) * x + s) + 1
|
|
74
|
+
def ramp(c, e, t_in=0.25, t_out=0.2): return clamp(c.lt / t_in) * clamp((e.d - c.lt) / t_out) if t_out else clamp(c.lt / t_in)
|
|
75
|
+
def rgb(v, default):
|
|
76
|
+
if v is None: return default
|
|
77
|
+
if isinstance(v, (list, tuple)): return tuple(int(x) for x in v[:3])
|
|
78
|
+
v = str(v).lstrip('#'); return tuple(int(v[i:i + 2], 16) for i in (0, 2, 4))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
_fc = {}
|
|
82
|
+
def font(kind, size):
|
|
83
|
+
k = (kind, int(size))
|
|
84
|
+
if k not in _fc:
|
|
85
|
+
f = ImageFont.truetype(FONT[kind], max(6, int(size)))
|
|
86
|
+
if kind in WGHT:
|
|
87
|
+
try: f.set_variation_by_axes(list(WGHT[kind]))
|
|
88
|
+
except Exception: pass
|
|
89
|
+
_fc[k] = f
|
|
90
|
+
return _fc[k]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def text_img(s, size, kind='bold', fill=(255, 255, 255), stroke=0, stroke_fill=INK, shadow=0, glow=None):
|
|
94
|
+
f = font(kind, size)
|
|
95
|
+
bb = f.getbbox(s, stroke_width=stroke)
|
|
96
|
+
pad = int(size * 0.2 + shadow * 2.5 + (glow[1] * 2.5 if glow else 0)) + 4
|
|
97
|
+
w, h = bb[2] - bb[0] + 2 * pad, bb[3] - bb[1] + 2 * pad
|
|
98
|
+
pos = (pad - bb[0], pad - bb[1])
|
|
99
|
+
im = Image.new('RGBA', (w, h), (0, 0, 0, 0))
|
|
100
|
+
if shadow:
|
|
101
|
+
sh = Image.new('RGBA', (w, h), (0, 0, 0, 0))
|
|
102
|
+
ImageDraw.Draw(sh).text((pos[0], pos[1] + shadow * 0.5), s, font=f, fill=(0, 0, 0, 160), stroke_width=stroke)
|
|
103
|
+
im = Image.alpha_composite(im, sh.filter(ImageFilter.GaussianBlur(shadow)))
|
|
104
|
+
if glow:
|
|
105
|
+
g = Image.new('RGBA', (w, h), (0, 0, 0, 0))
|
|
106
|
+
ImageDraw.Draw(g).text(pos, s, font=f, fill=tuple(glow[0]) + (255,), stroke_width=int(size * 0.04))
|
|
107
|
+
g = g.filter(ImageFilter.GaussianBlur(glow[1]))
|
|
108
|
+
im = Image.alpha_composite(Image.alpha_composite(im, g), g)
|
|
109
|
+
ImageDraw.Draw(im).text(pos, s, font=f, fill=tuple(fill) + (255,), stroke_width=stroke, stroke_fill=tuple(stroke_fill) + (255,))
|
|
110
|
+
return im
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def fit_text(s, max_w, kind='bold', start=400, **kw):
|
|
114
|
+
size = start
|
|
115
|
+
while size > 10 and font(kind, size).getlength(s) > max_w: size = int(size * 0.92)
|
|
116
|
+
return text_img(s, size, kind, **kw)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def rrect(w, h, r, fill, outline=None, width=0):
|
|
120
|
+
im = Image.new('RGBA', (int(w), int(h)), (0, 0, 0, 0))
|
|
121
|
+
ImageDraw.Draw(im).rounded_rectangle([0, 0, int(w) - 1, int(h) - 1], int(r), fill=fill, outline=outline, width=width)
|
|
122
|
+
return im
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def shadowed(im, blur=18, dy=10, alpha=120):
|
|
126
|
+
pad = blur * 2 + abs(dy)
|
|
127
|
+
out = Image.new('RGBA', (im.width + 2 * pad, im.height + 2 * pad), (0, 0, 0, 0))
|
|
128
|
+
a = im.split()[3].point(lambda v: v * alpha // 255)
|
|
129
|
+
sh = Image.new('RGBA', im.size, (0, 0, 0, 255)); sh.putalpha(a)
|
|
130
|
+
out.paste(sh, (pad, pad + dy), sh)
|
|
131
|
+
out = out.filter(ImageFilter.GaussianBlur(blur))
|
|
132
|
+
out.alpha_composite(im, (pad, pad))
|
|
133
|
+
return out
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def to_np(im): return np.asarray(im.convert('RGBA'), dtype=np.float32) / 255.0
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def comp(c, layer, x, y, alpha=1.0, behind=False, guard=False):
|
|
140
|
+
"""Alpha-composite an RGBA layer with its top-left at (x, y).
|
|
141
|
+
behind=True hides it wherever the person is (so it sits behind you).
|
|
142
|
+
guard=True only hides it where it would cover your face."""
|
|
143
|
+
L = to_np(layer) if isinstance(layer, Image.Image) else layer
|
|
144
|
+
h, w = L.shape[:2]; x, y = int(round(x)), int(round(y))
|
|
145
|
+
x0, y0, x1, y1 = max(0, x), max(0, y), min(c.W, x + w), min(c.H, y + h)
|
|
146
|
+
if x1 <= x0 or y1 <= y0 or alpha <= 0: return
|
|
147
|
+
L = L[y0 - y:y1 - y, x0 - x:x1 - x]
|
|
148
|
+
a = L[..., 3:4] * alpha
|
|
149
|
+
m = c.m[y0:y1, x0:x1, None]
|
|
150
|
+
if behind: a = a * (1 - m)
|
|
151
|
+
elif guard:
|
|
152
|
+
yy, xx = np.ogrid[y0:y1, x0:x1]
|
|
153
|
+
e = ((xx - c.fx) / (c.fw * 0.95)) ** 2 + ((yy - c.fy) / (c.fw * 1.35)) ** 2
|
|
154
|
+
a = a * (1 - np.clip((1.2 - e) / 0.3, 0, 1)[..., None] * m)
|
|
155
|
+
dst = c.img[y0:y1, x0:x1]
|
|
156
|
+
dst[:] = dst * (1 - a) + L[..., :3] * a
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def place(c, im, cx, cy, scale=1.0, rot=0.0, alpha=1.0, behind=False, guard=False):
|
|
160
|
+
"""Draw a PIL image centred on (cx, cy), scaled and rotated (degrees, counter-clockwise)."""
|
|
161
|
+
if scale <= 0.01 or alpha <= 0: return
|
|
162
|
+
if abs(scale - 1) > 0.005:
|
|
163
|
+
im = im.resize((max(1, int(im.width * scale)), max(1, int(im.height * scale))), Image.BILINEAR)
|
|
164
|
+
if abs(rot) > 0.05: im = im.rotate(rot, Image.BICUBIC, expand=True)
|
|
165
|
+
comp(c, im, cx - im.width / 2, cy - im.height / 2, alpha, behind, guard)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def camera(c, zoom, cx, cy):
|
|
169
|
+
"""Zoom the whole frame (and the person mask) towards (cx, cy). Capped at 2x so it stays sharp."""
|
|
170
|
+
zoom = min(zoom, 2.0)
|
|
171
|
+
if zoom <= 1.002: return
|
|
172
|
+
cw, ch = c.W / zoom, c.H / zoom
|
|
173
|
+
x0 = clamp(cx - cw / 2, 0, c.W - cw); y0 = clamp(cy - ch / 2, 0, c.H - ch)
|
|
174
|
+
M = np.float32([[zoom, 0, -x0 * zoom], [0, zoom, -y0 * zoom]])
|
|
175
|
+
c.img = cv2.warpAffine(c.img, M, (c.W, c.H), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REFLECT)
|
|
176
|
+
c.m = cv2.warpAffine(c.m, M, (c.W, c.H), flags=cv2.INTER_LINEAR)
|
|
177
|
+
c.fx, c.fy, c.fw = (c.fx - x0) * zoom, (c.fy - y0) * zoom, c.fw * zoom
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def face_cam(c, zoom, head_at=0.40):
|
|
181
|
+
"""Zoom on the face, keeping it at `head_at` of the frame height."""
|
|
182
|
+
z = min(zoom, 2.0)
|
|
183
|
+
camera(c, z, c.fx, c.fy + (c.H / z) * (0.5 - head_at))
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def grade(img, kind='moody'):
|
|
187
|
+
lum = (img @ np.float32([0.299, 0.587, 0.114]))[..., None]
|
|
188
|
+
if kind == 'bw':
|
|
189
|
+
g = np.clip((lum - 0.5) * 1.25 + 0.5, 0, 1); return np.repeat(g, 3, axis=2)
|
|
190
|
+
if kind == 'warm': return np.clip(img * np.float32([1.08, 1.0, 0.86]) + 0.02, 0, 1)
|
|
191
|
+
if kind == 'cool': return np.clip(img * np.float32([0.9, 1.0, 1.1]), 0, 1)
|
|
192
|
+
if kind == 'pop':
|
|
193
|
+
o = lum + (img - lum) * 1.35; return np.clip((o - 0.5) * 1.12 + 0.5, 0, 1)
|
|
194
|
+
# moody: a little darker, softer colour, teal shadows, warm highlights, gentle contrast
|
|
195
|
+
o = lum + (img - lum) * 0.6
|
|
196
|
+
o = np.power(np.clip(o, 0, 1), 1.3) * 0.88
|
|
197
|
+
o = o + (1 - lum) * np.float32([-0.03, 0.035, 0.065]) + lum * np.float32([0.05, 0.015, -0.04])
|
|
198
|
+
o = np.clip((o - 0.42) * 1.12 + 0.42, 0, 1)
|
|
199
|
+
return o
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
_vig = {}
|
|
203
|
+
def vignette(c, strength=0.35):
|
|
204
|
+
k = (c.W, c.H)
|
|
205
|
+
if k not in _vig:
|
|
206
|
+
yy, xx = np.ogrid[0:c.H, 0:c.W]
|
|
207
|
+
d = ((xx - c.W / 2) / (c.W * 0.75)) ** 2 + ((yy - c.H / 2) / (c.H * 0.7)) ** 2
|
|
208
|
+
_vig[k] = np.clip(d, 0, 1).astype(np.float32)
|
|
209
|
+
c.img *= (1 - strength * _vig[k])[..., None]
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def card(im, w, radius=0.07):
|
|
213
|
+
"""A reel-shaped (9:16) rounded card with a soft shadow."""
|
|
214
|
+
h = int(w * 16 / 9)
|
|
215
|
+
src = im.convert('RGB'); sw, sh = src.size
|
|
216
|
+
s = max(w / sw, h / sh)
|
|
217
|
+
src = src.resize((max(w, int(sw * s)), max(h, int(sh * s))), Image.LANCZOS)
|
|
218
|
+
l, t = (src.width - w) // 2, (src.height - h) // 2
|
|
219
|
+
src = src.crop((l, t, l + w, t + h)).convert('RGBA')
|
|
220
|
+
m = Image.new('L', (w, h), 0); ImageDraw.Draw(m).rounded_rectangle([0, 0, w - 1, h - 1], int(w * radius), fill=255)
|
|
221
|
+
src.putalpha(m)
|
|
222
|
+
ImageDraw.Draw(src).rounded_rectangle([0, 0, w - 1, h - 1], int(w * radius), outline=(0, 0, 0, 70), width=2)
|
|
223
|
+
return shadowed(src, blur=max(6, w // 16), dy=w // 22, alpha=150)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def vary(im, i):
|
|
227
|
+
"""Give each card its own look, so a pile of frames reads as different reels."""
|
|
228
|
+
kind = ('pop', 'bw', 'warm', 'cool', 'moody')[i % 5]
|
|
229
|
+
a = np.asarray(im.convert('RGB'), np.float32) / 255
|
|
230
|
+
return Image.fromarray((grade(a, kind) * 255).astype(np.uint8))
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def cached(e, key, fn):
|
|
234
|
+
if key not in e.state: e.state[key] = fn()
|
|
235
|
+
return e.state[key]
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
# ---------- the 22 effects ----------
|
|
239
|
+
@effect('noise', 'reels pile up behind your head, one every quarter second')
|
|
240
|
+
def fx_noise(c, e):
|
|
241
|
+
cw = int(c.W * float(e.o.get('size', 0.34)))
|
|
242
|
+
def setup():
|
|
243
|
+
rnd = random.Random(7); n = min(16, max(4, int(e.d / 0.22)))
|
|
244
|
+
return [(rnd.uniform(0.14, 0.86), rnd.uniform(0.12, 0.52), rnd.uniform(-7, 7)) for _ in range(n)]
|
|
245
|
+
pos = cached(e, 'pos', setup)
|
|
246
|
+
cards = cached(e, 'cards', lambda: [card(vary(im, i) if e.o.get('images') is None else im, cw) for i, im in enumerate(e.cards)])
|
|
247
|
+
out = clamp((e.d - c.lt) / 0.2)
|
|
248
|
+
for i, (x, y, r) in enumerate(pos):
|
|
249
|
+
t0 = i * 0.22
|
|
250
|
+
if c.lt < t0: break
|
|
251
|
+
k = ease_back((c.lt - t0) / 0.25)
|
|
252
|
+
place(c, cards[i % len(cards)], x * c.W, y * c.H, 0.6 + 0.4 * k, r, clamp((c.lt - t0) / 0.08) * out, behind=True)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@effect('lineup', 'numbered tiles fan out in an arc above your head')
|
|
256
|
+
def fx_lineup(c, e):
|
|
257
|
+
names = e.o.get('text', '|'.join(NAMES)).split('|')
|
|
258
|
+
tw = int(c.W * 0.105)
|
|
259
|
+
def tile(i, name):
|
|
260
|
+
im = rrect(tw, int(tw * 1.25), tw * 0.16, (24, 24, 28, 225), (255, 255, 255, 60), 2)
|
|
261
|
+
d = ImageDraw.Draw(im)
|
|
262
|
+
num = text_img(f'{i + 1:02d}', tw * 0.42, 'serif', CREAM)
|
|
263
|
+
im.alpha_composite(num, ((tw - num.width) // 2, int(tw * 0.04)))
|
|
264
|
+
words = name.split(' ')
|
|
265
|
+
lines = [' '.join(words[:len(words) // 2 or 1]), ' '.join(words[len(words) // 2 or 1:])] if len(name) > 10 else [name]
|
|
266
|
+
f = font('ui', tw * 0.15)
|
|
267
|
+
for j, ln in enumerate([l for l in lines if l]):
|
|
268
|
+
d.text((tw / 2, tw * (0.78 + 0.19 * j)), ln, font=f, fill=(255, 255, 255, 235), anchor='mm')
|
|
269
|
+
return shadowed(im, 8, 5, 90)
|
|
270
|
+
tiles = cached(e, 'tiles', lambda: [tile(i, n) for i, n in enumerate(names)])
|
|
271
|
+
n = len(tiles); outer = math.ceil(n / 2 + 0.5); inner = n - outer
|
|
272
|
+
cx, cy = c.W / 2 * 0.6 + c.fx * 0.4, c.fy + c.fw * 0.3
|
|
273
|
+
slots = []
|
|
274
|
+
for row, cnt, R in ((0, outer, c.W * 0.47), (1, inner, c.W * 0.33)):
|
|
275
|
+
for k in range(cnt):
|
|
276
|
+
a = math.pi * (0.94 - 0.88 * k / max(1, cnt - 1))
|
|
277
|
+
slots.append((cx + R * math.cos(a), cy - R * math.sin(a) * 1.05, math.degrees(a - math.pi / 2) * 0.3))
|
|
278
|
+
out = clamp((e.d - c.lt) / 0.2)
|
|
279
|
+
for i, (x, y, r) in enumerate(slots[:n]):
|
|
280
|
+
t0 = 0.035 * i
|
|
281
|
+
if c.lt < t0: continue
|
|
282
|
+
k = ease_back((c.lt - t0) / 0.3)
|
|
283
|
+
place(c, tiles[i], x, y + (1 - k) * 40, 0.5 + 0.5 * k, r, clamp((c.lt - t0) / 0.1) * out, behind=True)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
@effect('locked-on', 'corner brackets snap onto your face and the camera follows you')
|
|
287
|
+
def fx_locked_on(c, e):
|
|
288
|
+
face_cam(c, 1 + (float(e.o.get('zoom', 1.35)) - 1) * ease_out(c.lt / 0.6))
|
|
289
|
+
snap = ease_out(c.lt / 0.22); s = c.fw * 0.85 * (1 + 0.6 * (1 - snap))
|
|
290
|
+
al = clamp(c.lt / 0.12) * clamp((e.d - c.lt) / 0.2)
|
|
291
|
+
size = int(2 * s + 40); im = Image.new('RGBA', (size, int(size * 1.25)), (0, 0, 0, 0)); d = ImageDraw.Draw(im)
|
|
292
|
+
x0, y0, x1, y1 = 20, 20, size - 20, im.height - 20; L = int(s * 0.32); wd = max(4, int(c.W / 200))
|
|
293
|
+
for (px, py, dx, dy) in ((x0, y0, 1, 1), (x1, y0, -1, 1), (x0, y1, 1, -1), (x1, y1, -1, -1)):
|
|
294
|
+
d.line([(px, py + dy * L), (px, py), (px + dx * L, py)], fill=(255, 255, 255, 255), width=wd, joint='curve')
|
|
295
|
+
place(c, shadowed(im, 6, 2, 120), c.fx, c.fy, alpha=al)
|
|
296
|
+
tag = text_img(e.o.get('text', 'LOCKED ON').upper(), c.W * 0.022, 'mono', INK)
|
|
297
|
+
pill = rrect(tag.width + 10, tag.height, tag.height / 2, (255, 255, 255, 235)); pill.alpha_composite(tag, (5, 0))
|
|
298
|
+
place(c, pill, c.fx, c.fy + s * 1.25 + pill.height, alpha=clamp((c.lt - 0.15) / 0.15) * al, guard=True)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
@effect('orbit', 'your reels circle your head: in front at the bottom, behind you at the top')
|
|
302
|
+
def fx_orbit(c, e):
|
|
303
|
+
K = int(e.o.get('count', 6)); cw = int(c.W * float(e.o.get('size', 0.2)))
|
|
304
|
+
cards = cached(e, 'cards', lambda: [card(vary(im, i) if e.o.get('images') is None else im, cw) for i, im in enumerate(e.cards)])
|
|
305
|
+
intro, out = ease_out(c.lt / 0.4), clamp((e.d - c.lt) / 0.25)
|
|
306
|
+
rx, ry = c.W * 0.38 * intro, max(c.fw * 1.5, c.H * 0.1)
|
|
307
|
+
oy = c.fy + c.fw * 0.9
|
|
308
|
+
items = []
|
|
309
|
+
for i in range(K):
|
|
310
|
+
th = i * 2 * math.pi / K + c.lt * float(e.o.get('speed', 1.9))
|
|
311
|
+
items.append((math.sin(th), th, i))
|
|
312
|
+
for depth, th, i in sorted(items):
|
|
313
|
+
place(c, cards[i % len(cards)], c.fx + rx * math.cos(th), oy + ry * math.sin(th), (0.78 + 0.24 * (depth + 1) / 2) * (0.5 + 0.5 * intro),
|
|
314
|
+
-6 * math.cos(th), out * clamp(c.lt / 0.15), behind=depth < 0, guard=depth >= 0)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
@effect('lean-in', 'a fast punch-in on one word')
|
|
318
|
+
def fx_lean_in(c, e):
|
|
319
|
+
z = float(e.o.get('zoom', 1.45))
|
|
320
|
+
face_cam(c, 1 + (z - 1) * ease_out(c.lt / float(e.o.get('speed', 0.18))), 0.42)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
@effect('backdrop-word', 'a giant word drops in behind you')
|
|
324
|
+
def fx_backdrop_word(c, e):
|
|
325
|
+
word = e.o.get('text', 'CLAUDE')
|
|
326
|
+
im = cached(e, 'w', lambda: fit_text(word, c.W * 0.94, e.o.get('font', 'bold'), fill=rgb(e.o.get('color'), CREAM), shadow=10))
|
|
327
|
+
k = ease_back(c.lt / 0.42)
|
|
328
|
+
y_end = c.fy - c.fw * 1.05
|
|
329
|
+
y = -im.height + (y_end + im.height) * k
|
|
330
|
+
place(c, im, c.W / 2 * 0.6 + c.fx * 0.4, y, alpha=clamp((e.d - c.lt) / 0.2), behind=True)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
_grid = {}
|
|
334
|
+
def grid(c):
|
|
335
|
+
if (c.W, c.H) not in _grid:
|
|
336
|
+
yy, xx = np.mgrid[0:c.H, 0:c.W].astype(np.float32); _grid[(c.W, c.H)] = (xx, yy)
|
|
337
|
+
return _grid[(c.W, c.H)]
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
@effect('spotlight', 'kill the lights, keep you lit')
|
|
341
|
+
def fx_spotlight(c, e):
|
|
342
|
+
if e.o.get('look') == 'sparkle': return spotlight_sparkle(c, e)
|
|
343
|
+
face_cam(c, 1 + (float(e.o.get('push', 1.1)) - 1) * ease_inout(c.lt / e.d))
|
|
344
|
+
k = ramp(c, e, 0.3, 0.25)
|
|
345
|
+
xx, yy = grid(c)
|
|
346
|
+
d = ((xx - c.fx) / (c.W * 0.5)) ** 2 + ((yy - (c.fy + c.H * 0.2)) / (c.H * 0.46)) ** 2
|
|
347
|
+
pool = np.clip(1 - d, 0, 1) ** 1.6
|
|
348
|
+
bright = 1 - k * (1 - (0.2 + 0.45 * pool))
|
|
349
|
+
f = bright * (1 - c.m) + c.m * (1 + 0.04 * k)
|
|
350
|
+
if e.o.get('text'):
|
|
351
|
+
word = e.o['text']; col = rgb(e.o.get('color'), PEACH)
|
|
352
|
+
im = cached(e, 'w', lambda: fit_text(word, c.W * 0.9, e.o.get('font', 'serif'), fill=col, glow=(col, 26)))
|
|
353
|
+
c.img *= f[..., None]
|
|
354
|
+
place(c, im, c.W / 2, c.fy - c.fw * 1.1, alpha=k, behind=True)
|
|
355
|
+
else:
|
|
356
|
+
c.img *= f[..., None]
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
@effect('the-bill', 'prints every instruction like a ticket, into the wall above your head')
|
|
360
|
+
def fx_bill(c, e):
|
|
361
|
+
lines = e.o.get('text', 'ORDER #1021|1x orbit|1x spotlight|1x lean-in|cut the dead air|TOTAL: 1 prompt').split('|')
|
|
362
|
+
def build():
|
|
363
|
+
pw = int(c.W * 0.5); lh = int(pw * 0.085); pad = int(pw * 0.08)
|
|
364
|
+
h = pad * 2 + lh * (len(lines) + 1)
|
|
365
|
+
im = Image.new('RGBA', (pw, h), CREAM + (255,)); d = ImageDraw.Draw(im)
|
|
366
|
+
f = font('mono', lh * 0.62)
|
|
367
|
+
for i, ln in enumerate(lines):
|
|
368
|
+
y = pad + lh * i + (lh if i == len(lines) - 1 else 0)
|
|
369
|
+
if i == len(lines) - 1:
|
|
370
|
+
for x in range(pad, pw - pad, 14): d.line([(x, y - lh * 0.45), (x + 7, y - lh * 0.45)], fill=INK + (140,), width=2)
|
|
371
|
+
d.text((pad, y), ln, font=f, fill=INK + (255,))
|
|
372
|
+
return im
|
|
373
|
+
rec = cached(e, 'r', build)
|
|
374
|
+
slot_y, sw = c.H * 0.075, c.W * 0.62
|
|
375
|
+
max_h = max(80, c.fy - c.fw * 1.3 - slot_y)
|
|
376
|
+
s = min(1.0, max_h / rec.height)
|
|
377
|
+
pr = ease_inout(c.lt / (e.d * 0.75)); L = int(rec.height * pr)
|
|
378
|
+
al = clamp((e.d - c.lt) / 0.25)
|
|
379
|
+
cx = c.W / 2
|
|
380
|
+
if L > 2:
|
|
381
|
+
paper = rec.crop((0, 0, rec.width, L))
|
|
382
|
+
z = 14; jag = Image.new('RGBA', (rec.width, L + z), (0, 0, 0, 0)); jag.paste(paper, (0, 0))
|
|
383
|
+
ImageDraw.Draw(jag).polygon([(x, L) for x in range(0, rec.width + 1, 2 * z)] + [(rec.width, L)] +
|
|
384
|
+
[(x + z, L + z) for x in range(rec.width - 2 * z, -1, -2 * z)], fill=CREAM + (255,))
|
|
385
|
+
paper = shadowed(jag, 10, 6, 90)
|
|
386
|
+
if s < 1: paper = paper.resize((int(paper.width * s), int(paper.height * s)), Image.BILINEAR)
|
|
387
|
+
comp(c, paper, cx - paper.width / 2, slot_y - 10 * s, al, behind=True)
|
|
388
|
+
slot = rrect(sw, c.H * 0.03, c.H * 0.015, (30, 30, 34, 255), (90, 90, 96, 255), 3)
|
|
389
|
+
place(c, shadowed(slot, 10, 6, 140), cx, slot_y, alpha=al * clamp(c.lt / 0.15), behind=True)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
@effect('moody', 'a moody colour grade: darker, softer, teal shadows')
|
|
393
|
+
def fx_moody(c, e):
|
|
394
|
+
k = ramp(c, e, 0.35, 0)
|
|
395
|
+
c.img = c.img * (1 - k) + grade(c.img, e.o.get('grade', 'moody')) * k
|
|
396
|
+
vignette(c, 0.4 * k)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
@effect('swipe', 'a before and after slider that sweeps across you')
|
|
400
|
+
def fx_swipe(c, e):
|
|
401
|
+
after = grade(c.img, e.o.get('grade', 'moody'))
|
|
402
|
+
p = c.lt / e.d
|
|
403
|
+
sp = 1.05 - 0.95 * ease_inout(p / 0.5) if p < 0.5 else 0.1 + 0.4 * ease_inout((p - 0.5) / 0.4)
|
|
404
|
+
xx, yy = grid(c)
|
|
405
|
+
line = sp * c.W + 0.22 * (yy - c.H / 2)
|
|
406
|
+
a = np.clip((xx - line) / 3 + 0.5, 0, 1)[..., None]
|
|
407
|
+
c.img = c.img * (1 - a) + after * a
|
|
408
|
+
hy = c.H * 0.62; hx = sp * c.W + 0.22 * (hy - c.H / 2)
|
|
409
|
+
edge = np.clip(1 - np.abs(xx - line) / 3.5, 0, 1)[..., None]
|
|
410
|
+
c.img = c.img * (1 - edge) + edge
|
|
411
|
+
r = int(c.W * 0.035); h = Image.new('RGBA', (2 * r + 4, 2 * r + 4), (0, 0, 0, 0)); d = ImageDraw.Draw(h)
|
|
412
|
+
d.ellipse([2, 2, 2 * r + 2, 2 * r + 2], fill=(255, 255, 255, 255))
|
|
413
|
+
d.text((r + 2, r + 2), '< >', font=font('mono', r * 0.7), fill=INK + (255,), anchor='mm')
|
|
414
|
+
place(c, shadowed(h, 8, 4, 110), hx, hy)
|
|
415
|
+
for lab, x in (('before', 0.14), ('after', 0.86)):
|
|
416
|
+
t = text_img(lab, c.W * 0.03, 'serif', INK); pill = rrect(t.width + 16, t.height, t.height / 2, (255, 255, 255, 225))
|
|
417
|
+
pill.alpha_composite(t, (8, 0)); place(c, pill, c.W * x, c.H * 0.88)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
@effect('todo', 'a checklist card beside your head that ticks off as you talk')
|
|
421
|
+
def fx_todo(c, e):
|
|
422
|
+
items = e.o.get('text', 'drop your video into Claude|install the skill|type /effects').split('|')
|
|
423
|
+
# ticks = video seconds when each item gets ticked (e.g. when you say it); default is evenly spaced
|
|
424
|
+
ticks = [float(t) - e.start for t in str(e.o['ticks']).split('|')] if e.o.get('ticks') else [e.d * (i + 1) / (len(items) + 1) for i in range(len(items))]
|
|
425
|
+
cw = int(c.W * 0.5); lh = int(cw * 0.13); pad = int(cw * 0.07)
|
|
426
|
+
im = rrect(cw, pad * 2 + lh * (len(items) + 1), cw * 0.07, (250, 248, 242, 235)); d = ImageDraw.Draw(im)
|
|
427
|
+
done = sum(c.lt >= t for t in ticks)
|
|
428
|
+
d.text((pad, pad), e.o.get('title', 'TO DO').upper(), font=font('ui', lh * 0.42), fill=(200, 140, 20, 255))
|
|
429
|
+
d.text((cw - pad, pad), f'{done} of {len(items)}', font=font('ui', lh * 0.36), fill=(120, 120, 120, 255), anchor='ra')
|
|
430
|
+
f = font('ui', lh * 0.4)
|
|
431
|
+
for i, it in enumerate(items):
|
|
432
|
+
y = pad + lh * (i + 1); bx = lh * 0.42
|
|
433
|
+
d.rounded_rectangle([pad, y + lh * 0.12, pad + bx, y + lh * 0.12 + bx], 6, outline=(160, 160, 160, 255), width=3)
|
|
434
|
+
d.text((pad + bx * 1.5, y + lh * 0.1), it, font=f, fill=INK + (255,))
|
|
435
|
+
if c.lt >= ticks[i]:
|
|
436
|
+
k = ease_out((c.lt - ticks[i]) / 0.25)
|
|
437
|
+
d.rounded_rectangle([pad, y + lh * 0.12, pad + bx, y + lh * 0.12 + bx], 6, fill=(52, 199, 89, 255))
|
|
438
|
+
d.line([(pad + bx * .22, y + lh * .12 + bx * .52), (pad + bx * .42, y + lh * .12 + bx * .74), (pad + bx * .8, y + lh * .12 + bx * .28)], fill=(255, 255, 255, 255), width=4)
|
|
439
|
+
tw = f.getlength(it) * k
|
|
440
|
+
d.line([(pad + bx * 1.5, y + lh * 0.36), (pad + bx * 1.5 + tw, y + lh * 0.36)], fill=INK + (255,), width=3)
|
|
441
|
+
left = c.fx > c.W / 2
|
|
442
|
+
x = c.W * 0.05 + cw / 2 if left else c.W * 0.95 - cw / 2
|
|
443
|
+
pop = ease_back(c.lt / 0.3)
|
|
444
|
+
place(c, shadowed(im, 14, 8, 90), x, max(im.height / 2 + c.H * 0.06, c.fy - c.fw * 1.4), 0.8 + 0.2 * pop, 0, clamp(c.lt / 0.12) * clamp((e.d - c.lt) / 0.2), behind=True)
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
def heart(size, color=(255, 48, 64)):
|
|
448
|
+
s = int(size); im = Image.new('RGBA', (s, s), (0, 0, 0, 0)); d = ImageDraw.Draw(im)
|
|
449
|
+
pts = [(s / 2 + s * 0.48 * (16 * math.sin(t) ** 3) / 16, s * 0.46 - s * 0.46 * (13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t)) / 16)
|
|
450
|
+
for t in np.linspace(0, 2 * math.pi, 60)]
|
|
451
|
+
d.polygon(pts, fill=color + (255,)); return im
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def comment_bar(c, e):
|
|
455
|
+
word = e.o.get('text', 'EFFECTS')
|
|
456
|
+
bw, bh = int(c.W * 0.9), int(c.W * 0.11)
|
|
457
|
+
slide = ease_out(c.lt / 0.3); y = c.H * 0.8 + (1 - slide) * c.H * 0.25
|
|
458
|
+
type_t, post_t = 0.35, 0.35 + 0.08 * len(word) + 0.25
|
|
459
|
+
typed = word[:int(clamp((c.lt - type_t) / (0.08 * len(word))) * len(word) + 0.001)] if c.lt < post_t else ''
|
|
460
|
+
im = rrect(bw, bh, bh / 2, (255, 255, 255, 245)); d = ImageDraw.Draw(im)
|
|
461
|
+
r = bh * 0.32; d.ellipse([bh * 0.2, bh / 2 - r, bh * 0.2 + 2 * r, bh / 2 + r], fill=(214, 41, 118, 255))
|
|
462
|
+
f = font('ui', bh * 0.3)
|
|
463
|
+
if typed: d.text((bh * 0.95, bh / 2), typed + ('|' if int(c.lt * 4) % 2 else ''), font=f, fill=INK + (255,), anchor='lm')
|
|
464
|
+
elif c.lt < post_t: d.text((bh * 0.95, bh / 2), 'Add a comment...', font=f, fill=(150, 150, 150, 255), anchor='lm')
|
|
465
|
+
d.text((bw - bh * 0.4, bh / 2), 'Post', font=f, fill=((0, 149, 246, 255) if typed else (180, 210, 240, 255)), anchor='rm')
|
|
466
|
+
al = clamp((e.d - c.lt) / 0.2)
|
|
467
|
+
place(c, shadowed(im, 14, 6, 100), c.W / 2, y, alpha=al, guard=True)
|
|
468
|
+
if c.lt >= post_t:
|
|
469
|
+
k = ease_back((c.lt - post_t) / 0.3)
|
|
470
|
+
b = rrect(int(c.W * 0.52), int(bh * 0.85), bh * 0.3, (255, 255, 255, 240)); bd = ImageDraw.Draw(b)
|
|
471
|
+
bd.text((bh * 0.3, b.height * 0.32), 'you', font=font('ui', bh * 0.2), fill=(120, 120, 120, 255), anchor='lm')
|
|
472
|
+
bd.text((bh * 0.3, b.height * 0.66), word, font=font('ui', bh * 0.3), fill=INK + (255,), anchor='lm')
|
|
473
|
+
hk = ease_back((c.lt - post_t - 0.3) / 0.3)
|
|
474
|
+
if hk > 0:
|
|
475
|
+
hh = heart(bh * 0.4 * hk); b.alpha_composite(hh, (int(b.width - bh * 0.3 - hh.width), int(b.height / 2 - hh.height / 2)))
|
|
476
|
+
place(c, shadowed(b, 12, 5, 90), c.W * 0.07 + b.width / 2, y - bh * 1.05, 0.7 + 0.3 * k, 0, al * clamp((c.lt - post_t) / 0.1), guard=True)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
@effect('tap', 'a Follow button pops up and flips to Following')
|
|
480
|
+
def fx_tap(c, e):
|
|
481
|
+
at = float(e.o['at']) - e.start if 'at' in e.o else e.d * 0.45 # 'at' = video second of the tap
|
|
482
|
+
bw, bh = int(c.W * 0.3), int(c.W * 0.09)
|
|
483
|
+
x = clamp(float(e.o['x']) * c.W if 'x' in e.o else c.fx + c.fw * 1.9, bw / 2 + 30, c.W - bw / 2 - 30)
|
|
484
|
+
y = clamp(float(e.o['y']) * c.H if 'y' in e.o else c.fy + c.fw * 1.6, bh + 30, c.H - bh - 30)
|
|
485
|
+
on = c.lt >= at
|
|
486
|
+
col = rgb(e.o.get('color'), (124, 92, 255)) if on else (0, 149, 246)
|
|
487
|
+
im = rrect(bw, bh, bh * 0.28, col + (255,)); d = ImageDraw.Draw(im)
|
|
488
|
+
d.text((bw / 2, bh / 2), 'Following' if on else '+ Follow', font=font('ui', bh * 0.4), fill=(255, 255, 255, 255), anchor='mm')
|
|
489
|
+
pop = ease_back(c.lt / 0.3)
|
|
490
|
+
sq = 1.0
|
|
491
|
+
if on: q = (c.lt - at) / 0.3; sq = 1 - 0.12 * math.sin(math.pi * clamp(q)) if q < 1 else 1
|
|
492
|
+
place(c, shadowed(im, 12, 6, 110), x, y, (0.6 + 0.4 * pop) * sq, 0, clamp(c.lt / 0.1) * clamp((e.d - c.lt) / 0.2), guard=True)
|
|
493
|
+
if on and c.lt - at < 0.4:
|
|
494
|
+
q = (c.lt - at) / 0.4; r = int(bh * (0.3 + 0.9 * q)); ring = Image.new('RGBA', (2 * r + 8, 2 * r + 8), (0, 0, 0, 0))
|
|
495
|
+
ImageDraw.Draw(ring).ellipse([4, 4, 2 * r + 4, 2 * r + 4], outline=(255, 255, 255, int(220 * (1 - q))), width=5)
|
|
496
|
+
place(c, ring, x, y, guard=True)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def hand_path(d, pts, color, width, frac):
|
|
500
|
+
n = max(2, int(len(pts) * clamp(frac)))
|
|
501
|
+
if frac > 0: d.line(pts[:n], fill=color, width=width, joint='curve')
|
|
502
|
+
return pts[n - 1]
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
def arrow_pts(x0, y0, x1, y1, bend=0.25, n=40):
|
|
506
|
+
mx, my = (x0 + x1) / 2 - (y1 - y0) * bend, (y0 + y1) / 2 + (x1 - x0) * bend
|
|
507
|
+
return [((1 - t) ** 2 * x0 + 2 * (1 - t) * t * mx + t * t * x1, (1 - t) ** 2 * y0 + 2 * (1 - t) * t * my + t * t * y1) for t in np.linspace(0, 1, n)]
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
def arrow_head(d, pts, color, width, size):
|
|
511
|
+
(xa, ya), (xb, yb) = pts[-4], pts[-1]; a = math.atan2(yb - ya, xb - xa)
|
|
512
|
+
for s in (2.6, -2.6):
|
|
513
|
+
d.line([(xb, yb), (xb + size * math.cos(a + s), yb + size * math.sin(a + s))], fill=color, width=width)
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
@effect('pause-point', 'freeze the frame and point at something with a hand-drawn arrow')
|
|
517
|
+
def fx_pause_point(c, e):
|
|
518
|
+
if 'f' not in e.state: e.state['f'] = (c.img.copy(), c.m.copy(), c.fx, c.fy, c.fw)
|
|
519
|
+
img, m, c.fx, c.fy, c.fw = e.state['f']; c.img, c.m = img.copy(), m
|
|
520
|
+
face_cam(c, 1 + 0.06 * ease_out(c.lt / e.d), 0.4)
|
|
521
|
+
c.img = c.img * 0.92 + grade(c.img, 'bw') * 0.08
|
|
522
|
+
col = rgb(e.o.get('color'), YELLOW) + (255,)
|
|
523
|
+
lay = Image.new('RGBA', (c.W, c.H), (0, 0, 0, 0)); d = ImageDraw.Draw(lay)
|
|
524
|
+
d.rounded_rectangle([c.W * 0.05, c.H * 0.06, c.W * 0.05 + c.W * 0.1, c.H * 0.06 + c.W * 0.1], 16, fill=(0, 0, 0, 150))
|
|
525
|
+
for bx in (0.075, 0.11): d.rectangle([c.W * bx, c.H * 0.06 + c.W * 0.025, c.W * (bx + 0.017), c.H * 0.06 + c.W * 0.075], fill=(255, 255, 255, 230))
|
|
526
|
+
tx, ty = c.W * float(e.o.get('label_x', 0.72)), c.fy - c.fw * 2.2
|
|
527
|
+
pts = arrow_pts(tx - c.W * 0.05, ty + c.W * 0.06, c.fx + c.fw * 0.75, c.fy - c.fw * 0.35, 0.3)
|
|
528
|
+
k = ease_out((c.lt - 0.15) / 0.4)
|
|
529
|
+
hand_path(d, pts, col, max(6, c.W // 140), k)
|
|
530
|
+
if k >= 0.99: arrow_head(d, pts, col, max(6, c.W // 140), c.W * 0.04)
|
|
531
|
+
comp(c, to_np(lay), 0, 0)
|
|
532
|
+
lab = text_img(e.o.get('text', 'look here'), c.W * 0.07, 'hand', col[:3], shadow=6)
|
|
533
|
+
place(c, lab, tx, ty - lab.height * 0.2, 0.7 + 0.3 * ease_back(c.lt / 0.3), -6, clamp(c.lt / 0.1), guard=True)
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
@effect('uninstall', 'a glitchy uninstall bar that breaks the frame apart')
|
|
537
|
+
def fx_uninstall(c, e):
|
|
538
|
+
p = clamp(c.lt / e.d); g = p ** 1.6
|
|
539
|
+
rnd = np.random.default_rng(int(c.t * 30))
|
|
540
|
+
sh = int(g * c.W * 0.025)
|
|
541
|
+
if sh: c.img = np.stack([np.roll(c.img[..., 0], sh, 1), c.img[..., 1], np.roll(c.img[..., 2], -sh, 1)], -1)
|
|
542
|
+
for _ in range(int(2 + g * 10)):
|
|
543
|
+
y0 = int(rnd.uniform(0, c.H)); hh = int(rnd.uniform(8, 60)); off = int(rnd.uniform(-1, 1) * g * c.W * 0.08)
|
|
544
|
+
c.img[y0:y0 + hh] = np.roll(c.img[y0:y0 + hh], off, 1)
|
|
545
|
+
if p > 0.82:
|
|
546
|
+
q = (p - 0.82) / 0.18; f = 1 + int(q * 40)
|
|
547
|
+
small = cv2.resize(c.img, (max(1, c.W // f), max(1, c.H // f)), interpolation=cv2.INTER_AREA)
|
|
548
|
+
c.img = cv2.resize(small, (c.W, c.H), interpolation=cv2.INTER_NEAREST) * (1 - 0.6 * q)
|
|
549
|
+
bw, bh = int(c.W * 0.7), int(c.W * 0.2)
|
|
550
|
+
im = rrect(bw, bh, 22, (245, 245, 247, 240)); d = ImageDraw.Draw(im)
|
|
551
|
+
d.text((bw * 0.06, bh * 0.28), e.o.get('text', 'Uninstalling...'), font=font('ui', bh * 0.18), fill=INK + (255,), anchor='lm')
|
|
552
|
+
d.rounded_rectangle([bw * 0.06, bh * 0.56, bw * 0.94, bh * 0.7], 8, fill=(215, 215, 220, 255))
|
|
553
|
+
d.rounded_rectangle([bw * 0.06, bh * 0.56, bw * 0.06 + bw * 0.88 * max(0.03, ease_inout(p)), bh * 0.7], 8, fill=(0, 122, 255, 255))
|
|
554
|
+
d.text((bw * 0.94, bh * 0.85), f'{int(ease_inout(p) * 100)}%', font=font('ui', bh * 0.13), fill=(110, 110, 110, 255), anchor='rm')
|
|
555
|
+
place(c, shadowed(im, 16, 8, 120), c.W / 2, c.H * 0.16, 0.8 + 0.2 * ease_back(c.lt / 0.3), 0, clamp(c.lt / 0.1))
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
def reel_icons(size):
|
|
559
|
+
s = int(size); im = Image.new('RGBA', (s, int(s * 3.6)), (0, 0, 0, 0)); d = ImageDraw.Draw(im); w = max(3, s // 12)
|
|
560
|
+
h = heart(s * 0.8, (255, 255, 255)); im.alpha_composite(h, (int(s * 0.1), 0))
|
|
561
|
+
d.text((s / 2, s * 0.95), '26.9K', font=font('ui', s * 0.24), fill=(255, 255, 255, 255), anchor='mm')
|
|
562
|
+
d.ellipse([s * 0.15, s * 1.25, s * 0.85, s * 1.95], outline=(255, 255, 255, 255), width=w)
|
|
563
|
+
d.text((s / 2, s * 2.15), '412', font=font('ui', s * 0.24), fill=(255, 255, 255, 255), anchor='mm')
|
|
564
|
+
d.polygon([(s * 0.12, s * 2.75), (s * 0.9, s * 2.45), (s * 0.55, s * 3.25), (s * 0.45, s * 2.88)], outline=(255, 255, 255, 255), width=w)
|
|
565
|
+
return im
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
@effect('reel-frame', 'your video shrinks into an Instagram reel card')
|
|
569
|
+
def fx_reel_frame(c, e):
|
|
570
|
+
k = ease_out(c.lt / 0.35) * clamp((e.d - c.lt) / 0.3)
|
|
571
|
+
if k <= 0: return
|
|
572
|
+
s = 1 - 0.2 * k
|
|
573
|
+
small = cv2.resize(c.img, (c.W // 16, c.H // 16), interpolation=cv2.INTER_AREA)
|
|
574
|
+
bg = cv2.GaussianBlur(cv2.resize(small, (c.W, c.H), interpolation=cv2.INTER_LINEAR), (0, 0), 12) * (1 - 0.45 * k)
|
|
575
|
+
iw, ih = int(c.W * s), int(c.H * s)
|
|
576
|
+
inset = cv2.resize(c.img, (iw, ih), interpolation=cv2.INTER_AREA)
|
|
577
|
+
m = to_np(rrect(iw, ih, c.W * 0.05 * k + 1, (255, 255, 255, 255)))[..., 3:4]
|
|
578
|
+
x0, y0 = (c.W - iw) // 2, int((c.H - ih) * 0.42)
|
|
579
|
+
out = bg.copy(); reg = out[y0:y0 + ih, x0:x0 + iw]; reg[:] = reg * (1 - m) + inset * m
|
|
580
|
+
c.img = out
|
|
581
|
+
mm = np.zeros_like(c.m); mm[y0:y0 + ih, x0:x0 + iw] = cv2.resize(c.m, (iw, ih)); c.m = mm
|
|
582
|
+
c.fx, c.fy, c.fw = x0 + c.fx * s, y0 + c.fy * s, c.fw * s
|
|
583
|
+
ic = cached(e, 'ic', lambda: shadowed(reel_icons(c.W * 0.075), 6, 2, 120))
|
|
584
|
+
comp(c, ic, x0 + iw - ic.width - c.W * 0.01, y0 + ih * 0.52, k)
|
|
585
|
+
hdl = text_img(e.o.get('text', PROFILE['handle']), c.W * 0.032, 'ui', (255, 255, 255), shadow=4)
|
|
586
|
+
comp(c, hdl, x0 + c.W * 0.03, y0 + ih - hdl.height - c.W * 0.04, k)
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
@effect('shortcut-rain', 'keyboard keys rain down behind you')
|
|
590
|
+
def fx_shortcut_rain(c, e):
|
|
591
|
+
keys = e.o.get('text', 'cmd|/|C|V|Z|esc|tab|shift|enter|opt').split('|')
|
|
592
|
+
ks = int(c.W * 0.1)
|
|
593
|
+
def cap(k):
|
|
594
|
+
w = max(ks, int(font('mono', ks * 0.36).getlength(k) + ks * 0.5))
|
|
595
|
+
im = rrect(w, ks, ks * 0.18, (190, 190, 198, 255)); top = rrect(w - 8, ks - 14, ks * 0.16, (246, 246, 248, 255))
|
|
596
|
+
im.alpha_composite(top, (4, 3)); ImageDraw.Draw(im).text((w / 2, ks * 0.44), k, font=font('mono', ks * 0.36), fill=INK + (255,), anchor='mm')
|
|
597
|
+
return shadowed(im, 8, 6, 100)
|
|
598
|
+
caps = cached(e, 'caps', lambda: [cap(k) for k in keys])
|
|
599
|
+
parts = cached(e, 'p', lambda: [(random.Random(i).random(), random.Random(i + 99).random() * max(0.1, e.d - 0.8),
|
|
600
|
+
0.45 + 0.4 * random.Random(i + 7).random(), random.Random(i + 3).uniform(-25, 25),
|
|
601
|
+
random.Random(i + 5).uniform(-60, 60)) for i in range(int(e.o.get('count', 26)))])
|
|
602
|
+
for i, (x, t0, v, r0, w) in enumerate(parts):
|
|
603
|
+
if c.lt < t0: continue
|
|
604
|
+
y = -ks + (c.lt - t0) * v * c.H
|
|
605
|
+
place(c, caps[i % len(caps)], c.W * (0.04 + 0.92 * x), y, 0.75 + 0.35 * v, r0 + w * (c.lt - t0), clamp((e.d - c.lt) / 0.2), behind=True)
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
@effect('reject-stamp', 'a big red stamp slams onto the screen')
|
|
609
|
+
def fx_reject_stamp(c, e):
|
|
610
|
+
word = e.o.get('text', 'REJECTED').upper(); col = rgb(e.o.get('color'), (214, 40, 40))
|
|
611
|
+
def build():
|
|
612
|
+
t = fit_text(word, c.W * 0.62, 'bold', 200, fill=col); pad = int(t.height * 0.12)
|
|
613
|
+
im = Image.new('RGBA', (t.width + 4 * pad, t.height + 2 * pad), (0, 0, 0, 0)); d = ImageDraw.Draw(im)
|
|
614
|
+
d.rounded_rectangle([3, 3, im.width - 4, im.height - 4], 18, outline=col + (255,), width=max(6, pad // 2))
|
|
615
|
+
im.alpha_composite(t, (2 * pad, pad))
|
|
616
|
+
a = np.asarray(im.split()[3], np.float32) * np.clip(np.random.default_rng(3).uniform(0.55, 1.6, (im.height, im.width)), 0, 1)
|
|
617
|
+
im.putalpha(Image.fromarray(a.astype(np.uint8)))
|
|
618
|
+
return im
|
|
619
|
+
st = cached(e, 's', build)
|
|
620
|
+
k = clamp(c.lt / 0.16); sc = 2.3 - 1.3 * k * k
|
|
621
|
+
if 0.16 < c.lt < 0.45:
|
|
622
|
+
a = (0.45 - c.lt) / 0.29 * c.W * 0.012; rnd = np.random.default_rng(int(c.t * 30))
|
|
623
|
+
M = np.float32([[1, 0, rnd.uniform(-a, a)], [0, 1, rnd.uniform(-a, a)]])
|
|
624
|
+
c.img = cv2.warpAffine(c.img, M, (c.W, c.H), borderMode=cv2.BORDER_REFLECT)
|
|
625
|
+
y = clamp(float(e.o['y']) * c.H if 'y' in e.o else c.fy + c.fw * 2.7, 0, c.H * 0.85)
|
|
626
|
+
place(c, st, c.W / 2, y, sc, float(e.o.get('angle', 12)), k * clamp((e.d - c.lt) / 0.2), guard=True)
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
@effect('countdown-flip', 'a 3, 2, 1 flip clock above your head')
|
|
630
|
+
def fx_countdown(c, e):
|
|
631
|
+
n0 = int(e.o.get('from', 3)); seg = e.d / n0
|
|
632
|
+
i = min(n0 - 1, int(c.lt / seg)); cur, prev = n0 - i, n0 - i + 1
|
|
633
|
+
f = clamp((c.lt - i * seg) / 0.3) if i > 0 else 1.0
|
|
634
|
+
tw, th = int(c.W * 0.3), int(c.W * 0.38)
|
|
635
|
+
def half(num, top):
|
|
636
|
+
im = rrect(tw, th, tw * 0.1, (30, 30, 34, 255)); d = ImageDraw.Draw(im)
|
|
637
|
+
d.text((tw / 2, th / 2), str(num), font=font('bold', th * 0.62), fill=CREAM + (255,), anchor='mm')
|
|
638
|
+
return im.crop((0, 0, tw, th // 2)) if top else im.crop((0, th // 2, tw, th))
|
|
639
|
+
hv = cached(e, 'h', lambda: {(n, t): half(n, t) for n in range(0, n0 + 2) for t in (True, False)})
|
|
640
|
+
im = Image.new('RGBA', (tw, th), (0, 0, 0, 0))
|
|
641
|
+
im.paste(hv[(cur, True)], (0, 0)); im.paste(hv[(prev if f < 1 else cur, False)], (0, th // 2))
|
|
642
|
+
if f < 0.5:
|
|
643
|
+
h = max(1, int(th / 2 * (1 - 2 * f))); fl = hv[(prev, True)].resize((tw, h)); im.paste(fl, (0, th // 2 - h))
|
|
644
|
+
elif f < 1:
|
|
645
|
+
h = max(1, int(th / 2 * (2 * f - 1))); fl = hv[(cur, False)].resize((tw, h)); im.paste(fl, (0, th // 2))
|
|
646
|
+
ImageDraw.Draw(im).line([(0, th // 2), (tw, th // 2)], fill=(0, 0, 0, 255), width=4)
|
|
647
|
+
y = max(th / 2 + c.H * 0.05, c.fy - c.fw * 2.3)
|
|
648
|
+
place(c, shadowed(im, 16, 10, 120), c.W / 2 * 0.6 + c.fx * 0.4, y, 0.7 + 0.3 * ease_back(c.lt / 0.3), 0, clamp((e.d - c.lt) / 0.2), behind=True)
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
_rect = {}
|
|
652
|
+
@effect('rabbit-hole', 'the frame tunnels into itself, spinning')
|
|
653
|
+
def fx_rabbit_hole(c, e):
|
|
654
|
+
k = ease_out(c.lt / 0.4) * clamp((e.d - c.lt) / 0.3)
|
|
655
|
+
if k <= 0: return
|
|
656
|
+
if (c.W, c.H) not in _rect:
|
|
657
|
+
a = np.ones((c.H, c.W), np.float32); b = np.zeros((c.H, c.W), np.float32); t = max(4, c.W // 120)
|
|
658
|
+
b[:t] = b[-t:] = 1; b[:, :t] = b[:, -t:] = 1; _rect[(c.W, c.H)] = (a, b)
|
|
659
|
+
ones, border = _rect[(c.W, c.H)]
|
|
660
|
+
r = float(e.o.get('ratio', 0.62)); z = (c.lt * float(e.o.get('speed', 0.8))) % 1.0
|
|
661
|
+
src = c.img; cx, cy = c.fx, c.fy
|
|
662
|
+
out = None
|
|
663
|
+
for lev in range(0, 7):
|
|
664
|
+
s = r ** (lev - z * k) if lev else 1.0
|
|
665
|
+
ang = (lev - z) * float(e.o.get('spin', 10)) * k if lev else 0
|
|
666
|
+
if lev and s < 0.03: break
|
|
667
|
+
M = cv2.getRotationMatrix2D((cx, cy), ang, s)
|
|
668
|
+
if lev == 0:
|
|
669
|
+
out = src.copy(); continue
|
|
670
|
+
L = cv2.warpAffine(src, M, (c.W, c.H), flags=cv2.INTER_LINEAR)
|
|
671
|
+
a = cv2.warpAffine(ones, M, (c.W, c.H))[..., None] * k
|
|
672
|
+
bd = cv2.warpAffine(border, M, (c.W, c.H))[..., None] * k
|
|
673
|
+
out = out * (1 - a) + L * a
|
|
674
|
+
out = out * (1 - bd) + bd
|
|
675
|
+
m = c.m[..., None] * k # you stay in front while the room tunnels behind you
|
|
676
|
+
c.img = out * (1 - m) + src * m
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
@effect('cover-star', 'you become a magazine cover, with the title behind your head')
|
|
680
|
+
def fx_cover_star(c, e):
|
|
681
|
+
if e.o.get('look') == 'editorial': return cover_editorial(c, e)
|
|
682
|
+
k = ease_out(c.lt / 0.35); al = clamp((e.d - c.lt) / 0.2)
|
|
683
|
+
c.img = c.img * (1 - 0.6 * k) + grade(c.img, 'pop') * 0.6 * k
|
|
684
|
+
title = e.o.get('text', 'VIBE').upper(); col = rgb(e.o.get('color'), (232, 36, 52))
|
|
685
|
+
mast = cached(e, 'm', lambda: fit_text(title, c.W * 0.92, 'bold', 600, fill=col))
|
|
686
|
+
mast_h = min(mast.height, c.H * 0.24)
|
|
687
|
+
place(c, mast, c.W / 2, c.H * 0.035 + mast_h / 2 - (1 - k) * mast_h, mast_h / mast.height, 0, al * k, behind=True)
|
|
688
|
+
iss = cached(e, 'i', lambda: text_img(e.o.get('issue', 'THE AI ISSUE · 2026'), c.W * 0.025, 'mono', (255, 255, 255), shadow=3))
|
|
689
|
+
place(c, iss, c.W / 2, c.H * 0.03, alpha=al * k, behind=True)
|
|
690
|
+
lines = e.o.get('lines', '55 effects|you can steal|no editor|needed').split('|')
|
|
691
|
+
y = c.H * 0.5
|
|
692
|
+
for j, ln in enumerate(lines):
|
|
693
|
+
big = j == 0
|
|
694
|
+
im = cached(e, ('l', j), lambda: text_img(ln, c.W * (0.085 if big else 0.045), 'serif' if big else 'bold', YELLOW if big else (255, 255, 255), shadow=5))
|
|
695
|
+
kj = ease_out((c.lt - 0.15 - 0.08 * j) / 0.3)
|
|
696
|
+
comp(c, im, c.W * 0.05 - (1 - kj) * 60, y, al * kj, guard=True); y += im.height * 0.86
|
|
697
|
+
def barcode():
|
|
698
|
+
rnd = random.Random(1); bw, bh = int(c.W * 0.16), int(c.W * 0.09)
|
|
699
|
+
im = Image.new('RGBA', (bw, bh), (255, 255, 255, 255)); d = ImageDraw.Draw(im); x = 8
|
|
700
|
+
while x < bw - 8:
|
|
701
|
+
w = rnd.choice((2, 2, 3, 5)); d.rectangle([x, 6, x + w - 1, bh - 18], fill=(0, 0, 0, 255)); x += w + rnd.choice((2, 3, 4))
|
|
702
|
+
return im
|
|
703
|
+
bc = cached(e, 'b', barcode)
|
|
704
|
+
comp(c, bc, c.W * 0.95 - bc.width, c.H * 0.93 - bc.height, al * k, guard=True)
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
@effect('scribble', 'marker doodles draw themselves around you')
|
|
708
|
+
def fx_scribble(c, e):
|
|
709
|
+
col = rgb(e.o.get('color'), YELLOW) + (255,); wd = max(6, c.W // 130)
|
|
710
|
+
lay = Image.new('RGBA', (c.W, c.H), (0, 0, 0, 0)); d = ImageDraw.Draw(lay)
|
|
711
|
+
rx, ry = c.fw * 1.0, c.fw * 1.3
|
|
712
|
+
angs = np.linspace(-1.9, -1.9 + 2 * math.pi * 1.08, 70)
|
|
713
|
+
ring = [(c.fx + rx * (1 + 0.04 * math.sin(3 * a)) * math.cos(a), c.fy + ry * (1 + 0.04 * math.cos(2 * a)) * math.sin(a)) for a in angs]
|
|
714
|
+
hand_path(d, ring, col, wd, ease_inout(c.lt / 0.5))
|
|
715
|
+
lx, ly = clamp(c.fx + c.fw * 2.3, c.W * 0.2, c.W * 0.8), max(c.H * 0.08, c.fy - c.fw * 2.4)
|
|
716
|
+
pts = arrow_pts(lx - c.fw * 0.3, ly + c.fw * 0.5, c.fx + rx * 0.85, c.fy - ry * 0.75, -0.3)
|
|
717
|
+
k2 = ease_out((c.lt - 0.45) / 0.35)
|
|
718
|
+
if k2 > 0: hand_path(d, pts, col, wd, k2)
|
|
719
|
+
if k2 >= 0.99: arrow_head(d, pts, col, wd, c.W * 0.035)
|
|
720
|
+
for j, (sx, sy) in enumerate(((c.fx - c.fw * 1.9, c.fy - c.fw * 1.2), (c.fx - c.fw * 1.5, c.fy + c.fw * 0.6), (c.fx + c.fw * 1.6, c.fy + c.fw * 0.3))):
|
|
721
|
+
ks = ease_back((c.lt - 0.8 - 0.1 * j) / 0.25) * c.fw * 0.28
|
|
722
|
+
if ks > 0:
|
|
723
|
+
d.line([(sx - ks, sy), (sx + ks, sy)], fill=col, width=wd); d.line([(sx, sy - ks), (sx, sy + ks)], fill=col, width=wd)
|
|
724
|
+
al = clamp((e.d - c.lt) / 0.2)
|
|
725
|
+
comp(c, to_np(lay), 0, 0, al)
|
|
726
|
+
if c.lt > 0.7:
|
|
727
|
+
lab = text_img(e.o.get('text', 'me!'), c.W * 0.075, 'hand', col[:3], shadow=6)
|
|
728
|
+
place(c, lab, lx, ly - lab.height * 0.15, 0.7 + 0.3 * ease_back((c.lt - 0.7) / 0.3), 8, al)
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
# ---------- pack 2: app-style effects (added 21 Oct 2026) ----------
|
|
732
|
+
def pop(c, t0, dur=0.3): return ease_back((c.lt - t0) / dur) if c.lt > t0 else 0.0
|
|
733
|
+
def fade(c, e, t=0.2): return clamp((e.d - c.lt) / t)
|
|
734
|
+
GREEN, BLUE, PURPLE, ORANGE, RED = (34, 197, 94), (10, 132, 255), (124, 92, 255), (217, 119, 87), (238, 34, 34)
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
def glass(c, w, h, r, cx, cy, amt=0.22, tint=(255, 255, 255), blur=None, alpha=240, dark=0.0, liquid=True):
|
|
738
|
+
"""A glass panel made from whatever sits behind it. liquid=True (default since 27 Oct 2026) is see-through liquid
|
|
739
|
+
glass after liquid-glass-js (MIT, dashersw): light blur, refraction bending the room at the rim, a red/blue fringe
|
|
740
|
+
(after React Bits' GlassSurface) and a specular edge lit from the top-left. liquid=False is the old frosted card."""
|
|
741
|
+
w, h = int(w), int(h); blur = blur or max(8, c.W // 40); x0, y0 = int(cx - w / 2), int(cy - h / 2)
|
|
742
|
+
if not liquid:
|
|
743
|
+
pad = blur * 2
|
|
744
|
+
xs = np.clip(np.arange(x0 - pad, x0 + w + pad), 0, c.W - 1); ys = np.clip(np.arange(y0 - pad, y0 + h + pad), 0, c.H - 1)
|
|
745
|
+
reg = cv2.GaussianBlur(np.ascontiguousarray(c.img[np.ix_(ys, xs)]), (0, 0), blur)[pad:pad + h, pad:pad + w]
|
|
746
|
+
reg = reg * (1 - dark) * (1 - amt) + np.float32(tint) / 255 * amt
|
|
747
|
+
im = Image.fromarray((np.clip(reg, 0, 1) * 255).astype(np.uint8)).convert('RGBA')
|
|
748
|
+
m = Image.new('L', (w, h), 0); ImageDraw.Draw(m).rounded_rectangle([0, 0, w - 1, h - 1], int(r), fill=alpha); im.putalpha(m)
|
|
749
|
+
ImageDraw.Draw(im).rounded_rectangle([1, 1, w - 2, h - 2], int(r), outline=(255, 255, 255, 120), width=max(2, c.W // 540))
|
|
750
|
+
return im
|
|
751
|
+
u = c.W / 2160; pad = int(140 * u) + 4
|
|
752
|
+
xs = np.clip(np.arange(x0 - pad, x0 + w + pad), 0, c.W - 1); ys = np.clip(np.arange(y0 - pad, y0 + h + pad), 0, c.H - 1)
|
|
753
|
+
tex = cv2.GaussianBlur(np.ascontiguousarray(c.img[np.ix_(ys, xs)]), (0, 0), max(3.0, blur * 0.3))
|
|
754
|
+
yy, xx = np.mgrid[0:h, 0:w].astype(np.float32); r = max(2.0, float(r))
|
|
755
|
+
q = np.stack([np.abs(xx - w / 2) - (w / 2 - r), np.abs(yy - h / 2) - (h / 2 - r)], -1)
|
|
756
|
+
sdf = np.linalg.norm(np.maximum(q, 0), axis=-1) + np.minimum(np.maximum(q[..., 0], q[..., 1]), 0) - r
|
|
757
|
+
d = np.maximum(-sdf, 0) / u
|
|
758
|
+
nx, ny = xx - w / 2, yy - h / 2; nl = np.sqrt(nx * nx + ny * ny) + 1e-3; nx, ny = nx / nl, ny / nl
|
|
759
|
+
k = (70 * np.exp(-d / 14) + 34 * np.exp(-d / 70) + 10 * np.exp(-d / 260)) * u
|
|
760
|
+
out = np.zeros((h, w, 3), np.float32)
|
|
761
|
+
for ch, fr in enumerate((1.10, 1.0, 0.90)):
|
|
762
|
+
out[..., ch] = cv2.remap(tex[..., ch], (xx + pad + nx * k * fr).astype(np.float32), (yy + pad + ny * k * fr).astype(np.float32), cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT)
|
|
763
|
+
out = out * (1 - dark * 0.3) * 0.9 + np.float32(tint) / 255 * amt * 0.25 + 0.05 * (1.0 - 0.30 * (yy / h))[..., None] - 0.04
|
|
764
|
+
spec = np.exp(-d / 5) * np.clip(0.55 - 0.45 * (nx * 0.6 + ny * 0.8), 0, 1)
|
|
765
|
+
out = np.clip(out + (spec * 0.85 + np.exp(-d / 30) * 0.10)[..., None], 0, 1)
|
|
766
|
+
a = (np.clip(0.5 - sdf, 0, 1) * alpha).astype(np.uint8)
|
|
767
|
+
im = Image.fromarray((out * 255).astype(np.uint8)).convert('RGBA'); im.putalpha(Image.fromarray(a))
|
|
768
|
+
return im
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
def face_chip(c, e, size):
|
|
772
|
+
"""A round avatar cut from your own face (grabbed once, at the start of the effect)."""
|
|
773
|
+
def grab():
|
|
774
|
+
r = c.fw * 0.9; x0, y0 = int(max(0, c.fx - r)), int(max(0, c.fy - r * 1.05))
|
|
775
|
+
crop = c.img[y0:int(y0 + 2 * r), x0:int(x0 + 2 * r)]
|
|
776
|
+
im = Image.fromarray((np.clip(crop, 0, 1) * 255).astype(np.uint8)).convert('RGBA')
|
|
777
|
+
return im
|
|
778
|
+
src = cached(e, 'face', grab).resize((int(size), int(size)), Image.LANCZOS)
|
|
779
|
+
m = Image.new('L', src.size, 0); ImageDraw.Draw(m).ellipse([0, 0, src.width - 1, src.height - 1], fill=255); src.putalpha(m)
|
|
780
|
+
return src
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
def cursor(size):
|
|
784
|
+
s = float(size); im = Image.new('RGBA', (int(s * 0.95), int(s * 1.45)), (0, 0, 0, 0)); d = ImageDraw.Draw(im)
|
|
785
|
+
pts = [(3, 3), (3, s * 1.12), (s * 0.3, s * 0.87), (s * 0.5, s * 1.33), (s * 0.66, s * 1.26), (s * 0.46, s * 0.8), (s * 0.82, s * 0.8)]
|
|
786
|
+
d.polygon(pts, fill=(255, 255, 255, 255)); d.line(pts + [pts[0]], fill=(0, 0, 0, 255), width=max(2, int(s / 14)), joint='curve')
|
|
787
|
+
return shadowed(im, 6, 3, 110)
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
def tick(d, x, y, s, color=(255, 255, 255, 255), w=None):
|
|
791
|
+
d.line([(x, y + s * 0.5), (x + s * 0.36, y + s * 0.85), (x + s, y + s * 0.1)], fill=color, width=w or max(3, int(s / 5)), joint='curve')
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
def lines_fit(lines, max_w, kind, start):
|
|
795
|
+
size = start
|
|
796
|
+
while size > 10 and max(font(kind, size).getlength(l) for l in lines) > max_w: size = int(size * 0.94)
|
|
797
|
+
return size
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
def shift(c, dy):
|
|
801
|
+
"""Slide the whole picture (and you) down by dy pixels."""
|
|
802
|
+
if abs(dy) < 0.5: return
|
|
803
|
+
M = np.float32([[1, 0, 0], [0, 1, dy]])
|
|
804
|
+
c.img = cv2.warpAffine(c.img, M, (c.W, c.H), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_REPLICATE)
|
|
805
|
+
c.m = cv2.warpAffine(c.m, M, (c.W, c.H), flags=cv2.INTER_LINEAR); c.fy += dy
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
def thumb_grid(cards, cols, rows, cell, gap, i0=0, look=True):
|
|
809
|
+
im = Image.new('RGBA', (cols * cell + (cols - 1) * gap, rows * int(cell * 1.25) + (rows - 1) * gap), (0, 0, 0, 0))
|
|
810
|
+
ch = int(cell * 1.25)
|
|
811
|
+
for k in range(cols * rows):
|
|
812
|
+
src = cards[(i0 + k) % len(cards)]; src = vary(src, i0 + k) if look else src.convert('RGB')
|
|
813
|
+
sw, sh = src.size; s = max(cell / sw, ch / sh); t = src.resize((max(cell, int(sw * s)), max(ch, int(sh * s))), Image.LANCZOS)
|
|
814
|
+
l, tp = (t.width - cell) // 2, int((t.height - ch) * 0.3); t = t.crop((l, tp, l + cell, tp + ch)).convert('RGBA')
|
|
815
|
+
m = Image.new('L', t.size, 0); ImageDraw.Draw(m).rounded_rectangle([0, 0, cell - 1, ch - 1], max(4, cell // 12), fill=255); t.putalpha(m)
|
|
816
|
+
im.alpha_composite(t, ((k % cols) * (cell + gap), (k // cols) * (ch + gap)))
|
|
817
|
+
return im
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
def glass_widgets_v1(c, e):
|
|
821
|
+
k0 = ramp(c, e, 0.3, 0)
|
|
822
|
+
if e.o.get('grade', 'warm') != 'none': c.img = c.img * (1 - 0.6 * k0) + grade(c.img, e.o.get('grade', 'warm')) * 0.6 * k0
|
|
823
|
+
al = fade(c, e); W = c.W; mg = W * 0.055
|
|
824
|
+
S = W * 0.31; y_top = c.H * 0.07
|
|
825
|
+
gd = float(e.o.get('dark', 0.2))
|
|
826
|
+
a = glass(c, S, S, S * 0.2, mg + S / 2, y_top + S / 2, amt=0.14, dark=gd); d = ImageDraw.Draw(a)
|
|
827
|
+
d.ellipse([S * 0.1, S * 0.115, S * 0.1 + S * 0.06, S * 0.115 + S * 0.06], fill=ORANGE + (255,))
|
|
828
|
+
d.text((S * 0.2, S * 0.145), e.o.get('title', 'Claude'), font=font('uim', S * 0.085), fill=(255, 255, 255, 235), anchor='lm')
|
|
829
|
+
d.text((S * 0.08, S * 0.2), e.o.get('text', '22'), font=font('uib', S * 0.44), fill=(255, 255, 255, 255))
|
|
830
|
+
for j, ln in enumerate(e.o.get('sub', 'effects|one clip').split('|')):
|
|
831
|
+
d.text((S * 0.1, S * (0.7 + 0.11 * j)), ln, font=font('uim', S * 0.085), fill=(255, 255, 255, 235))
|
|
832
|
+
place(c, a, mg + S / 2, y_top + S / 2, 0.6 + 0.4 * pop(c, 0.0), 0, al * clamp(c.lt / 0.1), behind=True)
|
|
833
|
+
bw, bh = W * 0.37, W * 0.15; bx = W - mg - bw / 2
|
|
834
|
+
b = glass(c, bw, bh, bh * 0.28, bx, y_top + bh / 2, amt=0.14, dark=gd); d = ImageDraw.Draw(b)
|
|
835
|
+
d.ellipse([bh * 0.17, bh * 0.2, bh * 0.17 + bh * 0.11, bh * 0.31], fill=(255, 69, 58, 255))
|
|
836
|
+
d.text((bh * 0.36, bh * 0.255), 'Rendering', font=font('uim', bh * 0.19), fill=(255, 255, 255, 240), anchor='lm')
|
|
837
|
+
p = ease_inout(c.lt / max(0.3, e.d * 0.85))
|
|
838
|
+
d.rounded_rectangle([bh * 0.17, bh * 0.5, bw - bh * 0.17, bh * 0.6], bh * 0.05, fill=(255, 255, 255, 70))
|
|
839
|
+
d.rounded_rectangle([bh * 0.17, bh * 0.5, bh * 0.17 + (bw - bh * 0.34) * max(0.04, p), bh * 0.6], bh * 0.05, fill=(255, 255, 255, 245))
|
|
840
|
+
d.text((bh * 0.17, bh * 0.78), f"{e.o.get('label', 'glass UI')} · {int(p * 100)}%", font=font('uim', bh * 0.14), fill=(255, 255, 255, 210), anchor='lm')
|
|
841
|
+
place(c, b, bx, y_top + bh / 2, 0.6 + 0.4 * pop(c, 0.12), 0, al * clamp((c.lt - 0.12) / 0.1), behind=True)
|
|
842
|
+
cy2 = y_top + bh + mg * 0.45 + bh / 2
|
|
843
|
+
g = glass(c, bw, bh, bh * 0.28, bx, cy2, amt=0.14, dark=gd); d = ImageDraw.Draw(g)
|
|
844
|
+
av = face_chip(c, e, bh * 0.62); g.alpha_composite(av, (int(bw - bh * 0.19 - av.width), int((bh - av.height) / 2)))
|
|
845
|
+
d.text((bh * 0.2, bh * 0.36), e.o.get('name', PROFILE['name']), font=font('uib', bh * 0.22), fill=(255, 255, 255, 255), anchor='lm')
|
|
846
|
+
d.text((bh * 0.2, bh * 0.66), e.o.get('handle', PROFILE['handle']), font=font('uim', bh * 0.14), fill=(255, 255, 255, 215), anchor='lm')
|
|
847
|
+
place(c, g, bx, cy2, 0.6 + 0.4 * pop(c, 0.24), 0, al * clamp((c.lt - 0.24) / 0.1), behind=True)
|
|
848
|
+
f1, f2 = font('uim', W * 0.045), font('uib', W * 0.045)
|
|
849
|
+
pre, hi = e.o.get('pill', 'Edited by |Claude').split('|') if '|' in e.o.get('pill', 'Edited by |Claude') else (e.o['pill'], '')
|
|
850
|
+
tw = f1.getlength(pre) + f2.getlength(hi); ph = W * 0.105; pw = tw + ph * 0.9; py = c.H * 0.865
|
|
851
|
+
q = glass(c, pw, ph, ph / 2, W / 2, py, amt=0.16, tint=(70, 70, 76)); d = ImageDraw.Draw(q)
|
|
852
|
+
d.text(((pw - tw) / 2, ph / 2), pre, font=f1, fill=(255, 255, 255, 255), anchor='lm')
|
|
853
|
+
d.text(((pw - tw) / 2 + f1.getlength(pre), ph / 2), hi, font=f2, fill=(255, 176, 146, 255), anchor='lm')
|
|
854
|
+
place(c, shadowed(q, 14, 6, 70), W / 2, py, 0.7 + 0.3 * pop(c, 0.4), 0, al * clamp((c.lt - 0.4) / 0.1), guard=True)
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
@effect('red-collage', 'black and white you, a giant red word behind, kinetic type stacked beside you')
|
|
858
|
+
def fx_red_collage(c, e):
|
|
859
|
+
k = ramp(c, e, 0.15, 0); m = c.m[..., None]
|
|
860
|
+
bw = grade(c.img, 'bw'); out = bw * m + bw * 0.62 * (1 - m)
|
|
861
|
+
c.img = c.img * (1 - k) + out * k
|
|
862
|
+
vignette(c, 0.45 * k)
|
|
863
|
+
red = rgb(e.o.get('color'), RED); al = fade(c, e)
|
|
864
|
+
w = cached(e, 'w', lambda: fit_text(e.o.get('text', 'EDIT').upper(), c.W * 0.98, 'uib', 700, fill=red, glow=(red, 34)))
|
|
865
|
+
s = 1.12 - 0.12 * ease_out(c.lt / 0.4)
|
|
866
|
+
place(c, w, c.W / 2, max(w.height * 0.42, c.fy - c.fw * 1.05), s, 0, clamp(c.lt / 0.12) * al, behind=True)
|
|
867
|
+
lines = e.o.get('lines', 'ONE CLIP.|55 EFFECTS.|ZERO APPS.').split('|')
|
|
868
|
+
size = cached(e, 'sz', lambda: lines_fit(lines, c.W * 0.8, 'uib', int(c.W * 0.14)))
|
|
869
|
+
y = max(c.H * 0.5, c.fy + c.fw * 1.55)
|
|
870
|
+
for j, ln in enumerate(lines):
|
|
871
|
+
im = cached(e, ('l', j), lambda: text_img(ln, size, 'uib', red if j == 1 else (255, 255, 255), shadow=8))
|
|
872
|
+
kk = clamp((c.lt - 0.18 - 0.13 * j) / 0.16)
|
|
873
|
+
if kk > 0: place(c, im, c.W * 0.05 + im.width / 2, y + im.height / 2, 1.4 - 0.4 * ease_out(kk), 0, kk * al, guard=True)
|
|
874
|
+
y += size * 1.0
|
|
875
|
+
tag = cached(e, 'tag', lambda: text_img(e.o.get('tag', 'REC · RED COLLAGE'), c.W * 0.027, 'mono', red))
|
|
876
|
+
dot = Image.new('RGBA', (int(tag.height * 0.4),) * 2, (0, 0, 0, 0)); ImageDraw.Draw(dot).ellipse([0, 0, dot.width - 1, dot.width - 1], fill=red + (255,))
|
|
877
|
+
blink = 1.0 if int(c.lt * 2.5) % 2 == 0 else 0.35
|
|
878
|
+
place(c, dot, c.W * 0.07, c.H * 0.93, alpha=al * k * blink, guard=True)
|
|
879
|
+
place(c, tag, c.W * 0.07 + dot.width + tag.width / 2, c.H * 0.93, alpha=al * k, guard=True)
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
@effect('split-headline', 'a clean headline card slides down and pushes you into the bottom of the frame')
|
|
883
|
+
def fx_split_headline(c, e):
|
|
884
|
+
k = ease_out(c.lt / 0.38) * clamp((e.d - c.lt) / 0.25)
|
|
885
|
+
ch = c.H * float(e.o.get('height', 0.36))
|
|
886
|
+
shift(c, ch * float(e.o.get('push', 0.72)) * k)
|
|
887
|
+
top = ch * k; W = c.W; col = rgb(e.o.get('color'), GREEN)
|
|
888
|
+
lay = Image.new('RGBA', (W, int(ch)), (244, 242, 236, 255)); d = ImageDraw.Draw(lay)
|
|
889
|
+
lines = e.o.get('text', 'Claude|edits my|reels.').split('|'); hl = e.o.get('hl', 'edits')
|
|
890
|
+
S = cached(e, 'sz', lambda: lines_fit(lines, W * 0.84, 'uib', int(W * 0.135))); f = font('uib', S)
|
|
891
|
+
x0, y0 = W * 0.07, ch * 0.13
|
|
892
|
+
for j, ln in enumerate(lines):
|
|
893
|
+
kj = clamp((c.lt - 0.12 - 0.08 * j) / 0.18)
|
|
894
|
+
if kj <= 0: continue
|
|
895
|
+
y = y0 + j * S * 1.04 + (1 - ease_out(kj)) * S * 0.35; a = int(255 * kj)
|
|
896
|
+
x = x0
|
|
897
|
+
for wi, word in enumerate(ln.split(' ')):
|
|
898
|
+
tail = '.' if word.endswith('.') else ''; core = word[:-1] if tail else word
|
|
899
|
+
wl = f.getlength(core)
|
|
900
|
+
if core == hl:
|
|
901
|
+
hk = ease_out((c.lt - 0.42) / 0.22); pad = S * 0.12
|
|
902
|
+
if hk > 0: d.rounded_rectangle([x - pad, y + S * 0.02, x - pad + (wl + 2 * pad) * hk, y + S * 1.1], S * 0.16, fill=col + (a,))
|
|
903
|
+
d.text((x, y), core, font=f, fill=((255, 255, 255, a) if hk > 0.55 else (20, 20, 22, a)))
|
|
904
|
+
else: d.text((x, y), core, font=f, fill=(20, 20, 22, a))
|
|
905
|
+
x += wl
|
|
906
|
+
if tail: d.text((x, y), tail, font=f, fill=col + (a,)); x += f.getlength(tail)
|
|
907
|
+
x += f.getlength(' ') + (S * 0.12 if core == hl else 0)
|
|
908
|
+
d.rectangle([0, ch - max(5, W // 180), W, ch], fill=col + (255,))
|
|
909
|
+
comp(c, lay, 0, top - ch)
|
|
910
|
+
pt = text_img(e.o.get('pill', 'in seconds ↗'), W * 0.034, 'uib', (255, 255, 255))
|
|
911
|
+
pill = rrect(pt.width + W * 0.02, pt.height * 0.95, pt.height * 0.47, col + (255,)); pill.alpha_composite(pt, (int(W * 0.01), int(-pt.height * 0.025)))
|
|
912
|
+
place(c, shadowed(pill, 10, 4, 80), W * 0.93 - pill.width / 2, top + pill.height * 0.95, 0.6 + 0.4 * pop(c, 0.62), 0, clamp((c.lt - 0.62) / 0.1) * k, guard=True)
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
_grad = {}
|
|
916
|
+
@effect('pastel-word', 'a soft lavender backdrop, a giant word behind you and a profile card that gets followed')
|
|
917
|
+
def fx_pastel_word(c, e):
|
|
918
|
+
W, H = c.W, c.H; k = ramp(c, e, 0.2, 0); m = c.m[..., None]; al = fade(c, e)
|
|
919
|
+
if (W, H) not in _grad:
|
|
920
|
+
yy, xx = np.mgrid[0:H, 0:W].astype(np.float32); t = np.clip((yy / H) * 0.8 + (xx / W) * 0.2, 0, 1)[..., None]
|
|
921
|
+
_grad[(W, H)] = np.float32([0.70, 0.67, 0.97]) * (1 - t) + np.float32([0.93, 0.90, 1.0]) * t
|
|
922
|
+
lum = (c.img @ np.float32([0.299, 0.587, 0.114]))[..., None]
|
|
923
|
+
bg = _grad[(W, H)] * (0.86 + 0.22 * lum)
|
|
924
|
+
you = np.clip(c.img * 0.93 + 0.05, 0, 1)
|
|
925
|
+
c.img = c.img * (1 - k) + (you * m + bg * (1 - m)) * k
|
|
926
|
+
word = cached(e, 'w', lambda: fit_text(e.o.get('text', 'REELS').upper(), W * 0.96, 'uib', 700, fill=(255, 255, 255)))
|
|
927
|
+
dk = ease_out(c.lt / 0.45)
|
|
928
|
+
place(c, shadowed(word, 24, 12, 60), W / 2, max(word.height * 0.45, c.fy - c.fw * 1.2) - (1 - dk) * H * 0.06, 1, 0, al * clamp(c.lt / 0.15), behind=True)
|
|
929
|
+
cw, chh = W * 0.86, W * 0.15; cy = H * 0.865 + (1 - ease_out((c.lt - 0.15) / 0.35)) * H * 0.2
|
|
930
|
+
card_ = rrect(cw, chh, chh * 0.3, (255, 255, 255, 248)); d = ImageDraw.Draw(card_)
|
|
931
|
+
av = face_chip(c, e, chh * 0.64); card_.alpha_composite(av, (int(chh * 0.18), int((chh - av.height) / 2)))
|
|
932
|
+
d.text((chh * 0.98, chh * 0.38), e.o.get('name', PROFILE['name']), font=font('uib', chh * 0.22), fill=(20, 20, 22, 255), anchor='lm')
|
|
933
|
+
h1 = e.o.get('handle', PROFILE['handle'] + ' · '); f = font('uim', chh * 0.15)
|
|
934
|
+
d.text((chh * 0.98, chh * 0.66), h1, font=f, fill=(140, 140, 150, 255), anchor='lm')
|
|
935
|
+
d.text((chh * 0.98 + f.getlength(h1), chh * 0.66), e.o.get('role', 'creator'), font=f, fill=PURPLE + (255,), anchor='lm')
|
|
936
|
+
at = e.d * 0.6; on = c.lt >= at
|
|
937
|
+
bx = cw - chh * 0.22
|
|
938
|
+
d.text((bx, chh / 2), 'Following' if on else 'Follow', font=font('uib', chh * 0.2), fill=((140, 140, 150, 255) if on else PURPLE + (255,)), anchor='rm')
|
|
939
|
+
sq = 1 - 0.06 * math.sin(math.pi * clamp((c.lt - at) / 0.25)) if on else 1
|
|
940
|
+
place(c, shadowed(card_, 18, 8, 90), W / 2, cy, sq, 0, al * clamp((c.lt - 0.15) / 0.12), guard=True)
|
|
941
|
+
cu = cached(e, 'cur', lambda: cursor(W * 0.06))
|
|
942
|
+
ck = ease_inout((c.lt - 0.25) / max(0.2, at - 0.3))
|
|
943
|
+
tx, ty = W / 2 + cw / 2 - chh * 0.55, cy + chh * 0.12
|
|
944
|
+
sx, sy = W * 1.02, H * 1.02
|
|
945
|
+
place(c, cu, sx + (tx - sx) * ck + cu.width / 2, sy + (ty - sy) * ck + cu.height / 2, 0.85 if on and c.lt - at < 0.15 else 1, 0, al * clamp((c.lt - 0.25) / 0.1))
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
_gp = {}
|
|
949
|
+
@effect('check-pills', 'grid-paper room, your reels pinned behind you and blue pills that get clicked')
|
|
950
|
+
def fx_check_pills(c, e):
|
|
951
|
+
W, H = c.W, c.H; k = ramp(c, e, 0.15, 0); m = c.m[..., None]; al = fade(c, e)
|
|
952
|
+
if (W, H) not in _gp:
|
|
953
|
+
g = np.ones((H, W, 3), np.float32) * np.float32([0.935, 0.945, 0.96]); st = max(20, W // 20); lw = max(1, W // 700)
|
|
954
|
+
for x in range(0, W, st): g[:, x:x + lw] = np.float32([0.86, 0.875, 0.9])
|
|
955
|
+
for y in range(0, H, st): g[y:y + lw] = np.float32([0.86, 0.875, 0.9])
|
|
956
|
+
_gp[(W, H)] = g
|
|
957
|
+
c.img = c.img * (1 - k) + (c.img * m + _gp[(W, H)] * (1 - m)) * k
|
|
958
|
+
def board(i, title):
|
|
959
|
+
bw = int(W * 0.44); im = rrect(bw, int(bw * 1.12), bw * 0.07, (255, 255, 255, 255)); d = ImageDraw.Draw(im)
|
|
960
|
+
d.ellipse([bw * 0.06, bw * 0.055, bw * 0.06 + bw * 0.09, bw * 0.145], fill=(255, 160, 140, 255))
|
|
961
|
+
d.text((bw * 0.19, bw * 0.1), title, font=font('uib', bw * 0.06), fill=(20, 20, 22, 255), anchor='lm')
|
|
962
|
+
gr = thumb_grid(e.cards, 3, 3, int(bw * 0.28), int(bw * 0.025), i0=i * 3)
|
|
963
|
+
im.alpha_composite(gr, ((bw - gr.width) // 2, int(bw * 0.2))); return shadowed(im, 16, 8, 70)
|
|
964
|
+
b1 = cached(e, 'b1', lambda: board(0, e.o.get('handle', PROFILE['handle'])))
|
|
965
|
+
b2 = cached(e, 'b2', lambda: board(1, e.o.get('board', 'Reels · 55 effects')))
|
|
966
|
+
by = max(H * 0.17, c.fy - c.fw * 0.9)
|
|
967
|
+
place(c, b1, W * 0.25, by, 0.6 + 0.4 * pop(c, 0.0), 8, al * clamp(c.lt / 0.1), behind=True)
|
|
968
|
+
place(c, b2, W * 0.76, by - W * 0.02, 0.6 + 0.4 * pop(c, 0.1), -8, al * clamp((c.lt - 0.1) / 0.1), behind=True)
|
|
969
|
+
names = e.o.get('text', 'Hook|Captions|Cuts|B-roll').split('|')
|
|
970
|
+
spots = [(-0.95, 2.35), (0.55, 2.0), (-0.35, 2.95), (0.95, 2.75), (0.1, 3.45), (-1.1, 3.3)]
|
|
971
|
+
ph = W * 0.078; cu = cached(e, 'cur', lambda: cursor(W * 0.055))
|
|
972
|
+
pos = []
|
|
973
|
+
for i, n in enumerate(names):
|
|
974
|
+
sx, sy = spots[i % len(spots)]
|
|
975
|
+
x = clamp(c.fx + sx * c.fw * 1.6, W * 0.16, W * 0.84); y = clamp(c.fy + sy * c.fw, H * 0.3, H * 0.9)
|
|
976
|
+
t0 = 0.22 + 0.2 * i; pos.append((x, y, t0))
|
|
977
|
+
if c.lt < t0: continue
|
|
978
|
+
clicked = c.lt >= t0 + 0.12
|
|
979
|
+
t = text_img(n, ph * 0.42, 'uib', (255, 255, 255)); pw = int(t.width + ph * (0.75 if clicked else 0.35))
|
|
980
|
+
pill = rrect(pw, ph, ph / 2, BLUE + (255,)); pill.alpha_composite(t, (int(ph * 0.18), int((ph - t.height) / 2)))
|
|
981
|
+
if clicked: tick(ImageDraw.Draw(pill), pw - ph * 0.55, ph * 0.33, ph * 0.33)
|
|
982
|
+
sq = 1 - 0.1 * math.sin(math.pi * clamp((c.lt - t0 - 0.12) / 0.2))
|
|
983
|
+
place(c, shadowed(pill, 10, 5, 90), x, y, (0.5 + 0.5 * pop(c, t0, 0.25)) * sq, 0, al, guard=True)
|
|
984
|
+
if pos and c.lt > pos[0][2] - 0.1:
|
|
985
|
+
seg = [p for p in pos if p[2] <= c.lt + 0.1]; tx, ty, t0 = seg[-1]
|
|
986
|
+
px, py = (pos[len(seg) - 2][0], pos[len(seg) - 2][1]) if len(seg) > 1 else (W * 0.9, H * 0.95)
|
|
987
|
+
q = ease_inout((c.lt - (t0 - 0.12)) / 0.2)
|
|
988
|
+
place(c, cu, px + (tx - px) * q + ph * 0.3 + cu.width / 2, py + (ty - py) * q + ph * 0.1 + cu.height / 2, 1, 0, al)
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
def red_timeline(c, e):
|
|
992
|
+
W, H = c.W, c.H; k = ramp(c, e, 0.2, 0); m = c.m[..., None]; al = fade(c, e)
|
|
993
|
+
lum = (c.img @ np.float32([0.299, 0.587, 0.114]))[..., None]
|
|
994
|
+
bg = np.clip(lum * np.float32([1.05, 0.3, 0.27]) * 0.85, 0, 1)
|
|
995
|
+
you = np.clip(c.img * np.float32([1.04, 0.86, 0.82]), 0, 1)
|
|
996
|
+
c.img = c.img * (1 - k) + (you * m + bg * (1 - m)) * k; vignette(c, 0.5 * k)
|
|
997
|
+
red = rgb(e.o.get('color'), (255, 52, 44))
|
|
998
|
+
sl = (1 - ease_out(c.lt / 0.35)) * W * 0.08; tb = clamp(c.lt / 0.15) * al
|
|
999
|
+
secs = 21 + int(c.lt * 3)
|
|
1000
|
+
rec = text_img(f"{e.o.get('tc', 'REC')} 00:{secs:02d}", W * 0.032, 'mono', red)
|
|
1001
|
+
dot = Image.new('RGBA', (int(rec.height * 0.36),) * 2, (0, 0, 0, 0)); ImageDraw.Draw(dot).ellipse([0, 0, dot.width - 1, dot.width - 1], fill=red + (255,))
|
|
1002
|
+
comp(c, dot, W * 0.065 - sl, H * 0.075 + (rec.height - dot.height) / 2, tb * (1.0 if int(c.lt * 2.5) % 2 == 0 else 0.35), guard=True)
|
|
1003
|
+
comp(c, rec, W * 0.065 + dot.width * 1.4 - sl, H * 0.075, tb, guard=True)
|
|
1004
|
+
ti = cached(e, 'ti', lambda: text_img(e.o.get('text', 'AUTO-EDIT'), W * 0.13, 'uib', (255, 255, 255), shadow=10))
|
|
1005
|
+
comp(c, ti, W * 0.055 - sl, H * 0.075 + rec.height * 0.85, tb, guard=True)
|
|
1006
|
+
su = cached(e, 'su', lambda: text_img(e.o.get('sub', 'timeline by Claude'), W * 0.037, 'uim', red))
|
|
1007
|
+
comp(c, su, W * 0.065 - sl, H * 0.075 + rec.height * 0.85 + ti.height * 0.88, tb, guard=True)
|
|
1008
|
+
pw, phh = int(W * 0.9), int(H * 0.19); py = H * 0.755 + (1 - ease_out((c.lt - 0.1) / 0.35)) * H * 0.3
|
|
1009
|
+
lay = rrect(pw, phh, W * 0.03, (14, 10, 10, 215), (255, 70, 60, 90), 2); d = ImageDraw.Draw(lay)
|
|
1010
|
+
for j in range(4): d.text((pw * (0.05 + 0.3 * j), phh * 0.12), f'00:0{j}', font=font('mono', W * 0.022), fill=(170, 170, 175, 255), anchor='lm')
|
|
1011
|
+
clips = cached(e, 'cl', lambda: [(r, a, b) for r, segs in enumerate([[(0.04, 0.24), (0.26, 0.5), (0.53, 0.76), (0.79, 0.96)],
|
|
1012
|
+
[(0.04, 0.3), (0.33, 0.45), (0.48, 0.7)], [(0.04, 0.55), (0.6, 0.96)]]) for a, b in segs])
|
|
1013
|
+
p = 0.04 + 0.92 * clamp(c.lt / (e.d * 0.95)); ph_x = pw * p
|
|
1014
|
+
glow = Image.new('RGBA', (pw, phh), (0, 0, 0, 0)); gd = ImageDraw.Draw(glow)
|
|
1015
|
+
for r, a, b in clips:
|
|
1016
|
+
y0 = phh * (0.27 + 0.235 * r); x0, x1 = pw * a, pw * b; on = pw * a < ph_x
|
|
1017
|
+
fill = red + (255,) if on else (120, 30, 28, 255)
|
|
1018
|
+
d.rounded_rectangle([x0, y0, x1, y0 + phh * 0.17], phh * 0.04, fill=fill)
|
|
1019
|
+
if on: gd.rounded_rectangle([x0, y0, x1, y0 + phh * 0.17], phh * 0.04, fill=red + (200,))
|
|
1020
|
+
d.line([(ph_x, phh * 0.2), (ph_x, phh * 0.97)], fill=(255, 255, 255, 255), width=max(3, W // 300))
|
|
1021
|
+
gd.line([(ph_x, phh * 0.2), (ph_x, phh * 0.97)], fill=(255, 255, 255, 255), width=max(8, W // 100))
|
|
1022
|
+
lay = Image.alpha_composite(glow.filter(ImageFilter.GaussianBlur(W // 90)), lay)
|
|
1023
|
+
comp(c, lay, (W - pw) / 2, py, al, guard=True)
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
@effect('headline-box', 'a punch-in with a clean two-line headline, the second line in a white box')
|
|
1027
|
+
def fx_headline_box(c, e):
|
|
1028
|
+
face_cam(c, 1 + (float(e.o.get('zoom', 1.2)) - 1) * ease_out(c.lt / 0.22), 0.45)
|
|
1029
|
+
W = c.W; al = fade(c, e); lines = e.o.get('text', 'How I got Claude|to edit my reels.').split('|')
|
|
1030
|
+
S = cached(e, 'sz', lambda: lines_fit(lines, W * 0.84, 'uib', int(W * 0.085)))
|
|
1031
|
+
y = max(c.H * 0.06, c.fy - c.fw * 1.3 - S * 1.3 * len(lines))
|
|
1032
|
+
for j, ln in enumerate(lines):
|
|
1033
|
+
kj = clamp((c.lt - 0.1 - 0.12 * j) / 0.18)
|
|
1034
|
+
if kj <= 0: y += S * 1.3; continue
|
|
1035
|
+
boxed = j == len(lines) - 1
|
|
1036
|
+
t = cached(e, ('t', j), lambda: text_img(ln, S, 'uib', (16, 16, 18) if boxed else (255, 255, 255), shadow=0 if boxed else 9))
|
|
1037
|
+
if boxed:
|
|
1038
|
+
bx = rrect(t.width - S * 0.15, S * 1.22, S * 0.08, (255, 255, 255, 255))
|
|
1039
|
+
wk = ease_out(kj); bx = bx.crop((0, 0, max(1, int(bx.width * wk)), bx.height))
|
|
1040
|
+
comp(c, bx, W / 2 - (t.width - S * 0.15) / 2, y, al, guard=True)
|
|
1041
|
+
place(c, t, W / 2, y + S * 0.6, 0.92 + 0.08 * ease_out(kj), 0, al * kj, guard=True)
|
|
1042
|
+
y += S * 1.3
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
@effect('profile-wall', 'your profile grid fills the wall behind you while a counter ticks up')
|
|
1046
|
+
def fx_profile_wall(c, e):
|
|
1047
|
+
W, H = c.W, c.H; al = fade(c, e)
|
|
1048
|
+
def wall():
|
|
1049
|
+
pw = int(W * 0.92); ph = int(H * 0.36); im = rrect(pw, ph, W * 0.035, (16, 16, 18, 240)); d = ImageDraw.Draw(im)
|
|
1050
|
+
tabs = ('Posts', 'Reels', 'Tagged'); f = font('uim', W * 0.032)
|
|
1051
|
+
for j, tb in enumerate(tabs):
|
|
1052
|
+
x = pw * (0.2 + 0.3 * j); d.text((x, ph * 0.06), tb, font=f, fill=((255, 255, 255, 255) if j == 1 else (130, 130, 136, 255)), anchor='mm')
|
|
1053
|
+
if j == 1: d.rectangle([x - pw * 0.08, ph * 0.1, x + pw * 0.08, ph * 0.1 + 4], fill=(255, 255, 255, 255))
|
|
1054
|
+
gr = thumb_grid(e.cards, 4, 2, int(pw * 0.225), int(pw * 0.012), look=False)
|
|
1055
|
+
im.alpha_composite(gr, ((pw - gr.width) // 2, int(ph * 0.14))); return shadowed(im, 20, 10, 110)
|
|
1056
|
+
wl = cached(e, 'wall', wall)
|
|
1057
|
+
place(c, wl, W / 2, H * 0.04 + wl.height / 2, 0.94 + 0.06 * ease_out(c.lt / 0.35), 0, al * clamp(c.lt / 0.15), behind=True)
|
|
1058
|
+
cw, chh = W * 0.76, W * 0.25; cy = min(H * 0.86, c.fy + c.fw * 2.6)
|
|
1059
|
+
g = glass(c, cw, chh, chh * 0.18, W / 2, cy, amt=0.5, tint=(12, 12, 14)); d = ImageDraw.Draw(g)
|
|
1060
|
+
target = int(e.o.get('count', 197000)); n = int(target * ease_out((c.lt - 0.2) / 0.8))
|
|
1061
|
+
swap = clamp((c.lt - 1.15) / 0.2)
|
|
1062
|
+
if swap < 1: d.text((cw / 2, chh * 0.33), f'{n:,}', font=font('uib', chh * 0.3), fill=(255, 255, 255, int(255 * (1 - swap))), anchor='mm')
|
|
1063
|
+
if swap > 0: d.text((cw / 2, chh * 0.33), e.o.get('label', 'views'), font=font('uib', chh * 0.3), fill=(255, 255, 255, int(255 * swap)), anchor='mm')
|
|
1064
|
+
av = face_chip(c, e, chh * 0.3); g.alpha_composite(av, (int(chh * 0.14), int(chh * 0.58)))
|
|
1065
|
+
d.text((chh * 0.52, chh * 0.68), e.o.get('name', PROFILE['handle'].lstrip('@')), font=font('uib', chh * 0.09), fill=(255, 255, 255, 255), anchor='lm')
|
|
1066
|
+
d.text((chh * 0.52, chh * 0.8), e.o.get('sub', 'top reel'), font=font('uim', chh * 0.075), fill=(170, 170, 176, 255), anchor='lm')
|
|
1067
|
+
on = c.lt >= e.d * 0.7
|
|
1068
|
+
d.rounded_rectangle([cw - chh * 0.95, chh * 0.62, cw - chh * 0.14, chh * 0.86], chh * 0.12, fill=((60, 60, 66, 255) if on else (255, 255, 255, 255)))
|
|
1069
|
+
d.text((cw - chh * 0.545, chh * 0.74), 'Following' if on else 'Follow', font=font('uib', chh * 0.08), fill=((255, 255, 255, 255) if on else (16, 16, 18, 255)), anchor='mm')
|
|
1070
|
+
place(c, g, W / 2, cy + (1 - ease_out((c.lt - 0.05) / 0.3)) * H * 0.1, 1, 0, al * clamp((c.lt - 0.05) / 0.12), guard=True)
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
@effect('tier-list', 'a tier list drops in front of you and Claude flies into S tier')
|
|
1074
|
+
def fx_tier_list(c, e):
|
|
1075
|
+
W, H = c.W, c.H; al = fade(c, e)
|
|
1076
|
+
ttl = cached(e, 'ttl', lambda: fit_text(e.o.get('title', 'best way to edit a reel?'), W * 0.88, 'serif', int(W * 0.11), fill=YELLOW, shadow=8))
|
|
1077
|
+
place(c, ttl, W / 2, max(ttl.height * 0.6, c.fy - c.fw * 1.65), 0.9 + 0.1 * ease_out(c.lt / 0.3), 0, al * clamp(c.lt / 0.15), behind=True)
|
|
1078
|
+
tiers = [('S', (255, 127, 127)), ('A', (255, 191, 127)), ('B', (255, 223, 127)), ('C', (191, 255, 127)), ('D', (127, 191, 255)), ('F', (191, 127, 255))]
|
|
1079
|
+
cw = int(W * 0.66); rh = int(W * 0.082); pad = int(W * 0.015); chh = pad * 2 + rh * 6 + pad * 5
|
|
1080
|
+
fill = dict(zip('BCDF', e.o.get('others', 'templates|timelines|apps|doing it by hand').split('|')))
|
|
1081
|
+
def board():
|
|
1082
|
+
im = rrect(cw, chh, W * 0.025, (22, 22, 26, 240)); d = ImageDraw.Draw(im)
|
|
1083
|
+
for i, (lab, col) in enumerate(tiers):
|
|
1084
|
+
y = pad + i * (rh + pad)
|
|
1085
|
+
d.rounded_rectangle([pad, y, pad + rh, y + rh], rh * 0.14, fill=col + (255,))
|
|
1086
|
+
d.text((pad + rh / 2, y + rh / 2), lab, font=font('uib', rh * 0.5), fill=(20, 20, 22, 255), anchor='mm')
|
|
1087
|
+
d.rounded_rectangle([pad * 2 + rh, y, cw - pad, y + rh], rh * 0.14, fill=(40, 40, 46, 255))
|
|
1088
|
+
if lab in fill:
|
|
1089
|
+
f = font('uim', rh * 0.3); tw = f.getlength(fill[lab]) + rh * 0.4
|
|
1090
|
+
d.rounded_rectangle([pad * 3 + rh, y + rh * 0.15, pad * 3 + rh + tw, y + rh * 0.85], rh * 0.12, fill=(78, 78, 86, 255))
|
|
1091
|
+
d.text((pad * 3 + rh + rh * 0.2, y + rh / 2), fill[lab], font=f, fill=(225, 225, 230, 255), anchor='lm')
|
|
1092
|
+
return shadowed(im, 18, 10, 120)
|
|
1093
|
+
bd = cached(e, 'bd', board)
|
|
1094
|
+
top = min(H * 0.95 - bd.height, max(c.fy + c.fw * 1.4, H * 0.45))
|
|
1095
|
+
k = ease_back(c.lt / 0.35); bx, by = W / 2, top + bd.height / 2 + (1 - k) * H * 0.15
|
|
1096
|
+
place(c, bd, bx, by, 1, 0, al * clamp(c.lt / 0.12), guard=True)
|
|
1097
|
+
tile = cached(e, 'tile', lambda: shadowed(rrect(int(rh * 2.6), int(rh * 0.8), rh * 0.16, ORANGE + (255,)), 8, 4, 100))
|
|
1098
|
+
tx = cached(e, 'tx', lambda: text_img(e.o.get('item', 'Claude'), rh * 0.36, 'uib', (255, 255, 255)))
|
|
1099
|
+
tl = tile.copy(); tl.alpha_composite(tx, ((tl.width - tx.width) // 2, (tl.height - tx.height) // 2 - 3))
|
|
1100
|
+
sx, sy = W * 0.86, c.fy + c.fw * 0.4
|
|
1101
|
+
ex = bx - bd.width / 2 + 18 + pad * 3 + rh + tile.width / 2 - 10; ey = by - bd.height / 2 + 18 + pad + rh / 2
|
|
1102
|
+
q = ease_back((c.lt - 0.45) / 0.4)
|
|
1103
|
+
if c.lt > 0.4: place(c, tl, sx + (ex - sx) * q, sy + (ey - sy) * q, 1.25 - 0.25 * clamp(q), 18 * (1 - clamp(q)), al, guard=True)
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
@effect('broll-split', 'split screen: b-roll on top with a price-tag sticker, you on the bottom')
|
|
1107
|
+
def fx_broll_split(c, e):
|
|
1108
|
+
W, H = c.W, c.H; k = ease_out(c.lt / 0.3) * clamp((e.d - c.lt) / 0.2); al = fade(c, e)
|
|
1109
|
+
shift(c, (H * 0.72 - c.fy) * k)
|
|
1110
|
+
sh = int(H * 0.5 * k)
|
|
1111
|
+
if sh > 2:
|
|
1112
|
+
src = e.cards[int(e.o.get('pick', 0)) % len(e.cards)].convert('RGB')
|
|
1113
|
+
z = 1.0 + 0.06 * clamp(c.lt / e.d); tw, th = int(W * z), int(H * 0.5 * z)
|
|
1114
|
+
s = max(tw / src.width, th / src.height); im = src.resize((int(src.width * s) + 1, int(src.height * s) + 1), Image.BILINEAR)
|
|
1115
|
+
l, t = (im.width - W) // 2, int((im.height - H * 0.5) * 0.35); im = im.crop((l, t, l + W, t + int(H * 0.5)))
|
|
1116
|
+
top = np.asarray(im, np.float32) / 255
|
|
1117
|
+
c.img[:sh] = top[int(H * 0.5) - sh:]; c.m[:sh] = 0
|
|
1118
|
+
c.img[max(0, sh - 3):sh + 3] = 1.0
|
|
1119
|
+
tag = cached(e, 'tag', lambda: text_img(e.o.get('text', '4 hrs → 4 min'), W * 0.06, 'uib', (16, 16, 18)))
|
|
1120
|
+
tw, th = int(tag.width + W * 0.11), int(tag.height * 1.25)
|
|
1121
|
+
st = Image.new('RGBA', (tw, th), (0, 0, 0, 0)); d = ImageDraw.Draw(st); n = th * 0.5
|
|
1122
|
+
d.polygon([(0, th / 2), (n, 0), (tw, 0), (tw, th), (n, th)], fill=(255, 255, 255, 255))
|
|
1123
|
+
d.ellipse([n * 0.55, th / 2 - n * 0.16, n * 0.87, th / 2 + n * 0.16], fill=(200, 200, 205, 255))
|
|
1124
|
+
st.alpha_composite(tag, (int(n * 1.05), (th - tag.height) // 2))
|
|
1125
|
+
place(c, shadowed(st, 12, 6, 110), W * 0.66, H * 0.39 * k + H * 0.0, 0.5 + 0.5 * pop(c, 0.3), 8, al * clamp((c.lt - 0.3) / 0.08))
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
@effect('phone-fan', 'your reels fan out like a hand of phones in front of you, under a two-line headline')
|
|
1129
|
+
def fx_phone_fan(c, e):
|
|
1130
|
+
W, H = c.W, c.H; al = fade(c, e)
|
|
1131
|
+
lines = e.o.get('text', '55 effects.|zero editing apps.').split('|')
|
|
1132
|
+
S = cached(e, 'sz', lambda: lines_fit(lines, W * 0.84, 'uib', int(W * 0.08)))
|
|
1133
|
+
y = max(H * 0.06, c.fy - c.fw * 1.3 - S * 1.3 * len(lines))
|
|
1134
|
+
for j, ln in enumerate(lines):
|
|
1135
|
+
kj = clamp((c.lt - 0.05 - 0.1 * j) / 0.18); last = j == len(lines) - 1
|
|
1136
|
+
t = cached(e, ('t', j), lambda: text_img(ln, S, 'uib', (16, 16, 18) if last else (255, 255, 255), shadow=0 if last else 9))
|
|
1137
|
+
if last: comp(c, rrect(t.width - S * 0.15, S * 1.22, S * 0.08, (255, 255, 255, 255)), W / 2 - (t.width - S * 0.15) / 2, y, al * kj, guard=True)
|
|
1138
|
+
place(c, t, W / 2, y + S * 0.6, 1, 0, al * kj, guard=True); y += S * 1.3
|
|
1139
|
+
pw = int(W * 0.23); ph = int(pw * 2.0)
|
|
1140
|
+
def phone(i):
|
|
1141
|
+
im = rrect(pw, ph, pw * 0.16, (14, 14, 16, 255))
|
|
1142
|
+
scr = card(vary(e.cards[i % len(e.cards)], i) if e.o.get('images') is None else e.cards[i % len(e.cards)], pw - 10)
|
|
1143
|
+
inner = scr.crop(((scr.width - (pw - 10)) // 2, (scr.height - (ph - 10)) // 2 - 6, (scr.width + pw - 10) // 2, (scr.height + ph - 10) // 2 - 6))
|
|
1144
|
+
im.alpha_composite(inner, (5, 5))
|
|
1145
|
+
ImageDraw.Draw(im).rounded_rectangle([pw * 0.36, ph * 0.025, pw * 0.64, ph * 0.045], pw * 0.03, fill=(0, 0, 0, 255))
|
|
1146
|
+
return shadowed(im, 14, 8, 120)
|
|
1147
|
+
ph_ = cached(e, 'ph', lambda: [phone(i) for i in range(4)])
|
|
1148
|
+
cx = W / 2 * 0.5 + c.fx * 0.5; cy = max(c.fy + c.fw * 1.1 + ph / 2, H * 0.62)
|
|
1149
|
+
cy = min(cy, H - ph * 0.42)
|
|
1150
|
+
for i, o in enumerate((-1.5, -0.5, 0.5, 1.5)):
|
|
1151
|
+
q = ease_back((c.lt - 0.2 - 0.06 * i) / 0.4)
|
|
1152
|
+
place(c, ph_[i], cx + o * W * 0.19 * q, cy + o * o * W * 0.025 * q, 0.9, -o * 11 * q, al * clamp((c.lt - 0.2) / 0.1), guard=True)
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
@effect('dot-reveal', 'your shot builds itself out of glowing dots, then snaps into the full picture')
|
|
1156
|
+
def fx_dot_reveal(c, e):
|
|
1157
|
+
p = clamp(c.lt / e.d); W, H = c.W, c.H
|
|
1158
|
+
cell = max(6, int(W * float(e.o.get('cell', 0.017)))); gh, gw = H // cell + 1, W // cell + 1
|
|
1159
|
+
def geo():
|
|
1160
|
+
yy, xx = np.mgrid[0:gh * cell, 0:gw * cell].astype(np.float32)
|
|
1161
|
+
dist = np.sqrt((xx % cell - cell / 2 + 0.5) ** 2 + (yy % cell - cell / 2 + 0.5) ** 2)[:H, :W]
|
|
1162
|
+
return dist, np.random.default_rng(5).random((gh, gw)).astype(np.float32)
|
|
1163
|
+
dist, thr = cached(e, 'geo', geo)
|
|
1164
|
+
pad = np.pad(c.img, ((0, gh * cell - H), (0, gw * cell - W), (0, 0)), mode='edge')
|
|
1165
|
+
small = cv2.resize(pad, (gw, gh), interpolation=cv2.INTER_AREA)
|
|
1166
|
+
lum = small @ np.float32([0.299, 0.587, 0.114])
|
|
1167
|
+
on = np.clip((p * 1.7 - thr * 0.95) / 0.3, 0, 1)
|
|
1168
|
+
sparkle = 0.75 + 0.25 * np.sin(thr * 40 + c.lt * 18)
|
|
1169
|
+
r = (0.18 + 0.32 * np.sqrt(np.clip(lum, 0, 1))) * cell * on
|
|
1170
|
+
col = rgb(e.o.get('color'), (255, 128, 80))
|
|
1171
|
+
q2 = clamp((p - 0.3) / 0.35)
|
|
1172
|
+
dc = np.float32(col) / 255 * (0.55 + 0.6 * lum[..., None]) * sparkle[..., None] * (1 - q2) + np.clip(small * 1.15, 0, 1) * q2
|
|
1173
|
+
R = np.repeat(np.repeat(r, cell, 0), cell, 1)[:H, :W]
|
|
1174
|
+
DC = np.repeat(np.repeat(dc, cell, 0), cell, 1)[:H, :W]
|
|
1175
|
+
dm = np.clip(R - dist + 0.5, 0, 1)[..., None]
|
|
1176
|
+
bgc = np.float32(rgb(e.o.get('bg'), (20, 20, 22))) / 255
|
|
1177
|
+
dots = bgc * (1 - dm) + DC * dm
|
|
1178
|
+
q = ease_inout((p - 0.6) / 0.4)
|
|
1179
|
+
c.img = dots * (1 - q) + c.img * q
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
def tracked(s, size, kind, fill, spacing, colors=None):
|
|
1183
|
+
"""Letter-spaced text. colors: optional per-character fill list."""
|
|
1184
|
+
f = font(kind, size); w = sum(f.getlength(ch) for ch in s) + spacing * max(0, len(s) - 1)
|
|
1185
|
+
bb = f.getbbox('Ag'); im = Image.new('RGBA', (int(w) + 8, int(bb[3] - bb[1] + size * 0.4)), (0, 0, 0, 0)); d = ImageDraw.Draw(im); x = 4
|
|
1186
|
+
for i, ch in enumerate(s):
|
|
1187
|
+
d.text((x, -bb[1] + size * 0.2), ch, font=f, fill=(colors[i] if colors else fill) + (255,)); x += f.getlength(ch) + spacing
|
|
1188
|
+
return im
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
def rich(parts, size, kind, base, accent, accent_kind=None, shadow=0):
|
|
1192
|
+
"""One line of text where *starred* words take the accent colour (and optionally another font)."""
|
|
1193
|
+
segs = []
|
|
1194
|
+
for j, p in enumerate(parts.split('*')):
|
|
1195
|
+
if p: segs.append(text_img(p, size, accent_kind if (j % 2 and accent_kind) else kind, accent if j % 2 else base, shadow=shadow))
|
|
1196
|
+
pad = int(size * 0.2 + shadow * 2.5) + 4
|
|
1197
|
+
w = sum(s.width - 2 * pad for s in segs) + 2 * pad; h = max(s.height for s in segs)
|
|
1198
|
+
im = Image.new('RGBA', (w, h), (0, 0, 0, 0)); x = 0
|
|
1199
|
+
for s in segs: im.alpha_composite(s, (x, (h - s.height) // 2)); x += s.width - 2 * pad
|
|
1200
|
+
return im
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
@effect('headline-wall', 'a wall of your own reel headlines piles up behind your head, then your total views pop in front')
|
|
1204
|
+
def fx_headline_wall(c, e):
|
|
1205
|
+
W, H = c.W, c.H; u = W / 1080; al = fade(c, e)
|
|
1206
|
+
items = [x.split('::') for x in e.o.get('text', 'Protect your personal data with ChatGPT Agent Mode::197K views|Easiest no-code scroll animation websites::124K views|'
|
|
1207
|
+
'How to make your resume un-rejectable using Claude::83K views|Same prompt: Claude Fable 5 vs ChatGPT 5.6 Sol::50K views|'
|
|
1208
|
+
'Jev, the new AI model faster and cheaper than Claude::40K views|Scrape LinkedIn automatically::38K views|'
|
|
1209
|
+
'Protect your personal data on the internet::140K views').split('|')]
|
|
1210
|
+
looks = [((255, 255, 255), (20, 20, 22)), ((22, 20, 24), (255, 255, 255)), ((246, 238, 226), (30, 24, 20)), ((255, 214, 10), (20, 20, 22))]
|
|
1211
|
+
def hcard(i):
|
|
1212
|
+
title, meta = (items[i % len(items)] + [''])[:2]; bg, fg = looks[i % len(looks)]
|
|
1213
|
+
cw = int(W * 0.5); f = font('uib', cw * 0.085); words = title.split(' '); lines, cur = [], ''
|
|
1214
|
+
for w_ in words:
|
|
1215
|
+
tst = (cur + ' ' + w_).strip()
|
|
1216
|
+
if f.getlength(tst) > cw * 0.84 and cur: lines.append(cur); cur = w_
|
|
1217
|
+
else: cur = tst
|
|
1218
|
+
lines.append(cur); lh = cw * 0.1
|
|
1219
|
+
chh = int(cw * 0.1 + lh * len(lines) + cw * 0.16)
|
|
1220
|
+
im = rrect(cw, chh, cw * 0.04, bg + (255,)); d = ImageDraw.Draw(im)
|
|
1221
|
+
for j, ln in enumerate(lines): d.text((cw * 0.08, cw * 0.07 + j * lh), ln, font=f, fill=fg + (255,))
|
|
1222
|
+
my = chh - cw * 0.085; s = cw * 0.04
|
|
1223
|
+
d.polygon([(cw * 0.08, my - s / 2), (cw * 0.08, my + s / 2), (cw * 0.08 + s * 0.9, my)], fill=(255, 48, 64, 255))
|
|
1224
|
+
d.text((cw * 0.08 + s * 1.5, my), (e.o.get('handle', PROFILE['handle']) + ' · ' + meta) if meta else e.o.get('handle', PROFILE['handle']), font=font('uim', cw * 0.045), fill=fg + (170,), anchor='lm')
|
|
1225
|
+
return shadowed(im, 14, 8, 110)
|
|
1226
|
+
N = int(e.o.get('count', 13))
|
|
1227
|
+
cards = cached(e, 'cards', lambda: [hcard(i) for i in range(N)])
|
|
1228
|
+
pos = cached(e, 'pos', lambda: [(random.Random(i * 7 + 1).uniform(0.2, 0.8), random.Random(i * 7 + 2).uniform(0.07, 0.42), random.Random(i * 7 + 3).uniform(-9, 9)) for i in range(N)])
|
|
1229
|
+
gap = float(e.o.get('gap', 0.09))
|
|
1230
|
+
for i in range(N):
|
|
1231
|
+
t0 = i * gap
|
|
1232
|
+
if c.lt < t0: break
|
|
1233
|
+
x, y, r = pos[i]; kk = ease_back((c.lt - t0) / 0.22)
|
|
1234
|
+
place(c, cards[i], x * W, y * H, 0.55 + 0.45 * kk, r, al * clamp((c.lt - t0) / 0.06), behind=True)
|
|
1235
|
+
t1 = N * gap + 0.1
|
|
1236
|
+
if c.lt > t1:
|
|
1237
|
+
tot = e.o.get('total', '672K'); lab = e.o.get('label', 'views from 7 reels')
|
|
1238
|
+
a = text_img(tot, 96 * u, 'anton', (255, 255, 255)); b = text_img(lab, 34 * u, 'uib', (255, 255, 255))
|
|
1239
|
+
pw = int(a.width + b.width + 30 * u); ph = int(max(a.height, b.height) + 10 * u)
|
|
1240
|
+
pill = rrect(pw, ph, ph * 0.28, (217, 119, 87, 245)); pill.alpha_composite(a, (int(8 * u), (ph - a.height) // 2)); pill.alpha_composite(b, (int(a.width + 8 * u), (ph - b.height) // 2))
|
|
1241
|
+
place(c, shadowed(pill, 18, 8, 110), W / 2, max(c.fy + c.fw * 1.8, H * 0.6), 0.6 + 0.4 * pop(c, t1, 0.3), -3, al * clamp((c.lt - t1) / 0.08), guard=True)
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
@effect('checklist', 'a Claude task list builds under your chin: each step spins, then ticks green')
|
|
1245
|
+
def fx_checklist(c, e):
|
|
1246
|
+
W, H = c.W, c.H; u = W / 1080; al = fade(c, e)
|
|
1247
|
+
rows = [x.split('::') for x in e.o.get('text', 'Found your face::every frame|Cut you out of the room::AI mask|Put the text behind you::depth|'
|
|
1248
|
+
'Graded the colour::warm|Rendered in 4K::2160p').split('|')]
|
|
1249
|
+
n = len(rows); cw = W * 0.9; rh = 104 * u; hh = 120 * u; chh = hh + rh * n + 26 * u
|
|
1250
|
+
y0 = min(max(c.fy + c.fw * 1.35, H * 0.42), H * 0.93 - chh); cy = y0 + chh / 2 + (1 - ease_out(c.lt / 0.35)) * H * 0.12
|
|
1251
|
+
span = max(0.4, e.d - 0.55); done_at = [0.3 + span * (i + 1) / n for i in range(n)]
|
|
1252
|
+
g = glass(c, cw, chh, 40 * u, W / 2, cy, amt=0.78, tint=(14, 13, 16), blur=int(30 * u)); d = ImageDraw.Draw(g)
|
|
1253
|
+
sx, sy = 44 * u, hh / 2
|
|
1254
|
+
for a in range(4):
|
|
1255
|
+
ang = a * math.pi / 2 + math.pi / 4
|
|
1256
|
+
d.line([(sx, sy), (sx + 18 * u * math.cos(ang), sy + 18 * u * math.sin(ang))], fill=(217, 119, 87, 255), width=int(7 * u))
|
|
1257
|
+
d.line([(sx, sy), (sx + 18 * u * math.cos(ang + math.pi / 4), sy + 18 * u * math.sin(ang + math.pi / 4))], fill=(217, 119, 87, 255), width=int(5 * u))
|
|
1258
|
+
d.text((80 * u, hh / 2), e.o.get('title', 'Claude is editing your clip'), font=font('uib', 42 * u), fill=(255, 255, 255, 255), anchor='lm')
|
|
1259
|
+
nd = sum(c.lt >= t for t in done_at)
|
|
1260
|
+
d.text((cw - 36 * u, hh / 2), f'{nd} of {n}', font=font('uim', 28 * u), fill=(170, 170, 176, 255), anchor='rm')
|
|
1261
|
+
d.line([(30 * u, hh), (cw - 30 * u, hh)], fill=(255, 255, 255, 30), width=max(1, int(2 * u)))
|
|
1262
|
+
for i, (txt, meta) in enumerate([(r + [''])[:2] for r in rows]):
|
|
1263
|
+
y = hh + 13 * u + rh * i + rh / 2; x = 56 * u; r_ = 24 * u
|
|
1264
|
+
start = done_at[i - 1] if i else 0.3
|
|
1265
|
+
if c.lt >= done_at[i]:
|
|
1266
|
+
q = ease_back((c.lt - done_at[i]) / 0.25); rr = r_ * (0.6 + 0.4 * q)
|
|
1267
|
+
d.ellipse([x - rr, y - rr, x + rr, y + rr], fill=(52, 199, 89, 255)); tick(d, x - rr * 0.5, y - rr * 0.45, rr, w=int(5 * u))
|
|
1268
|
+
fc, mc = (255, 255, 255, 255), (52, 199, 89, 255)
|
|
1269
|
+
elif c.lt >= start:
|
|
1270
|
+
a0 = (c.lt * 540) % 360; d.ellipse([x - r_, y - r_, x + r_, y + r_], outline=(255, 255, 255, 50), width=int(5 * u))
|
|
1271
|
+
d.arc([x - r_, y - r_, x + r_, y + r_], a0, a0 + 100, fill=(217, 119, 87, 255), width=int(5 * u)); fc, mc = (255, 255, 255, 255), (170, 170, 176, 255)
|
|
1272
|
+
else:
|
|
1273
|
+
d.ellipse([x - r_, y - r_, x + r_, y + r_], outline=(255, 255, 255, 60), width=int(4 * u)); fc, mc = (255, 255, 255, 110), (170, 170, 176, 90)
|
|
1274
|
+
d.text((x + 48 * u, y), txt, font=font('uib', 40 * u), fill=fc, anchor='lm')
|
|
1275
|
+
d.text((cw - 36 * u, y), meta, font=font('mono', 28 * u), fill=mc, anchor='rm')
|
|
1276
|
+
place(c, shadowed(g, 24, 12, 120), W / 2, cy, 1, 0, al * clamp(c.lt / 0.12), guard=True)
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
def np_thumb(c, w, h):
|
|
1280
|
+
"""The current frame as a small PIL thumbnail (cropped to w:h around your face)."""
|
|
1281
|
+
ar = w / h; ch = c.H * 0.62; cw = ch * ar
|
|
1282
|
+
x0 = int(clamp(c.fx - cw / 2, 0, c.W - cw)); y0 = int(clamp(c.fy - ch * 0.4, 0, c.H - ch))
|
|
1283
|
+
crop = c.img[y0:int(y0 + ch), x0:int(x0 + cw)]
|
|
1284
|
+
return Image.fromarray((np.clip(crop, 0, 1) * 255).astype(np.uint8)).resize((int(w), int(h)), Image.LANCZOS)
|
|
1285
|
+
|
|
1286
|
+
|
|
1287
|
+
def glow_panel(w, h, r, top, bot, line, glow, gblur):
|
|
1288
|
+
"""A rounded panel with a vertical gradient fill, a thin border and an outer glow."""
|
|
1289
|
+
w, h = int(w), int(h); pad = int(gblur * 2.2)
|
|
1290
|
+
out = Image.new('RGBA', (w + 2 * pad, h + 2 * pad), (0, 0, 0, 0))
|
|
1291
|
+
g = Image.new('RGBA', out.size, (0, 0, 0, 0)); ImageDraw.Draw(g).rounded_rectangle([pad, pad, pad + w, pad + h], r, fill=glow)
|
|
1292
|
+
out.alpha_composite(g.filter(ImageFilter.GaussianBlur(gblur)))
|
|
1293
|
+
t = np.linspace(0, 1, h, dtype=np.float32)[:, None, None]
|
|
1294
|
+
fill = (np.float32(top) * (1 - t) + np.float32(bot) * t) * np.ones((1, w, 1), np.float32)
|
|
1295
|
+
body = Image.fromarray(np.concatenate([fill, np.full((h, w, 1), 255, np.float32)], 2).astype(np.uint8), 'RGBA')
|
|
1296
|
+
m = Image.new('L', (w, h), 0); ImageDraw.Draw(m).rounded_rectangle([0, 0, w - 1, h - 1], r, fill=255); body.putalpha(m)
|
|
1297
|
+
ImageDraw.Draw(body).rounded_rectangle([1, 1, w - 2, h - 2], r, outline=line, width=max(2, int(w / 400)))
|
|
1298
|
+
out.alpha_composite(body, (pad, pad))
|
|
1299
|
+
return out, pad
|
|
1300
|
+
|
|
1301
|
+
|
|
1302
|
+
def np_thumb_pil(im, w, h):
|
|
1303
|
+
src = im.convert('RGB'); s = max(w / src.width, h / src.height)
|
|
1304
|
+
t = src.resize((max(w, int(src.width * s) + 1), max(h, int(src.height * s) + 1)), Image.LANCZOS)
|
|
1305
|
+
l, tp = (t.width - w) // 2, int((t.height - h) * 0.3); t = t.crop((l, tp, l + w, tp + h)).convert('RGBA')
|
|
1306
|
+
m = Image.new('L', t.size, 0); ImageDraw.Draw(m).rounded_rectangle([0, 0, w - 1, h - 1], max(3, w // 10), fill=255); t.putalpha(m)
|
|
1307
|
+
return t
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
def glass_widgets_v2(c, e):
|
|
1311
|
+
"""More widgets, artifact-style: stat tile, render bar, profile, a mini views artifact, now-playing, calendar, a 4K ring and the Edited by Claude pill."""
|
|
1312
|
+
W, H = c.W, c.H; u = W / 1080
|
|
1313
|
+
k0 = ramp(c, e, 0.3, 0)
|
|
1314
|
+
if e.o.get('grade', 'warm') != 'none': c.img = c.img * (1 - 0.6 * k0) + grade(c.img, e.o.get('grade', 'warm')) * 0.6 * k0
|
|
1315
|
+
al = fade(c, e); gd = float(e.o.get('dark', 0.22)); white = (255, 255, 255)
|
|
1316
|
+
def bob(i): return 6 * u * math.sin(2 * math.pi * (c.lt * 0.55 + i * 0.17))
|
|
1317
|
+
def show(im, x, y, i, front=False):
|
|
1318
|
+
t0 = 0.07 * i
|
|
1319
|
+
if c.lt < t0: return
|
|
1320
|
+
place(c, im, x, y + bob(i), 0.6 + 0.4 * pop(c, t0, 0.32), 0, al * clamp((c.lt - t0) / 0.08), behind=not front, guard=front)
|
|
1321
|
+
G = lambda w, h, cx, cy, r=None: glass(c, w, h, r or min(w, h) * 0.2, cx, cy, amt=0.14, dark=gd)
|
|
1322
|
+
# 1 · stat tile
|
|
1323
|
+
S = 300 * u; ax, ay = 50 * u + S / 2, 118 * u + S / 2
|
|
1324
|
+
a = G(S, S, ax, ay); d = ImageDraw.Draw(a)
|
|
1325
|
+
d.ellipse([S * 0.1, S * 0.115, S * 0.16, S * 0.175], fill=ORANGE + (255,))
|
|
1326
|
+
d.text((S * 0.2, S * 0.145), e.o.get('title', 'Claude'), font=font('uim', S * 0.085), fill=white + (235,), anchor='lm')
|
|
1327
|
+
d.text((S * 0.08, S * 0.2), e.o.get('text', '38'), font=font('uib', S * 0.44), fill=white + (255,))
|
|
1328
|
+
for j, ln in enumerate(e.o.get('sub', 'effects|one clip').split('|')): d.text((S * 0.1, S * (0.7 + 0.11 * j)), ln, font=font('uim', S * 0.085), fill=white + (235,))
|
|
1329
|
+
show(a, ax, ay, 0)
|
|
1330
|
+
# 2 · render bar
|
|
1331
|
+
bw, bh = 400 * u, 150 * u; bx, by = W - 50 * u - bw / 2, 118 * u + bh / 2
|
|
1332
|
+
b = G(bw, bh, bx, by, bh * 0.28); d = ImageDraw.Draw(b); p = ease_inout(c.lt / max(0.3, e.d * 0.85))
|
|
1333
|
+
d.ellipse([bh * 0.17, bh * 0.2, bh * 0.28, bh * 0.31], fill=(255, 69, 58, 255))
|
|
1334
|
+
d.text((bh * 0.36, bh * 0.255), 'Rendering', font=font('uim', bh * 0.19), fill=white + (240,), anchor='lm')
|
|
1335
|
+
d.rounded_rectangle([bh * 0.17, bh * 0.5, bw - bh * 0.17, bh * 0.6], bh * 0.05, fill=white + (70,))
|
|
1336
|
+
d.rounded_rectangle([bh * 0.17, bh * 0.5, bh * 0.17 + (bw - bh * 0.34) * max(0.04, p), bh * 0.6], bh * 0.05, fill=white + (245,))
|
|
1337
|
+
d.text((bh * 0.17, bh * 0.78), f"4K render · {int(p * 100)}%", font=font('uim', bh * 0.14), fill=white + (210,), anchor='lm')
|
|
1338
|
+
show(b, bx, by, 1)
|
|
1339
|
+
# 3 · profile
|
|
1340
|
+
cy3 = by + bh / 2 + 22 * u + bh / 2
|
|
1341
|
+
g = G(bw, bh, bx, cy3, bh * 0.28); d = ImageDraw.Draw(g)
|
|
1342
|
+
av = face_chip(c, e, bh * 0.62); g.alpha_composite(av, (int(bw - bh * 0.19 - av.width), int((bh - av.height) / 2)))
|
|
1343
|
+
d.text((bh * 0.2, bh * 0.36), e.o.get('name', PROFILE['name']), font=font('uib', bh * 0.22), fill=white + (255,), anchor='lm')
|
|
1344
|
+
d.text((bh * 0.2, bh * 0.66), e.o.get('handle', PROFILE['handle']), font=font('uim', bh * 0.14), fill=white + (215,), anchor='lm')
|
|
1345
|
+
show(g, bx, cy3, 2)
|
|
1346
|
+
# 4 · views artifact (a mini page inside the glass)
|
|
1347
|
+
aw, ah = 330 * u, 330 * u; dx, dy = 50 * u + aw / 2, ay + S / 2 + 26 * u + ah / 2
|
|
1348
|
+
art = G(aw, ah, dx, dy, 44 * u); d = ImageDraw.Draw(art)
|
|
1349
|
+
d.text((24 * u, 30 * u), 'artifact · views.html', font=font('mono', 15 * u), fill=white + (220,), anchor='lm')
|
|
1350
|
+
inn = rrect(aw - 36 * u, ah - 74 * u, 20 * u, (250, 248, 244, 255)); di = ImageDraw.Draw(inn); iw, ih = inn.size
|
|
1351
|
+
for j in range(3): di.ellipse([14 * u + j * 16 * u, 14 * u, 24 * u + j * 16 * u, 24 * u], fill=((255, 95, 87), (255, 189, 46), (40, 200, 64))[j] + (255,))
|
|
1352
|
+
di.text((16 * u, 40 * u), 'Top reels', font=font('uib', 26 * u), fill=(24, 22, 26, 255))
|
|
1353
|
+
di.text((16 * u, 72 * u), '197K', font=font('anton', 44 * u), fill=(200, 85, 61, 255))
|
|
1354
|
+
vals = [197, 140, 124, 83, 50, 40, 38]; gx0, gx1, gy1 = 16 * u, iw - 16 * u, ih - 18 * u; bwid = (gx1 - gx0) / 7 * 0.66
|
|
1355
|
+
for j, v in enumerate(vals):
|
|
1356
|
+
q = ease_out((c.lt - 0.35 - 0.05 * j) / 0.4); hh = (ih * 0.42) * v / 197 * q; x0 = gx0 + (gx1 - gx0) * j / 7
|
|
1357
|
+
if hh > 1: di.rounded_rectangle([x0, gy1 - hh, x0 + bwid, gy1], 5 * u, fill=((242, 196, 109) if j == 0 else (200, 85, 61)) + (255,))
|
|
1358
|
+
art.alpha_composite(inn, (int(18 * u), int(56 * u)))
|
|
1359
|
+
show(art, dx, dy, 3)
|
|
1360
|
+
# 5 · now playing
|
|
1361
|
+
mw, mh = 360 * u, 220 * u; mx, my = W - 50 * u - mw / 2, cy3 + bh / 2 + 22 * u + mh / 2
|
|
1362
|
+
mu = G(mw, mh, mx, my, 40 * u); d = ImageDraw.Draw(mu); A = 96 * u
|
|
1363
|
+
t = np.linspace(0, 1, int(A), dtype=np.float32)[:, None, None]
|
|
1364
|
+
art2 = Image.fromarray(np.concatenate([(np.float32([255, 150, 110]) * (1 - t) + np.float32([217, 90, 70]) * t) * np.ones((1, int(A), 1), np.float32), np.full((int(A), int(A), 1), 255, np.float32)], 2).astype(np.uint8), 'RGBA')
|
|
1365
|
+
am = Image.new('L', art2.size, 0); ImageDraw.Draw(am).rounded_rectangle([0, 0, art2.width - 1, art2.height - 1], 16 * u, fill=255); art2.putalpha(am)
|
|
1366
|
+
ad = ImageDraw.Draw(art2)
|
|
1367
|
+
for k_ in range(6):
|
|
1368
|
+
ang = k_ * math.pi / 3; ad.line([(A / 2 - 26 * u * math.cos(ang), A / 2 - 26 * u * math.sin(ang)), (A / 2 + 26 * u * math.cos(ang), A / 2 + 26 * u * math.sin(ang))], fill=(255, 255, 255, 255), width=int(7 * u))
|
|
1369
|
+
mu.alpha_composite(art2, (int(22 * u), int(22 * u)))
|
|
1370
|
+
d.text((134 * u, 44 * u), 'NOW EDITING', font=font('mono', 15 * u), fill=white + (200,), anchor='lm')
|
|
1371
|
+
d.text((134 * u, 78 * u), e.o.get('song', 'soft UI pops'), font=font('uib', 28 * u), fill=white + (255,), anchor='lm')
|
|
1372
|
+
d.text((134 * u, 108 * u), 'sfx · 25.7s', font=font('uim', 20 * u), fill=white + (200,), anchor='lm')
|
|
1373
|
+
pp = clamp(c.lt / max(0.5, e.d)); d.rounded_rectangle([22 * u, 140 * u, mw - 22 * u, 146 * u], 3 * u, fill=white + (70,))
|
|
1374
|
+
d.rounded_rectangle([22 * u, 140 * u, 22 * u + (mw - 44 * u) * pp, 146 * u], 3 * u, fill=white + (240,))
|
|
1375
|
+
cxm, cym = mw / 2, 184 * u
|
|
1376
|
+
d.polygon([(cxm - 12 * u, cym - 16 * u), (cxm - 12 * u, cym + 16 * u), (cxm + 16 * u, cym)], fill=white + (255,))
|
|
1377
|
+
for sgn in (-1, 1):
|
|
1378
|
+
x = cxm + sgn * 80 * u
|
|
1379
|
+
d.polygon([(x - sgn * 10 * u, cym - 11 * u), (x - sgn * 10 * u, cym + 11 * u), (x + sgn * 6 * u, cym)], fill=white + (220,))
|
|
1380
|
+
d.polygon([(x + sgn * 4 * u, cym - 11 * u), (x + sgn * 4 * u, cym + 11 * u), (x + sgn * 20 * u, cym)], fill=white + (220,))
|
|
1381
|
+
show(mu, mx, my, 4)
|
|
1382
|
+
# 6 · calendar
|
|
1383
|
+
kw, kh = 330 * u, 190 * u; kx, ky = 50 * u + kw / 2, dy + ah / 2 + 26 * u + kh / 2
|
|
1384
|
+
ca = G(kw, kh, kx, ky, 40 * u); d = ImageDraw.Draw(ca)
|
|
1385
|
+
d.text((26 * u, 36 * u), e.o.get('day', 'WED'), font=font('uib', 22 * u), fill=(255, 92, 82, 255), anchor='lm')
|
|
1386
|
+
d.text((26 * u, 82 * u), e.o.get('date', '21'), font=font('uib', 56 * u), fill=white + (255,), anchor='lm')
|
|
1387
|
+
d.rounded_rectangle([22 * u, 120 * u, kw - 22 * u, 168 * u], 12 * u, fill=(255, 92, 82, 210))
|
|
1388
|
+
d.text((36 * u, 144 * u), e.o.get('event', 'Post 2 reels · tonight'), font=font('uib', 22 * u), fill=white + (255,), anchor='lm')
|
|
1389
|
+
show(ca, kx, ky, 5)
|
|
1390
|
+
# 7 · 4K ring
|
|
1391
|
+
R = 250 * u; rx, ry = W - 50 * u - R / 2, my + mh / 2 + 26 * u + R / 2
|
|
1392
|
+
rg = G(R, R, rx, ry, 56 * u); d = ImageDraw.Draw(rg); rp = ease_inout((c.lt - 0.4) / 1.0); rr = R * 0.34
|
|
1393
|
+
d.ellipse([R / 2 - rr, R / 2 - rr - 8 * u, R / 2 + rr, R / 2 + rr - 8 * u], outline=white + (60,), width=int(16 * u))
|
|
1394
|
+
if rp > 0: d.arc([R / 2 - rr, R / 2 - rr - 8 * u, R / 2 + rr, R / 2 + rr - 8 * u], -90, -90 + 360 * rp, fill=(52, 199, 89, 255), width=int(16 * u))
|
|
1395
|
+
d.text((R / 2, R / 2 - 8 * u), '4K', font=font('uib', 52 * u), fill=white + (255,), anchor='mm')
|
|
1396
|
+
d.text((R / 2, R - 26 * u), 'render', font=font('uim', 20 * u), fill=white + (210,), anchor='mm')
|
|
1397
|
+
show(rg, rx, ry, 6)
|
|
1398
|
+
# 8 · Edited by Claude pill (in front)
|
|
1399
|
+
f1, f2 = font('uim', W * 0.045), font('uib', W * 0.045); pre, hi = 'Edited by ', 'Claude'
|
|
1400
|
+
tw = f1.getlength(pre) + f2.getlength(hi); ph = W * 0.105; pw = tw + ph * 0.9; py = H * 0.875
|
|
1401
|
+
q = glass(c, pw, ph, ph / 2, W / 2, py, amt=0.16, tint=(70, 70, 76)); d = ImageDraw.Draw(q)
|
|
1402
|
+
d.text(((pw - tw) / 2, ph / 2), pre, font=f1, fill=white + (255,), anchor='lm')
|
|
1403
|
+
d.text(((pw - tw) / 2 + f1.getlength(pre), ph / 2), hi, font=f2, fill=(255, 176, 146, 255), anchor='lm')
|
|
1404
|
+
show(shadowed(q, 14, 6, 70), W / 2, py, 7, front=True)
|
|
1405
|
+
|
|
1406
|
+
|
|
1407
|
+
@effect('glass-widgets', 'frosted glass phone widgets and mini artifacts float around your head, with an Edited by Claude pill')
|
|
1408
|
+
def fx_glass_widgets(c, e):
|
|
1409
|
+
(glass_widgets_v1 if e.o.get('look') == 'simple' else glass_widgets_v2)(c, e)
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
@effect('timeline', 'a dark red cinematic grade with an editing timeline, a REC timecode and a glowing playhead')
|
|
1413
|
+
def fx_timeline(c, e):
|
|
1414
|
+
studio = globals().get('studio_timeline')
|
|
1415
|
+
(studio if studio and e.o.get('look') != 'red' else red_timeline)(c, e)
|
|
1416
|
+
|
|
1417
|
+
|
|
1418
|
+
_emoji = {}
|
|
1419
|
+
def emoji(ch, size):
|
|
1420
|
+
"""A colour emoji as an RGBA image (Apple Color Emoji on a Mac). Returns None where the font is missing."""
|
|
1421
|
+
k = (ch, int(size))
|
|
1422
|
+
if k not in _emoji:
|
|
1423
|
+
try:
|
|
1424
|
+
f = ImageFont.truetype('/System/Library/Fonts/Apple Color Emoji.ttc', 160)
|
|
1425
|
+
im = Image.new('RGBA', (200, 200), (0, 0, 0, 0)); ImageDraw.Draw(im).text((20, 10), ch, font=f, embedded_color=True)
|
|
1426
|
+
im = im.crop(im.getbbox()); _emoji[k] = im.resize((int(size), int(size * im.height / im.width)), Image.LANCZOS)
|
|
1427
|
+
except Exception:
|
|
1428
|
+
_emoji[k] = None
|
|
1429
|
+
return _emoji[k]
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
def comment_sheet(c, e):
|
|
1433
|
+
"""Reels 1021 + VOX look: an Instagram Comments sheet above your head (your hair in front). The word types in, posts,
|
|
1434
|
+
gets a heart, then your reply drops in with a link chip."""
|
|
1435
|
+
W, H = c.W, c.H; u = W / 1080; al = fade(c, e)
|
|
1436
|
+
word = e.o.get('text', 'EFFECTS'); handle = e.o.get('handle', PROFILE['handle'].lstrip('@'))
|
|
1437
|
+
reply = e.o.get('reply', 'Sent you the pack'); chip = e.o.get('chip', '55 effects')
|
|
1438
|
+
sw, sh = 740 * u, 450 * u
|
|
1439
|
+
t_post = 0.3 + 0.06 * len(word) + 0.1; t_heart, t_rep = t_post + 0.25, t_post + 0.4
|
|
1440
|
+
sheet = rrect(sw, sh, 30 * u, (38, 38, 40, 248)); d = ImageDraw.Draw(sheet)
|
|
1441
|
+
white, grey, blue = (245, 245, 245, 255), (160, 160, 166, 255), (0, 149, 246, 255)
|
|
1442
|
+
d.rounded_rectangle([sw / 2 - 32 * u, 14 * u, sw / 2 + 32 * u, 20 * u], 3 * u, fill=(110, 110, 116, 255))
|
|
1443
|
+
d.text((sw / 2, 50 * u), 'Comments', font=font('uib', 26 * u), fill=white, anchor='mm')
|
|
1444
|
+
d.line([(0, 80 * u), (sw, 80 * u)], fill=(60, 60, 64, 255), width=max(1, int(2 * u)))
|
|
1445
|
+
def avatar(sz):
|
|
1446
|
+
a = Image.new('RGBA', (int(sz), int(sz)), (0, 0, 0, 0)); ad = ImageDraw.Draw(a)
|
|
1447
|
+
ad.ellipse([0, 0, sz - 1, sz - 1], fill=(233, 90, 140, 255)); ad.text((sz / 2, sz / 2), 'V', font=font('uib', sz * 0.5), fill=(255, 255, 255, 255), anchor='mm')
|
|
1448
|
+
return a
|
|
1449
|
+
if c.lt < t_post:
|
|
1450
|
+
d.text((sw / 2, 190 * u), 'Start the conversation.', font=font('uim', 21 * u), fill=grey, anchor='mm')
|
|
1451
|
+
else:
|
|
1452
|
+
q = ease_out((c.lt - t_post) / 0.25); oy = (1 - q) * -20 * u; a8 = int(255 * clamp(q * 1.5))
|
|
1453
|
+
av = avatar(46 * u); av.putalpha(av.split()[3].point(lambda v: v * a8 // 255)); sheet.alpha_composite(av, (int(26 * u), int(100 * u + oy)))
|
|
1454
|
+
d.text((88 * u, 108 * u + oy), 'you', font=font('uib', 19 * u), fill=white[:3] + (a8,), anchor='lm')
|
|
1455
|
+
d.text((88 * u + font('uib', 19 * u).getlength('you ') + 4 * u, 108 * u + oy), 'now', font=font('uim', 18 * u), fill=grey[:3] + (a8,), anchor='lm')
|
|
1456
|
+
d.text((86 * u, 128 * u + oy), word, font=font('uib', 50 * u), fill=white[:3] + (a8,))
|
|
1457
|
+
d.text((88 * u, 196 * u + oy), 'Reply', font=font('uim', 17 * u), fill=grey[:3] + (a8,), anchor='lm')
|
|
1458
|
+
hk = ease_back((c.lt - t_heart) / 0.3)
|
|
1459
|
+
if hk > 0:
|
|
1460
|
+
hh = heart(30 * u * hk, (255, 48, 64)); sheet.alpha_composite(hh, (int(sw - 46 * u - hh.width / 2), int(130 * u - hh.height / 2)))
|
|
1461
|
+
rk = ease_out((c.lt - t_rep) / 0.25)
|
|
1462
|
+
if rk > 0:
|
|
1463
|
+
ra = int(255 * clamp(rk * 1.5)); ry = 226 * u + (1 - rk) * 16 * u; rx = 88 * u
|
|
1464
|
+
fc = face_chip(c, e, 34 * u); fc.putalpha(fc.split()[3].point(lambda v: v * ra // 255)); sheet.alpha_composite(fc, (int(rx), int(ry)))
|
|
1465
|
+
d.text((rx + 46 * u, ry + 8 * u), handle, font=font('uib', 18 * u), fill=white[:3] + (ra,), anchor='lm')
|
|
1466
|
+
d.text((rx + 46 * u + font('uib', 18 * u).getlength(handle) + 10 * u, ry + 8 * u), 'Author', font=font('uim', 16 * u), fill=grey[:3] + (ra,), anchor='lm')
|
|
1467
|
+
d.text((rx + 46 * u, ry + 36 * u), reply, font=font('uim', 22 * u), fill=white[:3] + (ra,), anchor='lm')
|
|
1468
|
+
gift = emoji('🎁', 24 * u)
|
|
1469
|
+
if gift is not None:
|
|
1470
|
+
g2 = gift.copy(); g2.putalpha(g2.split()[3].point(lambda v: v * ra // 255))
|
|
1471
|
+
sheet.alpha_composite(g2, (int(rx + 52 * u + font('uim', 22 * u).getlength(reply)), int(ry + 36 * u - g2.height / 2)))
|
|
1472
|
+
ck = ease_back((c.lt - t_rep - 0.12) / 0.3)
|
|
1473
|
+
if ck > 0:
|
|
1474
|
+
ct = text_img(chip, 19 * u, 'uib', (20, 20, 22)); lk = emoji('🔗', 20 * u)
|
|
1475
|
+
cw_ = ct.width + (lk.width + 4 * u if lk is not None else 0) + 10 * u
|
|
1476
|
+
cp = rrect(cw_, ct.height * 0.9, ct.height * 0.45, (255, 214, 10, 255))
|
|
1477
|
+
x0 = 6 * u
|
|
1478
|
+
if lk is not None: cp.alpha_composite(lk, (int(x0 + 4 * u), int((cp.height - lk.height) / 2))); x0 += lk.width + 4 * u
|
|
1479
|
+
cp.alpha_composite(ct, (int(x0), int((cp.height - ct.height) / 2)))
|
|
1480
|
+
cp = cp.resize((max(1, int(cp.width * (0.6 + 0.4 * ck))), max(1, int(cp.height * (0.6 + 0.4 * ck)))))
|
|
1481
|
+
sheet.alpha_composite(cp, (int(rx + 46 * u), int(ry + 56 * u)))
|
|
1482
|
+
ey = sh - 140 * u
|
|
1483
|
+
chars = ['❤️', '🙌', '🔥', '👏', '😢', '😍', '😮', '😂']
|
|
1484
|
+
for j, ch in enumerate(chars):
|
|
1485
|
+
im = emoji(ch, 36 * u)
|
|
1486
|
+
if im is not None: sheet.alpha_composite(im, (int(36 * u + j * (sw - 72 * u - 36 * u) / 7), int(ey)))
|
|
1487
|
+
iy = sh - 78 * u
|
|
1488
|
+
sheet.alpha_composite(avatar(48 * u), (int(22 * u), int(iy)))
|
|
1489
|
+
d.rounded_rectangle([82 * u, iy, sw - 22 * u, iy + 48 * u], 24 * u, fill=(54, 54, 58, 255))
|
|
1490
|
+
typed = word[:int(clamp((c.lt - 0.3) / (0.06 * len(word))) * len(word) + 1e-3)] if c.lt < t_post else ''
|
|
1491
|
+
if typed:
|
|
1492
|
+
d.text((104 * u, iy + 24 * u), typed, font=font('uib', 26 * u), fill=white, anchor='lm')
|
|
1493
|
+
if int(c.lt * 4) % 2: d.rectangle([104 * u + font('uib', 26 * u).getlength(typed) + 3 * u, iy + 10 * u, 106 * u + font('uib', 26 * u).getlength(typed) + 3 * u, iy + 38 * u], fill=(0, 149, 246, 255))
|
|
1494
|
+
else:
|
|
1495
|
+
d.text((104 * u, iy + 24 * u), f'Add a comment for {handle}', font=font('uim', 20 * u), fill=grey, anchor='lm')
|
|
1496
|
+
pressed = t_post - 0.08 <= c.lt < t_post
|
|
1497
|
+
d.text((sw - 44 * u, iy + 24 * u), 'Post', font=font('uib', 23 * u), fill=(blue if typed else (70, 110, 160, 255)) if not pressed else (140, 200, 255, 255), anchor='rm')
|
|
1498
|
+
sheet = shadowed(sheet, 22, 10, 120)
|
|
1499
|
+
bottom = c.fy - c.fw * 0.5; top = bottom - sheet.height
|
|
1500
|
+
s = 1.0
|
|
1501
|
+
if top < H * 0.02: s = max(0.6, (bottom - H * 0.02) / sheet.height)
|
|
1502
|
+
cy = bottom - sheet.height * s / 2 + 3 * u * math.sin(c.lt * 3.2)
|
|
1503
|
+
place(c, sheet, W / 2 * 0.5 + c.fx * 0.5, cy, s * (0.85 + 0.15 * ease_back(c.lt / 0.3)), 1.2, al * clamp(c.lt / 0.1), behind=True)
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
@effect('comment-box', 'an Instagram comments sheet above your head types your word, posts it, gets a heart and your reply')
|
|
1507
|
+
def fx_comment_box(c, e):
|
|
1508
|
+
(comment_bar if e.o.get('look') == 'bar' else comment_sheet)(c, e)
|
|
1509
|
+
|
|
1510
|
+
|
|
1511
|
+
# ---------- pack 3: showcase effects (added 23 Oct 2026) ----------
|
|
1512
|
+
def num_parts(s):
|
|
1513
|
+
"""'197K' -> (197.0, 'K', 0 decimals); '59%' -> (59.0, '%', 0); '4.8' -> (4.8, '', 1)."""
|
|
1514
|
+
s = str(s).strip(); i = len(s)
|
|
1515
|
+
while i and not (s[i - 1].isdigit()): i -= 1
|
|
1516
|
+
n = s[:i].replace(',', '') or '0'
|
|
1517
|
+
return float(n), s[i:], (len(n.split('.')[1]) if '.' in n else 0)
|
|
1518
|
+
|
|
1519
|
+
|
|
1520
|
+
@effect('liquid-glass-graph', 'a liquid glass card floats under your chin while a graph climbs and the number counts up')
|
|
1521
|
+
def fx_liquid_glass_graph(c, e):
|
|
1522
|
+
if e.o.get('look') == 'bento': return glass_bento(c, e)
|
|
1523
|
+
q = ease_out(c.lt / 0.4); al = fade(c, e) * clamp(c.lt / 0.12)
|
|
1524
|
+
if al <= 0: return
|
|
1525
|
+
W = c.W; cw, ch = int(W * 0.74), int(W * 0.46); sc = 0.88 + 0.12 * q
|
|
1526
|
+
cx = W / 2; cy = min(c.H - ch * 0.62, c.fy + c.fw * 2.7) + (1 - q) * W * 0.08
|
|
1527
|
+
gw, gh = int(cw * sc), int(ch * sc)
|
|
1528
|
+
im = glass(c, gw, gh, gh * 0.12, cx, cy, amt=0.16, blur=max(10, W // 30), dark=0.12)
|
|
1529
|
+
hi = cached(e, ('hi', gw, gh), lambda: Image.fromarray(np.dstack([np.full((gh, gw, 3), 255, np.uint8),
|
|
1530
|
+
(np.clip(1 - np.linspace(0, 1, gh) * 2.2, 0, 1)[:, None] * np.ones(gw) * 46).astype(np.uint8)]), 'RGBA'))
|
|
1531
|
+
hm = Image.new('L', (gw, gh), 0); ImageDraw.Draw(hm).rounded_rectangle([0, 0, gw - 1, gh - 1], int(gh * 0.12), fill=255)
|
|
1532
|
+
hl = hi.copy(); hl.putalpha(Image.fromarray(np.minimum(np.asarray(hi)[..., 3], np.asarray(hm)))); im.alpha_composite(hl)
|
|
1533
|
+
lay = Image.new('RGBA', (gw, gh), (0, 0, 0, 0)); d = ImageDraw.Draw(lay); pad = gw * 0.07
|
|
1534
|
+
g = ease_inout((c.lt - 0.25) / max(0.3, e.d * 0.72))
|
|
1535
|
+
lab = e.o.get('text', 'RETENTION').upper()
|
|
1536
|
+
d.text((pad, pad * 0.9), lab, font=font('mono', gw * 0.04), fill=(255, 255, 255, 190))
|
|
1537
|
+
a, _, _ = num_parts(e.o.get('from', '0')); b, suf, dp = num_parts(e.o.get('to', '59%'))
|
|
1538
|
+
v = a + (b - a) * g; s = f'{v:.{dp}f}{suf}'
|
|
1539
|
+
f = font('uib', gw * 0.12); d.text((gw - pad - f.getlength(s), pad * 0.55), s, font=f, fill=(255, 255, 255, 255))
|
|
1540
|
+
x0, x1, y0, y1 = pad, gw - pad, gh - pad * 0.9, gh * 0.36
|
|
1541
|
+
def ycurve(u): return y0 - (y0 - y1) * (u ** 1.5) + math.sin(u * 13) * gh * 0.018 * (1 - u)
|
|
1542
|
+
n = 60; pts = [(x0 + (x1 - x0) * j / n, ycurve(j / n)) for j in range(int(n * g) + 1)]
|
|
1543
|
+
green = rgb(e.o.get('color'), (52, 211, 110))
|
|
1544
|
+
if len(pts) > 1:
|
|
1545
|
+
area = Image.new('RGBA', (gw, gh), (0, 0, 0, 0))
|
|
1546
|
+
ImageDraw.Draw(area).polygon(pts + [(pts[-1][0], y0), (x0, y0)], fill=green + (55,)); lay.alpha_composite(area)
|
|
1547
|
+
glow = Image.new('RGBA', (gw, gh), (0, 0, 0, 0)); lw = max(4, int(gw * 0.011))
|
|
1548
|
+
ImageDraw.Draw(glow).line(pts, fill=green + (255,), width=lw * 3, joint='curve')
|
|
1549
|
+
lay.alpha_composite(glow.filter(ImageFilter.GaussianBlur(lw * 2)))
|
|
1550
|
+
ImageDraw.Draw(lay).line(pts, fill=green + (255,), width=lw, joint='curve')
|
|
1551
|
+
hx, hy = pts[-1]; r = lw * 1.9
|
|
1552
|
+
ImageDraw.Draw(lay).ellipse([hx - r, hy - r, hx + r, hy + r], fill=(255, 255, 255, 255), outline=green + (255,), width=max(2, lw // 2))
|
|
1553
|
+
for j in range(1, 4):
|
|
1554
|
+
yy = y0 - (y0 - y1) * j / 3.4
|
|
1555
|
+
d.line([(x0, yy), (x1, yy)], fill=(255, 255, 255, 40), width=max(1, int(gw * 0.002)))
|
|
1556
|
+
im.alpha_composite(lay)
|
|
1557
|
+
place(c, shadowed(im, max(10, W // 70), W // 90, 90), cx, cy, alpha=al, guard=True)
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
@effect('carousel-spin', 'your reels spin around you in a 3D carousel, then slow to a stop')
|
|
1561
|
+
def fx_carousel_spin(c, e):
|
|
1562
|
+
K = int(e.o.get('count', max(6, min(12, len(e.cards))))); cw = int(c.W * float(e.o.get('size', 0.3)))
|
|
1563
|
+
def mk():
|
|
1564
|
+
out = []
|
|
1565
|
+
for i, im in enumerate(e.cards):
|
|
1566
|
+
f = card(vary(im, i) if e.o.get('images') is None else im, cw)
|
|
1567
|
+
dk = f.copy(); a = np.asarray(dk).copy(); a[..., :3] = (a[..., :3] * 0.55).astype(np.uint8); out.append((f, Image.fromarray(a, 'RGBA')))
|
|
1568
|
+
return out
|
|
1569
|
+
cards = cached(e, 'cards', mk)
|
|
1570
|
+
k = ramp(c, e, 0.3, 0.25); xx, yy = grid(c)
|
|
1571
|
+
d = ((xx - c.fx) / (c.W * 0.55)) ** 2 + ((yy - (c.fy + c.H * 0.15)) / (c.H * 0.5)) ** 2
|
|
1572
|
+
dim = 1 - k * 0.5 * np.clip(d, 0, 1) - k * 0.12
|
|
1573
|
+
c.img *= (dim * (1 - c.m) + c.m)[..., None]
|
|
1574
|
+
p = clamp(c.lt / e.d); spin = float(e.o.get('turns', 1.1)) * 2 * math.pi * (1 - (1 - p) ** 2.4)
|
|
1575
|
+
intro, out = ease_out(c.lt / 0.45), fade(c, e, 0.25)
|
|
1576
|
+
R, ry = c.W * 0.56 * intro, c.H * 0.07
|
|
1577
|
+
cy = c.fy + c.fw * 1.8
|
|
1578
|
+
items = sorted((math.cos(i * 2 * math.pi / K + spin), i * 2 * math.pi / K + spin, i) for i in range(K))
|
|
1579
|
+
for depth, th, i in items:
|
|
1580
|
+
n = len(cards); f, dk = cards[(i * (3 if n % 3 else 2)) % n]; src = f if depth >= 0 else dk # spread similar covers apart
|
|
1581
|
+
sx = max(0.06, abs(math.cos(th)) ** 0.6)
|
|
1582
|
+
s = (0.72 + 0.34 * (depth + 1) / 2) * (0.5 + 0.5 * intro)
|
|
1583
|
+
w2, h2 = max(2, int(src.width * s * sx)), max(2, int(src.height * s))
|
|
1584
|
+
place(c, src.resize((w2, h2), Image.BILINEAR), c.fx + R * math.sin(th), cy + ry * depth, 1.0, 0,
|
|
1585
|
+
out * clamp(c.lt / 0.12) * (0.85 + 0.15 * depth), behind=depth < 0, guard=depth >= 0)
|
|
1586
|
+
|
|
1587
|
+
|
|
1588
|
+
MATCH_TXT = ('one clip went in and every cut came back before lunch while editors once spent whole weeks rebuilding the same '
|
|
1589
|
+
'timeline by hand early users called it unsettling then impossible to ignore the dead air was gone the captions '
|
|
1590
|
+
'matched and the colour finally looked like the room it was shot in nobody opened an editing app all week').split()
|
|
1591
|
+
|
|
1592
|
+
|
|
1593
|
+
def match_page(c, e, j, wx, wy):
|
|
1594
|
+
"""One article page, with the key word in a red box locked at (wx, wy)."""
|
|
1595
|
+
W, H = c.W, c.H; rnd = random.Random(31 + j)
|
|
1596
|
+
paper = [(246, 243, 236), (236, 229, 212), (251, 251, 250), (241, 236, 228), (232, 232, 230), (248, 240, 228)][j % 6]
|
|
1597
|
+
kind = ['serif', 'mont', 'ui', 'serif', 'anton', 'monts'][j % 6]
|
|
1598
|
+
size = W * [0.085, 0.07, 0.072, 0.095, 0.08, 0.068][j % 6]; f = font(kind, size); lh = size * 1.22
|
|
1599
|
+
word = e.o.get('text', 'Claude'); red = rgb(e.o.get('color'), (214, 40, 40))
|
|
1600
|
+
im = Image.new('RGB', (W, H), paper); d = ImageDraw.Draw(im); ink = (40, 38, 36)
|
|
1601
|
+
base = f.getbbox('Ag'); asc = -base[1]
|
|
1602
|
+
ww = f.getlength(word); bx0 = wx - ww / 2
|
|
1603
|
+
def run(x, y, direction):
|
|
1604
|
+
while (x < W + size if direction > 0 else x > -size * 6):
|
|
1605
|
+
w_ = rnd.choice(MATCH_TXT) + ' '
|
|
1606
|
+
if direction < 0: x -= f.getlength(w_)
|
|
1607
|
+
d.text((x, y), w_, font=f, fill=ink)
|
|
1608
|
+
if direction > 0: x += f.getlength(w_)
|
|
1609
|
+
off = rnd.uniform(0, size * 3)
|
|
1610
|
+
ys = wy - asc - lh * math.ceil((wy - asc) / lh + 1)
|
|
1611
|
+
y = ys
|
|
1612
|
+
while y < H + lh:
|
|
1613
|
+
if abs(y - (wy - asc)) < 1: pass
|
|
1614
|
+
else: run(-off - rnd.uniform(0, size * 4), y, 1)
|
|
1615
|
+
y += lh
|
|
1616
|
+
ky = wy - asc
|
|
1617
|
+
d.rectangle([0, ky - lh * 0.1, W, ky + lh * 0.95], fill=paper)
|
|
1618
|
+
run(bx0 - size * 0.45, ky, -1); run(bx0 + ww + size * 0.45, ky, 1)
|
|
1619
|
+
a = np.asarray(im, np.float32) / 255
|
|
1620
|
+
bl = cv2.GaussianBlur(a, (0, 0), W * 0.006)
|
|
1621
|
+
yy, xx = np.ogrid[0:H, 0:W]
|
|
1622
|
+
dd = np.clip((((xx - wx) / (W * 0.62)) ** 2 + ((yy - wy) / (H * 0.32)) ** 2) - 0.15, 0, 1)[..., None]
|
|
1623
|
+
a = a * (1 - dd) + bl * dd
|
|
1624
|
+
a *= (1 - 0.18 * np.clip(dd * 1.4, 0, 1))
|
|
1625
|
+
pg = Image.fromarray((a * 255).astype(np.uint8)).convert('RGBA')
|
|
1626
|
+
bf = font(kind, size); bb = bf.getbbox(word); padx, pady = size * 0.22, size * 0.12
|
|
1627
|
+
box = rrect(ww + 2 * padx, (bb[3] - bb[1]) + 2 * pady + size * 0.08, size * 0.08, red + (255,))
|
|
1628
|
+
ImageDraw.Draw(box).text((padx, pady - bb[1]), word, font=bf, fill=(255, 255, 255, 255))
|
|
1629
|
+
pg.alpha_composite(box, (int(bx0 - padx), int(wy - asc + bb[1] - pady)))
|
|
1630
|
+
return np.asarray(pg.convert('RGB'), np.uint8)
|
|
1631
|
+
|
|
1632
|
+
|
|
1633
|
+
@effect('match-cut', 'news pages cut on one word, locked in place behind your head')
|
|
1634
|
+
def fx_match_cut(c, e):
|
|
1635
|
+
k = clamp(c.lt / 0.06) * fade(c, e, 0.12)
|
|
1636
|
+
face_cam(c, 1 + 0.06 * ease_out(c.lt / e.d), 0.44)
|
|
1637
|
+
wx, wy = cached(e, 'anchor', lambda: (c.W / 2, max(c.H * 0.1, c.fy - c.fw * 1.55)))
|
|
1638
|
+
durs = [0.15, 0.15, 0.17, 0.19, 0.22, 0.26, 0.3, 0.45]; t, j = c.lt, 0
|
|
1639
|
+
while j < len(durs) - 1 and t > durs[j]: t -= durs[j]; j += 1
|
|
1640
|
+
pg = cached(e, ('pg', j), lambda: match_page(c, e, j, wx, wy)).astype(np.float32) / 255
|
|
1641
|
+
m = c.m[..., None]
|
|
1642
|
+
c.img = c.img * (1 - k) + (pg * (1 - m) + c.img * m) * k
|
|
1643
|
+
|
|
1644
|
+
|
|
1645
|
+
@effect('apple-toggles', 'an iPhone settings card under your chin flips its switches on, one line at a time')
|
|
1646
|
+
def fx_apple_toggles(c, e):
|
|
1647
|
+
rows = e.o.get('text', 'One clip|Type /effects|Zero editing apps').split('|')
|
|
1648
|
+
if e.o.get('pos', 'above') != 'below': face_cam(c, 1 + (float(e.o.get('zoom', 1.12)) - 1) * ease_out(c.lt / 0.5), 0.56)
|
|
1649
|
+
W = c.W; cw = int(W * 0.72); rh = int(W * 0.125); ch = rh * len(rows); r = int(W * 0.055)
|
|
1650
|
+
tw, th = int(W * 0.135), int(W * 0.08); tx = cw - int(W * 0.05) - tw
|
|
1651
|
+
def base():
|
|
1652
|
+
im = rrect(cw, ch, r, (255, 255, 255, 250)); d = ImageDraw.Draw(im)
|
|
1653
|
+
f = font('ui', W * 0.05)
|
|
1654
|
+
for i, s in enumerate(rows):
|
|
1655
|
+
d.text((W * 0.05, i * rh + rh / 2), s, font=f, fill=(18, 18, 20, 255), anchor='lm')
|
|
1656
|
+
if i: d.line([(W * 0.05, i * rh), (cw, i * rh)], fill=(222, 222, 226, 255), width=max(2, W // 900))
|
|
1657
|
+
pad = max(10, W // 60) * 2 + W // 90
|
|
1658
|
+
return shadowed(im, max(10, W // 60), W // 90, 110), pad
|
|
1659
|
+
sh, pad = cached(e, 'base', base)
|
|
1660
|
+
ts = [float(x) for x in e.o['ticks'].split('|')] if e.o.get('ticks') else [0.45 + 0.34 * i for i in range(len(rows))]
|
|
1661
|
+
im = sh.copy(); d = ImageDraw.Draw(im)
|
|
1662
|
+
off, on = np.float32((233, 233, 235)), np.float32(rgb(e.o.get('color'), (52, 199, 89)))
|
|
1663
|
+
for i in range(len(rows)):
|
|
1664
|
+
u = ease_out((c.lt - ts[i]) / 0.2) if i < len(ts) else 0.0
|
|
1665
|
+
col = tuple(int(v) for v in off * (1 - u) + on * u) + (255,)
|
|
1666
|
+
x0, y0 = pad + tx, pad + i * rh + (rh - th) / 2
|
|
1667
|
+
d.rounded_rectangle([x0, y0, x0 + tw, y0 + th], th // 2, fill=col)
|
|
1668
|
+
kr = th / 2 - W * 0.006; kx = x0 + th / 2 + (tw - th) * u; ky = y0 + th / 2
|
|
1669
|
+
d.ellipse([kx - kr, ky - kr + W * 0.002, kx + kr, ky + kr + W * 0.004], fill=(0, 0, 0, 40))
|
|
1670
|
+
d.ellipse([kx - kr, ky - kr, kx + kr, ky + kr], fill=(255, 255, 255, 255))
|
|
1671
|
+
q = pop(c, 0.0, 0.38); al = fade(c, e) * clamp(c.lt / 0.1)
|
|
1672
|
+
if e.o.get('pos', 'above') == 'below':
|
|
1673
|
+
place(c, im, c.W / 2, min(c.H - ch * 0.75, c.fy + c.fw * 2.5), 0.6 + 0.4 * q, 0, al, guard=True); return
|
|
1674
|
+
# above you, tucked behind your head: your hair overlaps only the bottom edge
|
|
1675
|
+
cy = max(c.H * 0.08 + ch / 2, c.fy - c.fw * 0.95 + c.fw * float(e.o.get('overlap', 0.08)) - ch / 2)
|
|
1676
|
+
place(c, im, c.W / 2, cy + (1 - q) * c.W * 0.04, 0.6 + 0.4 * q, 0, al, behind=True)
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
@effect('led-sign', 'the lights drop and a glowing LED sign types itself out behind you')
|
|
1680
|
+
def fx_led_sign(c, e):
|
|
1681
|
+
k = ramp(c, e, 0.2, 0.2)
|
|
1682
|
+
face_cam(c, 1 + (float(e.o.get('push', 1.08)) - 1) * ease_inout(c.lt / e.d), 0.42)
|
|
1683
|
+
lines = e.o.get('text', 'CLAUDE').upper().split('|'); col = np.float32(rgb(e.o.get('color'), (255, 146, 48))) / 255
|
|
1684
|
+
def setup():
|
|
1685
|
+
mats = []
|
|
1686
|
+
for s in lines:
|
|
1687
|
+
f = font('uib', 40); w = int(f.getlength(s)) + 8
|
|
1688
|
+
im = Image.new('L', (w, 56), 0); ImageDraw.Draw(im).text((4, 2), s, font=f, fill=255)
|
|
1689
|
+
bb = im.getbbox() or (0, 0, w, 56); im = im.crop(bb)
|
|
1690
|
+
rows = 11; cols = max(1, round(im.width / im.height * rows))
|
|
1691
|
+
mats.append(np.asarray(im.resize((cols, rows), Image.BOX), np.float32) / 255 > 0.42)
|
|
1692
|
+
cols = max(m.shape[1] for m in mats) + 2
|
|
1693
|
+
cell = int(min(c.W * 0.96 / cols, c.H * 0.3 / (len(mats) * 12)))
|
|
1694
|
+
L = np.zeros((len(mats) * 12 - 1, cols), np.float32)
|
|
1695
|
+
for i, m in enumerate(mats): o = (cols - m.shape[1]) // 2; L[i * 12:i * 12 + 11, o:o + m.shape[1]] = m
|
|
1696
|
+
yy, xx = np.mgrid[0:cell, 0:cell].astype(np.float32); rr = np.hypot(xx - cell / 2 + 0.5, yy - cell / 2 + 0.5)
|
|
1697
|
+
dot = np.clip(cell * 0.36 - rr + 0.5, 0, 1)
|
|
1698
|
+
return L, cell, dot, np.random.default_rng(3).random(L.shape).astype(np.float32)
|
|
1699
|
+
L, cell, dot, rnd = cached(e, 'm', setup)
|
|
1700
|
+
rows, cols = L.shape
|
|
1701
|
+
sweep = clamp((c.lt - 0.15) / 0.75) * (cols + 4)
|
|
1702
|
+
lit = L * np.clip((sweep - np.arange(cols)[None, :]) / 3, 0, 1)
|
|
1703
|
+
flick = 0.82 + 0.18 * np.sin(rnd * 50 + c.lt * 30)
|
|
1704
|
+
b = np.maximum(lit * flick, 0.09)
|
|
1705
|
+
pan = np.kron(b, dot)[..., None] * col
|
|
1706
|
+
glow = cv2.GaussianBlur(pan, (0, 0), cell * 0.9)
|
|
1707
|
+
pan = np.clip(pan + glow * 1.6, 0, 1)
|
|
1708
|
+
ph, pw = pan.shape[:2]; x0 = int(c.W / 2 - pw / 2)
|
|
1709
|
+
y0 = int(max(c.H * 0.03, c.fy - c.fw * 0.75 - ph))
|
|
1710
|
+
xx, yy = grid(c)
|
|
1711
|
+
d = ((xx - c.fx) / (c.W * 0.6)) ** 2 + ((yy - (c.fy + c.H * 0.25)) / (c.H * 0.55)) ** 2
|
|
1712
|
+
bright = 1 - k * (0.84 - 0.3 * np.clip(1 - d, 0, 1))
|
|
1713
|
+
c.img *= (bright * (1 - c.m) + c.m * (1 - 0.18 * k))[..., None]
|
|
1714
|
+
xa, xb = max(0, x0), min(c.W, x0 + pw); ya, yb = max(0, y0), min(c.H, y0 + ph)
|
|
1715
|
+
if xb > xa and yb > ya:
|
|
1716
|
+
sub = pan[ya - y0:yb - y0, xa - x0:xb - x0] * k * (1 - c.m[ya:yb, xa:xb, None])
|
|
1717
|
+
c.img[ya:yb, xa:xb] = np.clip(c.img[ya:yb, xa:xb] + sub, 0, 1)
|
|
1718
|
+
|
|
1719
|
+
|
|
1720
|
+
@effect('slow-push', 'a slow cinematic push-in from the wide shot to your face, the room melting out of focus')
|
|
1721
|
+
def fx_slow_push(c, e):
|
|
1722
|
+
p = ease_inout(c.lt / e.d)
|
|
1723
|
+
face_cam(c, 1 + (float(e.o.get('zoom', 1.6)) - 1) * p, 0.4)
|
|
1724
|
+
s = c.W * float(e.o.get('blur', 0.006)) * p
|
|
1725
|
+
if s > 0.6:
|
|
1726
|
+
bl = cv2.GaussianBlur(c.img, (0, 0), s); m = c.m[..., None]
|
|
1727
|
+
c.img = c.img * m + bl * (1 - m)
|
|
1728
|
+
vignette(c, 0.25 * p)
|
|
1729
|
+
|
|
1730
|
+
|
|
1731
|
+
# ---------- pack 3 looks: sparkle spotlight, editorial cover, glass bento (added 23 Oct 2026) ----------
|
|
1732
|
+
def star(size, color=(255, 244, 222)):
|
|
1733
|
+
"""A 4-point sparkle with a soft glow."""
|
|
1734
|
+
s = max(8, int(size)); h = s / 2; t = s * 0.075
|
|
1735
|
+
im = Image.new('RGBA', (s, s), (0, 0, 0, 0))
|
|
1736
|
+
ImageDraw.Draw(im).polygon([(h, s * 0.02), (h + t, h - t), (s * 0.98, h), (h + t, h + t), (h, s * 0.98), (h - t, h + t), (s * 0.02, h), (h - t, h - t)], fill=tuple(color) + (255,))
|
|
1737
|
+
g = im.filter(ImageFilter.GaussianBlur(s * 0.07)); out = Image.alpha_composite(g, g); out.alpha_composite(im)
|
|
1738
|
+
r = s * 0.07; ImageDraw.Draw(out).ellipse([h - r, h - r, h + r, h + r], fill=(255, 255, 255, 255))
|
|
1739
|
+
return out
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
def gradient_text(s, size, kind, top, bot, glow=None):
|
|
1743
|
+
"""Text filled with a vertical colour gradient (gold, chrome...), with an optional glow."""
|
|
1744
|
+
f = font(kind, size); bb = f.getbbox(s); pad = int(size * 0.25 + (glow[1] * 2.5 if glow else 0))
|
|
1745
|
+
w, h = bb[2] - bb[0] + 2 * pad, bb[3] - bb[1] + 2 * pad
|
|
1746
|
+
m = Image.new('L', (w, h), 0); ImageDraw.Draw(m).text((pad - bb[0], pad - bb[1]), s, font=f, fill=255)
|
|
1747
|
+
g = np.linspace(0, 1, h)[:, None, None]; col = np.float32(top) * (1 - g) + np.float32(bot) * g
|
|
1748
|
+
im = Image.fromarray(np.dstack([np.broadcast_to(col, (h, w, 3)).astype(np.uint8), np.asarray(m)]), 'RGBA')
|
|
1749
|
+
if glow:
|
|
1750
|
+
gl = Image.new('RGBA', (w, h), tuple(glow[0]) + (0,)); gl.putalpha(m.filter(ImageFilter.GaussianBlur(glow[1])))
|
|
1751
|
+
im = Image.alpha_composite(Image.alpha_composite(gl, gl), im)
|
|
1752
|
+
return im
|
|
1753
|
+
|
|
1754
|
+
|
|
1755
|
+
def spotlight_sparkle(c, e):
|
|
1756
|
+
k = ramp(c, e, 0.25, 0.2); W, H = c.W, c.H
|
|
1757
|
+
face_cam(c, 1 + (float(e.o.get('push', 1.12)) - 1) * ease_inout(c.lt / e.d), 0.46)
|
|
1758
|
+
gold = np.float32(rgb(e.o.get('color'), (255, 190, 128))) / 255
|
|
1759
|
+
xx, yy = grid(c)
|
|
1760
|
+
d = ((xx - c.fx) / (W * 0.55)) ** 2 + ((yy - (c.fy + H * 0.15)) / (H * 0.5)) ** 2
|
|
1761
|
+
pool = np.clip(1 - d, 0, 1) ** 1.5
|
|
1762
|
+
c.img *= ((1 - k * (0.92 - 0.3 * pool)) * (1 - c.m) + c.m * (1 + 0.06 * k))[..., None]
|
|
1763
|
+
ox, oy = c.fx, c.fy - c.fw * 1.1
|
|
1764
|
+
q = 4; sy, sx = np.mgrid[0:H // q, 0:W // q].astype(np.float32) * q
|
|
1765
|
+
ang = np.arctan2(sy - oy, sx - ox); rad = np.hypot(sx - ox, sy - oy)
|
|
1766
|
+
rays = (0.5 + 0.5 * np.cos(16 * ang + c.lt * 0.9)) ** 5 * np.exp(-rad / (H * 0.42)) + 0.9 * np.exp(-(rad / (H * 0.2)) ** 2)
|
|
1767
|
+
rays = cv2.resize(rays.astype(np.float32), (W, H), interpolation=cv2.INTER_LINEAR)
|
|
1768
|
+
halo = np.clip(cv2.GaussianBlur(c.m, (0, 0), W * 0.012) * 1.6 - c.m, 0, 1)
|
|
1769
|
+
c.img += (rays * 0.32 + halo * 0.7)[..., None] * gold * k * (1 - c.m[..., None])
|
|
1770
|
+
word = e.o.get('text', 'CLAUDE')
|
|
1771
|
+
def wimg():
|
|
1772
|
+
size = int(H * 0.2)
|
|
1773
|
+
while size > 20 and font('didonei', size).getlength(word) > W * 0.86: size = int(size * 0.94)
|
|
1774
|
+
im = gradient_text(word, size, 'didonei', (255, 255, 250), (255, 200, 130), glow=(tuple(int(v * 255) for v in gold), size * 0.06))
|
|
1775
|
+
im = shadowed(im, int(size * 0.05), 0, 200)
|
|
1776
|
+
return np.asarray(im, np.float32) / 255
|
|
1777
|
+
wa = cached(e, 'w', wimg); wh, ww = wa.shape[:2]
|
|
1778
|
+
band = np.exp(-(((np.arange(ww)[None, :] + np.arange(wh)[:, None] * 0.5) - (-0.3 + 1.6 * clamp((c.lt - 0.25) / 0.9)) * ww * 1.3) / (ww * 0.07)) ** 2)
|
|
1779
|
+
w2 = wa.copy(); w2[..., :3] = np.clip(w2[..., :3] + band[..., None] * 0.9, 0, 1)
|
|
1780
|
+
s = 1.08 - 0.08 * ease_out(c.lt / 0.5)
|
|
1781
|
+
im = Image.fromarray((w2 * 255).astype(np.uint8), 'RGBA')
|
|
1782
|
+
place(c, im, W / 2, max(wh * 0.5 + H * 0.06, c.fy - c.fw * 1.05 - wh * 0.28), s, 0, k, behind=True)
|
|
1783
|
+
def spots():
|
|
1784
|
+
rnd = random.Random(9)
|
|
1785
|
+
return [(rnd.uniform(0.04, 0.96), rnd.uniform(0.07, 0.62), rnd.uniform(0.025, 0.07), rnd.uniform(0, 6.3), rnd.uniform(5, 9), rnd.random() < 0.35) for _ in range(48)]
|
|
1786
|
+
spr = cached(e, 'star', lambda: star(W * 0.07))
|
|
1787
|
+
for x, y, sz, ph, sp, front in cached(e, 'sp', spots):
|
|
1788
|
+
a = max(0.0, math.sin(ph + c.lt * sp)) ** 2 * k
|
|
1789
|
+
if a < 0.03: continue
|
|
1790
|
+
sc = sz / 0.07 * (0.45 + 0.75 * a)
|
|
1791
|
+
place(c, spr, x * W, y * H, sc, c.lt * 40 + ph * 30, a, behind=not front, guard=front)
|
|
1792
|
+
|
|
1793
|
+
|
|
1794
|
+
def cover_editorial(c, e):
|
|
1795
|
+
k = ease_out(c.lt / 0.35); al = fade(c, e); W, H = c.W, c.H
|
|
1796
|
+
lum = (c.img @ np.float32([0.299, 0.587, 0.114]))[..., None]
|
|
1797
|
+
soft = (c.img * 0.82 + lum * 0.18) * 0.9 + np.float32((252, 238, 228)) / 255 * 0.1
|
|
1798
|
+
q = 4; bl = cv2.resize(np.clip(c.img[::q, ::q] - 0.62, 0, 1), (W, H), interpolation=cv2.INTER_LINEAR)
|
|
1799
|
+
bloom = cv2.GaussianBlur(bl, (0, 0), W * 0.012)
|
|
1800
|
+
c.img = c.img * (1 - k) + np.clip(soft + bloom * 0.55, 0, 1) * k
|
|
1801
|
+
ink, rose = rgb(e.o.get('color'), (26, 20, 22)), rgb(e.o.get('accent'), (168, 70, 94))
|
|
1802
|
+
cream = (252, 244, 236)
|
|
1803
|
+
title = e.o.get('text', 'EFFECTS').upper()
|
|
1804
|
+
def mast():
|
|
1805
|
+
size = int(H * 0.16)
|
|
1806
|
+
while size > 20 and font('didoneb', size).getlength(title) + size * 0.04 * len(title) > W * 0.92: size = int(size * 0.95)
|
|
1807
|
+
return tracked(title, size, 'didoneb', ink, size * 0.04)
|
|
1808
|
+
m = cached(e, 'm', mast)
|
|
1809
|
+
s = 1.05 - 0.05 * ease_out(c.lt / 0.5)
|
|
1810
|
+
place(c, m, W / 2, H * 0.085 + m.height / 2, s, 0, al * k, behind=True)
|
|
1811
|
+
iss = cached(e, 'i', lambda: tracked(e.o.get('issue', 'THE ONE-CLIP ISSUE · NO. 42 · OCTOBER 2026'), int(W * 0.022), 'ui', ink, W * 0.006))
|
|
1812
|
+
place(c, iss, W / 2, H * 0.075, alpha=al * k, behind=True)
|
|
1813
|
+
rule = cached(e, 'r', lambda: rrect(W * 0.86, max(3, W // 600), 1, ink + (255,)))
|
|
1814
|
+
place(c, rule, W / 2, H * 0.087 + m.height, alpha=al * k * 0.8, behind=True)
|
|
1815
|
+
lines = e.o.get('lines', 'One clip,|42 looks.|NO EDITOR · NO APPS').split('|')
|
|
1816
|
+
styles = [('didonei', 0.085, ink), ('didoneb', 0.105, rose), ('ui', 0.03, ink)]
|
|
1817
|
+
y = H * float(e.o.get('lines_y', 0.575))
|
|
1818
|
+
for j, ln in enumerate(lines):
|
|
1819
|
+
kind, sz, col = styles[min(j, 2)]
|
|
1820
|
+
im = cached(e, ('l', j), lambda: (tracked(ln, int(W * sz), kind, col, W * 0.006) if kind == 'ui' else text_img(ln, W * sz, kind, col, glow=(cream, W * 0.012))))
|
|
1821
|
+
kj = ease_out((c.lt - 0.2 - 0.1 * j) / 0.35)
|
|
1822
|
+
comp(c, im, W * 0.05 - (1 - kj) * W * 0.03, y, al * kj); y += im.height * (0.82 if kind != 'ui' else 1.6)
|
|
1823
|
+
right = e.o.get('right', 'the art of the|effortless edit').split('|')
|
|
1824
|
+
y = H * float(e.o.get('right_y', 0.715))
|
|
1825
|
+
for j, ln in enumerate(right):
|
|
1826
|
+
im = cached(e, ('r', j), lambda: text_img(ln, W * 0.058, 'didonei', ink, glow=(cream, W * 0.01)))
|
|
1827
|
+
kj = ease_out((c.lt - 0.45 - 0.1 * j) / 0.35)
|
|
1828
|
+
comp(c, im, W * 0.95 - im.width + (1 - kj) * W * 0.03, y, al * kj); y += im.height * 0.78
|
|
1829
|
+
|
|
1830
|
+
|
|
1831
|
+
def donut(size, pct, col, label, value):
|
|
1832
|
+
S = int(size) * 2; im = Image.new('RGBA', (S, S), (0, 0, 0, 0)); d = ImageDraw.Draw(im); w = int(S * 0.1); pad = int(S * 0.08)
|
|
1833
|
+
d.arc([pad, pad, S - pad, S - pad], 0, 360, fill=(255, 255, 255, 46), width=w)
|
|
1834
|
+
if pct > 0.002: d.arc([pad, pad, S - pad, S - pad], -90, -90 + 360 * pct, fill=tuple(col) + (255,), width=w)
|
|
1835
|
+
f = font('uib', S * 0.2); d.text((S / 2, S / 2 - S * 0.02), value, font=f, fill=(255, 255, 255, 255), anchor='mm')
|
|
1836
|
+
f2 = font('mono', S * 0.065); d.text((S / 2, S / 2 + S * 0.15), label.upper(), font=f2, fill=(255, 255, 255, 170), anchor='mm')
|
|
1837
|
+
return im.resize((int(size), int(size)), Image.LANCZOS)
|
|
1838
|
+
|
|
1839
|
+
|
|
1840
|
+
def glass_bento(c, e):
|
|
1841
|
+
W, H = c.W, c.H; al = fade(c, e) * clamp(c.lt / 0.12)
|
|
1842
|
+
if al <= 0: return
|
|
1843
|
+
green = rgb(e.o.get('color'), (52, 211, 110)); peach = (255, 160, 122)
|
|
1844
|
+
# 1. the big graph, on a smoked glass screen behind you
|
|
1845
|
+
q = ease_out(c.lt / 0.4); pw, ph = int(W * 0.9), int(H * 0.3); pcx, pcy = W / 2, H * 0.08 + ph / 2 + (1 - q) * H * 0.02
|
|
1846
|
+
pan = glass(c, pw, ph, W * 0.04, pcx, pcy, amt=0.06, dark=0.62, blur=max(10, W // 30))
|
|
1847
|
+
lay = Image.new('RGBA', (pw, ph), (0, 0, 0, 0)); d = ImageDraw.Draw(lay); pad = pw * 0.05
|
|
1848
|
+
g = ease_inout((c.lt - 0.2) / max(0.3, e.d * 0.75))
|
|
1849
|
+
d.text((pad, pad * 0.8), e.o.get('text', 'VIEWS').upper(), font=font('mono', pw * 0.026), fill=(255, 255, 255, 180))
|
|
1850
|
+
a, _, _ = num_parts(e.o.get('from', '0')); b, suf, dp = num_parts(e.o.get('to', '197K')); s = f'{a + (b - a) * g:.{dp}f}{suf}'
|
|
1851
|
+
f = font('uib', pw * 0.085); d.text((pw - pad - f.getlength(s), pad * 0.45), s, font=f, fill=(255, 255, 255, 255))
|
|
1852
|
+
x0, x1, y0, y1 = pad, pw - pad, ph - pad * 0.8, ph * 0.3
|
|
1853
|
+
for j in range(1, 4): yy = y0 - (y0 - y1) * j / 3.3; d.line([(x0, yy), (x1, yy)], fill=(255, 255, 255, 34), width=max(1, W // 1000))
|
|
1854
|
+
n = 80; pts = [(x0 + (x1 - x0) * j / n, y0 - (y0 - y1) * ((j / n) ** 1.7) + math.sin(j / n * 17) * ph * 0.02 * (1 - j / n)) for j in range(int(n * g) + 1)]
|
|
1855
|
+
if len(pts) > 1:
|
|
1856
|
+
area = Image.new('RGBA', (pw, ph), (0, 0, 0, 0)); ImageDraw.Draw(area).polygon(pts + [(pts[-1][0], y0), (x0, y0)], fill=green + (60,)); lay.alpha_composite(area)
|
|
1857
|
+
lw = max(4, int(pw * 0.006)); gl = Image.new('RGBA', (pw, ph), (0, 0, 0, 0)); ImageDraw.Draw(gl).line(pts, fill=green + (255,), width=lw * 3, joint='curve')
|
|
1858
|
+
lay.alpha_composite(gl.filter(ImageFilter.GaussianBlur(lw * 2))); ImageDraw.Draw(lay).line(pts, fill=green + (255,), width=lw, joint='curve')
|
|
1859
|
+
hx, hy = pts[-1]; r = lw * 2; ImageDraw.Draw(lay).ellipse([hx - r, hy - r, hx + r, hy + r], fill=(255, 255, 255, 255), outline=green + (255,), width=lw // 2)
|
|
1860
|
+
pan.alpha_composite(lay)
|
|
1861
|
+
place(c, pan, pcx, pcy, alpha=al * q, behind=True)
|
|
1862
|
+
# 2. the bento tiles in front of you
|
|
1863
|
+
def tile(i, cx, cy, tw, th, draw):
|
|
1864
|
+
k = pop(c, 0.15 + 0.12 * i, 0.4)
|
|
1865
|
+
if k <= 0: return
|
|
1866
|
+
t = glass(c, tw, th, W * 0.035, cx, cy, amt=0.08, dark=0.5, blur=max(10, W // 34))
|
|
1867
|
+
draw(t, ImageDraw.Draw(t), tw, th); place(c, shadowed(t, max(8, W // 80), W // 120, 90), cx, cy, 0.7 + 0.3 * k, 0, al * clamp(k * 2))
|
|
1868
|
+
dv, dl = (e.o.get('donut', '29%::ERASE share').split('::') + [''])[:2]; pct = num_parts(dv)[0] / 100
|
|
1869
|
+
def dr_donut(t, d, tw, th):
|
|
1870
|
+
p = ease_out((c.lt - 0.35) / 0.8) * pct
|
|
1871
|
+
dn = donut(tw * 0.86, p, peach, dl, f'{round(p * 100)}%'); t.alpha_composite(dn, (int((tw - dn.width) / 2), int((th - dn.height) / 2)))
|
|
1872
|
+
kv, kl = (e.o.get('kpi', '672K::views · top 7 reels').split('::') + [''])[:2]
|
|
1873
|
+
def dr_kpi(t, d, tw, th):
|
|
1874
|
+
b, suf, dp = num_parts(kv); v = b * ease_out((c.lt - 0.45) / 0.8)
|
|
1875
|
+
d.text((tw * 0.1, th * 0.18), f'{v:.{dp}f}{suf}', font=font('uib', th * 0.36), fill=(255, 255, 255, 255))
|
|
1876
|
+
d.text((tw * 0.1, th * 0.7), kl.upper(), font=font('mono', th * 0.1), fill=(255, 255, 255, 170))
|
|
1877
|
+
bv, bl = (e.o.get('bars', '197|140|124|83|50::top reels · K views').split('::') + [''])[:2]; vals = [num_parts(v)[0] for v in bv.split('|')]
|
|
1878
|
+
def dr_bars(t, d, tw, th):
|
|
1879
|
+
d.text((tw * 0.1, th * 0.06), bl.upper(), font=font('mono', tw * 0.055), fill=(255, 255, 255, 170))
|
|
1880
|
+
n = len(vals); bw = tw * 0.8 / n; top, base = th * 0.2, th * 0.88; mx = max(vals)
|
|
1881
|
+
for j, v in enumerate(vals):
|
|
1882
|
+
kk = ease_out((c.lt - 0.4 - 0.08 * j) / 0.5); hgt = (base - top) * v / mx * kk; x = tw * 0.1 + j * bw
|
|
1883
|
+
d.rounded_rectangle([x + bw * 0.14, base - hgt, x + bw * 0.86, base], int(bw * 0.18), fill=(green if j == 0 else (255, 255, 255)) + (255 if j == 0 else 150,))
|
|
1884
|
+
if kk > 0.6: d.text((x + bw / 2, base - hgt - tw * 0.02), f'{v:g}', font=font('uib', tw * 0.06), fill=(255, 255, 255, 230), anchor='md')
|
|
1885
|
+
tw = W * 0.25; gap = W * 0.02; ty = max(H * 0.5, c.fy + c.fw * 1.1)
|
|
1886
|
+
tile(0, W * 0.15, ty + tw * 0.5, tw, tw, dr_donut)
|
|
1887
|
+
tile(1, W * 0.15, ty + tw + gap + tw * 0.28, tw, tw * 0.56, dr_kpi)
|
|
1888
|
+
tile(2, W * 0.85, ty + tw * 0.65, tw, tw * 1.3, dr_bars)
|
|
1889
|
+
|
|
1890
|
+
|
|
1891
|
+
# ---------- pack 4: over-the-shoulder zoom, messages, place-in-grid (added 27 Oct 2026) ----------
|
|
1892
|
+
GREEN = (52, 211, 102)
|
|
1893
|
+
|
|
1894
|
+
|
|
1895
|
+
def liquid_glass(c, box, r=None, blur=None):
|
|
1896
|
+
"""Liquid glass panel on c.img, after liquid-glass-js (MIT, dashersw): rounded-rect SDF, edge + rim refraction
|
|
1897
|
+
along the normal, a light blur so the room still shows through, a faint top-to-bottom tint, a specular rim lit
|
|
1898
|
+
from the top-left, plus a red/blue fringe at the edge (after React Bits' GlassSurface)."""
|
|
1899
|
+
x0, y0, x1, y1 = [int(round(v)) for v in box]; w, h = x1 - x0, y1 - y0
|
|
1900
|
+
if w < 8 or h < 8: return
|
|
1901
|
+
u = c.W / 2160; r = r or 72 * u; M = int(140 * u)
|
|
1902
|
+
X0, Y0, X1, Y1 = max(0, x0 - M), max(0, y0 - M), min(c.W, x1 + M), min(c.H, y1 + M)
|
|
1903
|
+
tex = cv2.GaussianBlur(c.img[Y0:Y1, X0:X1], (0, 0), blur or 7 * u)
|
|
1904
|
+
yy, xx = np.mgrid[0:h, 0:w].astype(np.float32)
|
|
1905
|
+
q = np.stack([np.abs(xx - w / 2) - (w / 2 - r), np.abs(yy - h / 2) - (h / 2 - r)], -1)
|
|
1906
|
+
sdf = np.linalg.norm(np.maximum(q, 0), axis=-1) + np.minimum(np.maximum(q[..., 0], q[..., 1]), 0) - r
|
|
1907
|
+
d = np.maximum(-sdf, 0) / u
|
|
1908
|
+
nx, ny = xx - w / 2, yy - h / 2; nl = np.sqrt(nx * nx + ny * ny) + 1e-3; nx, ny = nx / nl, ny / nl
|
|
1909
|
+
k = (70 * np.exp(-d / 14) + 34 * np.exp(-d / 70) + 10 * np.exp(-d / 260)) * u
|
|
1910
|
+
out = np.zeros((h, w, 3), np.float32)
|
|
1911
|
+
for ch, fr in enumerate((1.10, 1.0, 0.90)):
|
|
1912
|
+
mx = (xx + x0 - X0 + nx * k * fr).astype(np.float32); my = (yy + y0 - Y0 + ny * k * fr).astype(np.float32)
|
|
1913
|
+
out[..., ch] = cv2.remap(tex[..., ch], mx, my, cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT)
|
|
1914
|
+
out = out * 0.86 + 0.06 * (1.0 - 0.30 * (yy / h))[..., None] - 0.05
|
|
1915
|
+
spec = np.exp(-d / 5) * np.clip(0.55 - 0.45 * (nx * 0.6 + ny * 0.8), 0, 1)
|
|
1916
|
+
out = np.clip(out + (spec * 0.85 + np.exp(-d / 30) * 0.10)[..., None], 0, 1)
|
|
1917
|
+
a = np.clip(0.5 - sdf, 0, 1)[..., None]
|
|
1918
|
+
gx0, gy0, gx1, gy1 = max(0, x0), max(0, y0), min(c.W, x1), min(c.H, y1)
|
|
1919
|
+
sl = (slice(gy0 - y0, gy1 - y0), slice(gx0 - x0, gx1 - x0))
|
|
1920
|
+
dst = c.img[gy0:gy1, gx0:gx1]; dst[:] = dst * (1 - a[sl]) + out[sl] * a[sl]
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
def split_num(s):
|
|
1924
|
+
"""'197K' -> (197.0, 'K', 0 decimals); '82%' -> (82.0, '%', 0); '1.2M' -> (1.2, 'M', 1)."""
|
|
1925
|
+
import re as _re
|
|
1926
|
+
m = _re.match(r'\s*([\d.,]+)\s*(.*)', str(s)); n = m.group(1).replace(',', '') if m else '0'
|
|
1927
|
+
return float(n), (m.group(2) if m else ''), (len(n.split('.')[1]) if '.' in n else 0)
|
|
1928
|
+
|
|
1929
|
+
|
|
1930
|
+
def glass_graph(c, cx, cy, k, prog, label, value, kind, scale=1.0):
|
|
1931
|
+
"""A see-through glass stat card: spaced-caps label, a number that counts up, a glowing line or bar chart."""
|
|
1932
|
+
if k <= 0: return
|
|
1933
|
+
u = c.W / 2160 * scale; sc = 0.82 + 0.18 * ease_back(k)
|
|
1934
|
+
w, h = 1760 * u * sc, 1056 * u * sc; lift = 40 * u * (1 - k)
|
|
1935
|
+
x0, y0 = cx - w / 2, cy - h / 2 + lift
|
|
1936
|
+
liquid_glass(c, (x0, y0, x0 + w, y0 + h))
|
|
1937
|
+
v = w / 1500
|
|
1938
|
+
lay = Image.new('RGBA', (int(w) + 40, int(h) + 40), (0, 0, 0, 0)); d = ImageDraw.Draw(lay); o = 20
|
|
1939
|
+
lab, big = font('uim', 44 * v), font('uib', 170 * v)
|
|
1940
|
+
num, suf, dec = split_num(value); txt = f'{num * ease_out(prog):.{dec}f}{suf}'
|
|
1941
|
+
xx = o + 64 * v
|
|
1942
|
+
for chh in label.upper(): d.text((xx, o + 64 * v), chh, font=lab, fill=(255, 255, 255, 235)); xx += lab.getlength(chh) + 9 * v
|
|
1943
|
+
d.text((o + w - 70 * v - big.getlength(txt), o + 40 * v), txt, font=big, fill=(255, 255, 255, 255))
|
|
1944
|
+
gx0, gx1, gy0, gy1 = o + 64 * v, o + w - 64 * v, o + 290 * v, o + h - 80 * v
|
|
1945
|
+
for j in range(3): d.line([gx0, gy0 + (gy1 - gy0) * j / 2, gx1, gy0 + (gy1 - gy0) * j / 2], fill=(255, 255, 255, 70), width=max(1, int(3 * v)))
|
|
1946
|
+
halo = Image.new('RGBA', lay.size, (0, 0, 0, 0)); hd = ImageDraw.Draw(halo)
|
|
1947
|
+
xx = o + 64 * v
|
|
1948
|
+
for chh in label.upper(): hd.text((xx, o + 64 * v), chh, font=lab, fill=(0, 0, 0, 150)); xx += lab.getlength(chh) + 9 * v
|
|
1949
|
+
hd.text((o + w - 70 * v - big.getlength(txt), o + 40 * v), txt, font=big, fill=(0, 0, 0, 150))
|
|
1950
|
+
base = halo.filter(ImageFilter.GaussianBlur(10 * v))
|
|
1951
|
+
chart = Image.new('RGBA', lay.size, (0, 0, 0, 0)); cd = ImageDraw.Draw(chart)
|
|
1952
|
+
if kind == 'line':
|
|
1953
|
+
ys = [0.04, 0.07, 0.10, 0.16, 0.22, 0.35, 0.52, 0.74, 1.0]; n = max(0.02, (len(ys) - 1) * ease_out(prog)); pts = []
|
|
1954
|
+
for i in range(int(n) + 1):
|
|
1955
|
+
t = min(i, n); i0 = min(int(t), len(ys) - 2); f = t - i0; yv = ys[i0] + (ys[i0 + 1] - ys[i0]) * f
|
|
1956
|
+
pts.append((gx0 + (gx1 - gx0) * t / (len(ys) - 1), gy1 - (gy1 - gy0) * yv))
|
|
1957
|
+
if len(pts) > 1:
|
|
1958
|
+
cd.polygon(pts + [(pts[-1][0], gy1), (pts[0][0], gy1)], fill=GREEN + (70,))
|
|
1959
|
+
gl = Image.new('RGBA', lay.size, (0, 0, 0, 0)); ImageDraw.Draw(gl).line(pts, fill=GREEN + (255,), width=int(60 * v), joint='curve')
|
|
1960
|
+
chart.alpha_composite(gl.filter(ImageFilter.GaussianBlur(26 * v)))
|
|
1961
|
+
cd = ImageDraw.Draw(chart); cd.line(pts, fill=GREEN + (255,), width=max(2, int(20 * v)), joint='curve')
|
|
1962
|
+
ex, ey = pts[-1]
|
|
1963
|
+
cd.ellipse([ex - 30 * v, ey - 30 * v, ex + 30 * v, ey + 30 * v], fill=GREEN + (90,)); cd.ellipse([ex - 15 * v, ey - 15 * v, ex + 15 * v, ey + 15 * v], fill=(235, 255, 240, 255))
|
|
1964
|
+
else:
|
|
1965
|
+
vals = [1.0, 0.71, 0.63, 0.42, 0.25, 0.20, 0.19]; bw = (gx1 - gx0) / len(vals)
|
|
1966
|
+
for i, val in enumerate(vals):
|
|
1967
|
+
g = ease_out(clamp(prog * 1.6 - i * 0.1)); top = gy1 - (gy1 - gy0) * val * g; bx = gx0 + i * bw + bw * 0.16
|
|
1968
|
+
if i == 0:
|
|
1969
|
+
gl = Image.new('RGBA', lay.size, (0, 0, 0, 0)); ImageDraw.Draw(gl).rounded_rectangle([bx, top, bx + bw * 0.68, gy1], int(18 * v), fill=GREEN + (230,))
|
|
1970
|
+
chart.alpha_composite(gl.filter(ImageFilter.GaussianBlur(22 * v))); cd = ImageDraw.Draw(chart)
|
|
1971
|
+
cd.rounded_rectangle([bx, top, bx + bw * 0.68, gy1], int(18 * v), fill=GREEN + (230 if i == 0 else 120,))
|
|
1972
|
+
base.alpha_composite(chart); base.alpha_composite(lay)
|
|
1973
|
+
comp(c, base, x0 - o, y0 - o)
|
|
1974
|
+
|
|
1975
|
+
|
|
1976
|
+
@effect('over-the-shoulder-zoom', 'the camera pushes into one top corner, a liquid glass graph pops beside your head, then the other corner with a second graph')
|
|
1977
|
+
def fx_over_the_shoulder_zoom(c, e):
|
|
1978
|
+
p = clamp(c.lt / e.d); z0 = float(e.o.get('zoom', 2.0))
|
|
1979
|
+
lx, rx = c.fx - c.W * 0.17, c.fx + c.W * 0.19
|
|
1980
|
+
keys = [(0, 1.0, c.fx, c.fy), (0.30, 1.04, c.fx, c.fy), (0.46, z0, lx, c.fy), (0.66, z0 + 0.04, lx, c.fy), (0.76, 1.05, c.fx, c.fy), (0.87, z0, rx, c.fy), (1.0, z0 + 0.04, rx, c.fy)]
|
|
1981
|
+
for (pa, za, xa, ya), (pb, zb, xb, yb) in zip(keys, keys[1:]):
|
|
1982
|
+
if pa <= p <= pb: q = ease_inout((p - pa) / (pb - pa)); z, x, y = za + (zb - za) * q, xa + (xb - xa) * q, ya + (yb - ya) * q; break
|
|
1983
|
+
camera(c, z, x, y)
|
|
1984
|
+
k1 = clamp((p - 0.42) / 0.065) * (1 - clamp((p - 0.66) / 0.055)); k2 = clamp((p - 0.84) / 0.065)
|
|
1985
|
+
if k1 <= 0 and k2 <= 0: return
|
|
1986
|
+
me, m = c.img.copy(), c.m[..., None]
|
|
1987
|
+
a, b = (e.o.get('text') or 'Views · this reel|Top reels · total').split('|')[:2]
|
|
1988
|
+
va, vb = (str(e.o.get('to') or '197K|672K')).split('|')[:2]
|
|
1989
|
+
glass_graph(c, c.W * 0.43, c.H * 0.255, k1, clamp((p - 0.45) / 0.17), a, va, 'line')
|
|
1990
|
+
glass_graph(c, c.W * 0.57, c.H * 0.255, k2, clamp((p - 0.86) / 0.14), b, vb, 'bars')
|
|
1991
|
+
c.img = c.img * (1 - m) + me * m # your head stays in front of the cards
|
|
1992
|
+
|
|
1993
|
+
|
|
1994
|
+
def msg_bubble(c, y, title, body, a):
|
|
1995
|
+
"""One creamy glass iMessage notification with a soft white halo, centred at height y."""
|
|
1996
|
+
u = c.W / 2160; w, h = int(1880 * u), int(330 * u); x0 = (c.W - w) // 2; y0 = int(y - h / 2)
|
|
1997
|
+
if a <= 0 or y0 + h < 0 or y0 > c.H: return
|
|
1998
|
+
s = 0.82 + 0.18 * ease_back(a); ww, hh = int(w * s), int(h * s); xs, ys = (c.W - ww) // 2, int(y - hh / 2)
|
|
1999
|
+
halo = Image.new('RGBA', (ww + int(240 * u), hh + int(240 * u)), (0, 0, 0, 0)); p = int(120 * u)
|
|
2000
|
+
ImageDraw.Draw(halo).rounded_rectangle([p - 30 * u, p - 30 * u, p + ww + 30 * u, p + hh + 30 * u], int(100 * u), fill=(255, 250, 240, int(215 * clamp(a * 2))))
|
|
2001
|
+
comp(c, halo.filter(ImageFilter.GaussianBlur(56 * u)), xs - p, ys - p)
|
|
2002
|
+
gx0, gy0, gx1, gy1 = max(0, xs), max(0, ys), min(c.W, xs + ww), min(c.H, ys + hh)
|
|
2003
|
+
if gx1 <= gx0 or gy1 <= gy0: return
|
|
2004
|
+
reg = cv2.GaussianBlur(c.img[gy0:gy1, gx0:gx1], (0, 0), 20 * u)
|
|
2005
|
+
yy = np.linspace(0, 1, gy1 - gy0, dtype=np.float32)[:, None, None]
|
|
2006
|
+
reg = reg * (1 - 0.78) + np.float32([252, 246, 238]) / 255 * 0.78 + (1 - yy) * 0.08
|
|
2007
|
+
mk = Image.new('L', (ww, hh), 0); ImageDraw.Draw(mk).rounded_rectangle([0, 0, ww - 1, hh - 1], int(70 * u * s), fill=255)
|
|
2008
|
+
mk = np.asarray(mk, np.float32)[gy0 - ys:gy1 - ys, gx0 - xs:gx1 - xs, None] / 255 * clamp(a * 2.5)
|
|
2009
|
+
dst = c.img[gy0:gy1, gx0:gx1]; dst[:] = dst * (1 - mk) + np.clip(reg, 0, 1) * mk
|
|
2010
|
+
lay = Image.new('RGBA', (ww, hh), (0, 0, 0, 0)); d = ImageDraw.Draw(lay); v = s * u; al = int(255 * clamp(a * 2.5))
|
|
2011
|
+
d.rounded_rectangle([1, 1, ww - 2, hh - 2], int(70 * v), outline=(255, 255, 255, int(170 * clamp(a * 2.5))), width=max(1, int(3 * v)))
|
|
2012
|
+
ic = np.linspace(0, 1, int(160 * v), dtype=np.float32)[:, None]
|
|
2013
|
+
icon = np.dstack([110 - ic * 64, 232 - ic * 51, 120 - ic * 51, np.full_like(ic, 255)]).repeat(int(160 * v), 1).astype(np.uint8)
|
|
2014
|
+
icon = Image.fromarray(icon, 'RGBA'); im_ = Image.new('L', icon.size, 0); ImageDraw.Draw(im_).rounded_rectangle([0, 0, icon.width - 1, icon.height - 1], int(40 * v), fill=al); icon.putalpha(im_)
|
|
2015
|
+
ImageDraw.Draw(icon).ellipse([30 * v, 34 * v, 130 * v, 114 * v], fill=(255, 255, 255, al)); ImageDraw.Draw(icon).polygon([(44 * v, 102 * v), (36 * v, 130 * v), (72 * v, 110 * v)], fill=(255, 255, 255, al))
|
|
2016
|
+
lay.alpha_composite(icon, (int(56 * v), int(70 * v)))
|
|
2017
|
+
d.text((262 * v, 76 * v), title, font=font('uib', 72 * v), fill=(28, 28, 30, al)); d.text((262 * v, 170 * v), body, font=font('uim', 76 * v), fill=(44, 44, 46, al))
|
|
2018
|
+
comp(c, lay, xs, ys)
|
|
2019
|
+
|
|
2020
|
+
|
|
2021
|
+
@effect('messages', 'iMessage notifications pop in one after another, creamy glass with a soft glow, stacking up above the bottom of the frame')
|
|
2022
|
+
def fx_messages(c, e):
|
|
2023
|
+
msgs = (e.o.get('text') or 'how did you edit this??|wait, which app is this|send me the effects pls|EFFECTS').split('|')
|
|
2024
|
+
title = e.o.get('title', 'Messages'); n = len(msgs); u = c.W / 2160
|
|
2025
|
+
gap = min(0.4, e.d * 0.75 / max(1, n)); pops = [0.13 + i * gap for i in range(n)]
|
|
2026
|
+
bottom = c.H * float(e.o.get('y', 0.61)); out = fade(c, e, 0.2)
|
|
2027
|
+
for k in range(n):
|
|
2028
|
+
if c.lt < pops[k]: continue
|
|
2029
|
+
newer = sum(ease_out(clamp((c.lt - pops[j]) / 0.17)) for j in range(k + 1, n) if c.lt >= pops[j])
|
|
2030
|
+
msg_bubble(c, bottom - 165 * u - newer * 365 * u, title, msgs[k], clamp((c.lt - pops[k]) / 0.17) * out)
|
|
2031
|
+
|
|
2032
|
+
|
|
2033
|
+
def views_icon(px):
|
|
2034
|
+
"""The Instagram 'views' eye: an arc above a teardrop (traced from the IG app)."""
|
|
2035
|
+
paths = [[(325, 490), [(-43, -9, -73, -30, -97, -68), (-28, -46, -14, -53, 22, -10), (37, 45, 79, 62, 133, 55), (33, -4, 50, -14, 80, -48), (40, -44, 60, -46, 37, -3), (-29, 52, -112, 87, -175, 74)]],
|
|
2036
|
+
[(315, 405), [(-51, -50, -21, -115, 52, -115), (51, 0, 88, 65, 41, 72), (-14, 2, -29, 15, -38, 35), (-8, 18, -19, 33, -23, 33), (-4, 0, -19, -11, -32, -25)]]]
|
|
2037
|
+
k = px / 24 * 4; im = Image.new('L', (int(34 * k), int(24 * k)), 0); d = ImageDraw.Draw(im)
|
|
2038
|
+
tx = lambda x, y: ((0.1 * x - 19) * k, (80 - 0.1 * y - 29) * k)
|
|
2039
|
+
for (sx, sy), segs in paths:
|
|
2040
|
+
pts = [tx(sx, sy)]; cx, cy = sx, sy
|
|
2041
|
+
for s in segs:
|
|
2042
|
+
p0, p1, p2, p3 = (cx, cy), (cx + s[0], cy + s[1]), (cx + s[2], cy + s[3]), (cx + s[4], cy + s[5])
|
|
2043
|
+
for j in range(1, 13):
|
|
2044
|
+
t = j / 12; pts.append(tx(*[(1 - t) ** 3 * a + 3 * (1 - t) ** 2 * t * b + 3 * (1 - t) * t * t * cc + t ** 3 * dd for a, b, cc, dd in zip(p0, p1, p2, p3)]))
|
|
2045
|
+
cx, cy = p3
|
|
2046
|
+
d.polygon(pts, fill=255)
|
|
2047
|
+
im = im.resize((int(34 * px / 24), px), Image.LANCZOS); out = Image.new('RGBA', im.size, (255, 255, 255, 0)); out.putalpha(im); return out
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
def grid_tile(im, w, h, views, r):
|
|
2051
|
+
t = im.convert('RGB'); s = max(w / t.width, h / t.height); t = t.resize((int(t.width * s) + 1, int(t.height * s) + 1), Image.LANCZOS)
|
|
2052
|
+
t = t.crop(((t.width - w) // 2, (t.height - h) // 2, (t.width - w) // 2 + w, (t.height - h) // 2 + h)).convert('RGBA')
|
|
2053
|
+
mk = Image.new('L', (w, h), 0); ImageDraw.Draw(mk).rounded_rectangle([0, 0, w - 1, h - 1], r, fill=255)
|
|
2054
|
+
if views:
|
|
2055
|
+
u = w / 660; fd = Image.linear_gradient('L').resize((w, int(h * 0.28))).point(lambda v: int(v * 0.75))
|
|
2056
|
+
sh = Image.new('RGBA', fd.size, (0, 0, 0, 0)); sh.putalpha(fd); t.alpha_composite(sh, (0, h - fd.height))
|
|
2057
|
+
ic = views_icon(int(56 * u)); x, y = int(34 * u), int(h - 92 * u); t.alpha_composite(ic, (x, y + int(2 * u)))
|
|
2058
|
+
ImageDraw.Draw(t).text((x + ic.width + 14 * u, y - 6 * u), views, font=font('uib', 58 * u), fill=(255, 255, 255, 255))
|
|
2059
|
+
t.putalpha(mk); ImageDraw.Draw(t).rounded_rectangle([1, 1, w - 2, h - 2], r, outline=(255, 255, 255, 150), width=max(1, int(4 * w / 660)))
|
|
2060
|
+
return t
|
|
2061
|
+
|
|
2062
|
+
|
|
2063
|
+
@effect('place-in-grid', 'you shrink into the centre tile of your 3x3 profile grid on frosted glass, then 8 of your reels pop in around you, one per frame, view counts on every tile')
|
|
2064
|
+
def fx_place_in_grid(c, e):
|
|
2065
|
+
W, H = c.W, c.H; g, m = int(33 * W / 2160), int(68 * W / 2160)
|
|
2066
|
+
tw = (W - 2 * m - 2 * g) // 3; th = int(tw * 16 / 9); top = (H - (3 * th + 2 * g)) // 2; r = int(28 * W / 2160)
|
|
2067
|
+
rect = lambda i: (m + (i % 3) * (tw + g), top + (i // 3) * (th + g))
|
|
2068
|
+
views = (e.o.get('views') or '2.4M|847K|1.2M|312K|3.4M|596K|268K|1.8M|3.1M').split('|')
|
|
2069
|
+
tiles = cached(e, 'tiles', lambda: [grid_tile(vary(im, i) if e.o.get('images') is None else im, tw, th, views[i % len(views)], r) for i, im in enumerate((e.cards * 8)[:8])])
|
|
2070
|
+
me = c.img.copy(); p = ease_inout(clamp(c.lt / 0.45))
|
|
2071
|
+
fz = cv2.resize(cv2.GaussianBlur(cv2.resize(me, (W // 8, H // 8)), (0, 0), 14), (W, H), interpolation=cv2.INTER_CUBIC)
|
|
2072
|
+
lum = (fz @ np.float32([0.299, 0.587, 0.114]))[..., None]; fz = np.clip(lum + (fz - lum) * 1.25, 0, 1)
|
|
2073
|
+
c.img = fz * (1 - 0.37) + np.float32([255, 248, 238]) / 255 * 0.37
|
|
2074
|
+
for j, slot in enumerate((1, 5, 7, 3, 2, 8, 6, 0)):
|
|
2075
|
+
a = clamp((c.lt - 0.47 - j / 30) / 0.1)
|
|
2076
|
+
if a > 0: x, y = rect(slot); place(c, tiles[j], x + tw / 2, y + th / 2, 0.82 + 0.18 * ease_back(a), 0, clamp(a * 2))
|
|
2077
|
+
cx, cy = rect(4); w2, h2 = int(W + (tw - W) * p), int(H + (th - H) * p)
|
|
2078
|
+
mine = Image.fromarray((np.clip(me, 0, 1) * 255).astype(np.uint8))
|
|
2079
|
+
tile = grid_tile(mine, w2, h2, views[8 % len(views)] if p > 0.9 else None, int(r * p))
|
|
2080
|
+
comp(c, tile, cx * p, cy * p)
|
|
2081
|
+
if p > 0.95: d = Image.new('RGBA', (tw + 8, th + 8), (0, 0, 0, 0)); ImageDraw.Draw(d).rounded_rectangle([2, 2, tw + 5, th + 5], r + 2, outline=(217, 119, 87, 255), width=8); comp(c, d, cx - 4, cy - 4)
|
|
2082
|
+
|
|
2083
|
+
|
|
2084
|
+
|
|
2085
|
+
|
|
2086
|
+
|
|
2087
|
+
# ---------- pack 5: phrase pops starters (added 2 Nov 2026) ----------
|
|
2088
|
+
INKY, TAPE, CRAYON, CREAMY = (23, 23, 27), (255, 225, 77), (200, 40, 56), (253, 246, 200)
|
|
2089
|
+
def above_head(c, h): return max(c.H * 0.12 + h / 2, c.fy - c.fw * 1.75)
|
|
2090
|
+
|
|
2091
|
+
|
|
2092
|
+
@effect('tape-label', 'a strip of yellow tape with your line lands on your chest')
|
|
2093
|
+
def fx_tape_label(c, e):
|
|
2094
|
+
k = pop(c, 0.05, 0.25) * fade(c, e)
|
|
2095
|
+
if k <= 0: return
|
|
2096
|
+
def tape():
|
|
2097
|
+
S = int(c.W * 0.055); t = text_img(e.o.get('text', 'your own reels'), S, 'hand', INKY)
|
|
2098
|
+
w, h = int(t.width + S * 0.6), int(t.height + S * 0.2); o = max(4, S // 9)
|
|
2099
|
+
im = Image.new('RGBA', (w + o, h + o), (0, 0, 0, 0)); d = ImageDraw.Draw(im)
|
|
2100
|
+
d.rectangle([o, o, w + o - 1, h + o - 1], fill=(17, 17, 17, 255)); d.rectangle([0, 0, w - 1, h - 1], fill=TAPE + (255,))
|
|
2101
|
+
im.alpha_composite(t, ((w - t.width) // 2, (h - t.height) // 2)); return im
|
|
2102
|
+
im = cached(e, 'tape', tape)
|
|
2103
|
+
place(c, im, c.W / 2, clamp(c.fy + c.fw * 1.6, c.H * 0.45, c.H * 0.68), 0.85 + 0.15 * k, 0, clamp(k * 1.5), guard=True)
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
@effect('select-resize', 'a blue selection box grabs your number and a cursor drags it bigger')
|
|
2107
|
+
def fx_select_resize(c, e):
|
|
2108
|
+
al = fade(c, e) * clamp(c.lt / 0.08)
|
|
2109
|
+
if al <= 0: return
|
|
2110
|
+
p = ease_inout((c.lt - 0.25) / 0.7); S = int(c.W * 0.2 * (0.55 + 0.45 * p)) // 4 * 4
|
|
2111
|
+
t = cached(e, ('t', S), lambda: text_img(e.o.get('text', '2X'), S, 'didone', CREAMY, shadow=8))
|
|
2112
|
+
bw, bh = t.width + c.W * 0.03, t.height; cx, cy = c.W / 2, above_head(c, bh)
|
|
2113
|
+
x0, y0 = cx - bw / 2, cy - bh / 2
|
|
2114
|
+
lay = Image.new('RGBA', (c.W, c.H), (0, 0, 0, 0)); d = ImageDraw.Draw(lay); B = BLUE + (255,); lw = max(2, c.W // 360)
|
|
2115
|
+
d.rectangle([x0, y0, x0 + bw, y0 + bh], fill=BLUE + (int(130 * (1 - 0.7 * clamp((c.lt - 0.9) / 0.3))),))
|
|
2116
|
+
for (ax, ay, bx, by) in ((x0, y0, x0 + bw, y0), (x0, y0 + bh, x0 + bw, y0 + bh), (x0, y0, x0, y0 + bh), (x0 + bw, y0, x0 + bw, y0 + bh)):
|
|
2117
|
+
n = max(1, int(math.hypot(bx - ax, by - ay) / (c.W * 0.018)))
|
|
2118
|
+
for j in range(0, n, 2): d.line([(ax + (bx - ax) * j / n, ay + (by - ay) * j / n), (ax + (bx - ax) * (j + 1) / n, ay + (by - ay) * (j + 1) / n)], fill=B, width=lw)
|
|
2119
|
+
hs = c.W * 0.009
|
|
2120
|
+
for qx, qy in ((x0, y0), (x0 + bw, y0), (x0, y0 + bh), (x0 + bw, y0 + bh)): d.rectangle([qx - hs, qy - hs, qx + hs, qy + hs], fill=(255, 255, 255, 255), outline=B, width=lw)
|
|
2121
|
+
comp(c, to_np(lay), 0, 0, al, behind=True); place(c, t, cx, cy, 1, 0, al, behind=True)
|
|
2122
|
+
cu = cached(e, 'cu', lambda: cursor(c.W * 0.045)); place(c, cu, x0 + bw + cu.width * 0.4, y0 + bh + cu.height * 0.4, 1, 0, al)
|
|
2123
|
+
|
|
2124
|
+
|
|
2125
|
+
@effect('wave-trim', 'the silent parts of your voice are trimmed away on screen until only your words are left')
|
|
2126
|
+
def fx_wave_trim(c, e):
|
|
2127
|
+
al = pop(c, 0, 0.2) * fade(c, e)
|
|
2128
|
+
if al <= 0: return
|
|
2129
|
+
p = ease_inout((c.lt - 0.25) / 0.5); pw, ph, ww = c.W * (0.84 - 0.4 * p), c.W * 0.2, c.W * 0.3
|
|
2130
|
+
hts = cached(e, 'h', lambda: np.random.default_rng(3).uniform(0.15, 1, 60))
|
|
2131
|
+
lay = Image.new('RGBA', (int(pw) + 2, int(ph) + 2), (0, 0, 0, 0)); d = ImageDraw.Draw(lay)
|
|
2132
|
+
d.rectangle([0, 0, pw, ph], fill=INKY + (240,)); cx, cy = pw / 2, ph / 2; st = ww / len(hts)
|
|
2133
|
+
for j, h in enumerate(hts):
|
|
2134
|
+
x = cx - ww / 2 + j * st; v = h * ph * 0.36 * (0.55 + 0.45 * math.sin(j * 0.33))
|
|
2135
|
+
d.rectangle([x, cy - v, x + st * 0.45, cy + v], fill=CREAMY + (255,))
|
|
2136
|
+
r, gap = c.W * 0.0045, c.W * 0.016
|
|
2137
|
+
for sd in (-1, 1):
|
|
2138
|
+
x = cx + sd * (ww / 2 + gap)
|
|
2139
|
+
while 0 < x < pw: d.ellipse([x - r, cy - r, x + r, cy + r], fill=RED + (255,)); x += sd * gap
|
|
2140
|
+
place(c, lay, c.W / 2, above_head(c, ph), 1, 0, al, behind=True)
|
|
2141
|
+
|
|
2142
|
+
|
|
2143
|
+
@effect('huge-strike', 'one huge serif word fills the wall behind you, then a red line crosses it out')
|
|
2144
|
+
def fx_huge_strike(c, e):
|
|
2145
|
+
al = fade(c, e)
|
|
2146
|
+
t = cached(e, 't', lambda: fit_text(e.o.get('text', '8 HOURS'), c.W * 0.9, 'didone', int(c.W * 0.28), fill=CREAMY, shadow=10))
|
|
2147
|
+
cw = int(t.width * ease_out(c.lt / 0.35)); cy = above_head(c, t.height)
|
|
2148
|
+
if cw > 2: place(c, t.crop((0, 0, cw, t.height)), c.W / 2 - (t.width - cw) / 2, cy, 1, 0, al, behind=True)
|
|
2149
|
+
at = float(e.o.get('at', 0.6)); k = ease_out((c.lt - at) / 0.18)
|
|
2150
|
+
if k > 0:
|
|
2151
|
+
lay = Image.new('RGBA', (c.W, c.H), (0, 0, 0, 0)); x0, x1 = c.W / 2 - t.width * 0.46, c.W / 2 + t.width * 0.46
|
|
2152
|
+
pts = [(x0 + (x1 - x0) * u, cy + t.height * 0.04 - u * t.height * 0.05 + math.sin(u * 19) * c.W * 0.002) for u in np.linspace(0, 1, 40)]
|
|
2153
|
+
hand_path(ImageDraw.Draw(lay), pts, RED + (255,), max(6, c.W // 80), k); comp(c, to_np(lay), 0, 0, al, behind=True)
|
|
2154
|
+
|
|
2155
|
+
|
|
2156
|
+
@effect('crayon-write', 'a red crayon writes your word behind your head, then underlines it')
|
|
2157
|
+
def fx_crayon_write(c, e):
|
|
2158
|
+
al = fade(c, e)
|
|
2159
|
+
t = cached(e, 't', lambda: fit_text(e.o.get('text', 'NOBODY'), c.W * 0.82, 'hand', int(c.W * 0.17), fill=CRAYON, shadow=4))
|
|
2160
|
+
p = ease_inout((c.lt - 0.05) / 0.8); cw = int(t.width * p); cy = above_head(c, t.height); x0 = c.W / 2 - t.width / 2
|
|
2161
|
+
if cw > 2: place(c, t.crop((0, 0, cw, t.height)), x0 + cw / 2, cy, 1, 0, al, behind=True)
|
|
2162
|
+
if c.lt > 0.9:
|
|
2163
|
+
lay = Image.new('RGBA', (c.W, c.H), (0, 0, 0, 0)); yy = cy + t.height * 0.42
|
|
2164
|
+
pts = [(x0 + t.width * (0.06 + 0.88 * u), yy - u * c.W * 0.006 + math.sin(u * 23) * c.W * 0.002) for u in np.linspace(0, 1, 40)]
|
|
2165
|
+
hand_path(ImageDraw.Draw(lay), pts, CRAYON + (255,), max(5, c.W // 95), ease_out((c.lt - 0.9) / 0.25)); comp(c, to_np(lay), 0, 0, al, behind=True)
|
|
2166
|
+
def mk():
|
|
2167
|
+
L = int(c.W * 0.22); T = int(L * 0.2); im = Image.new('RGBA', (L + T, T), (0, 0, 0, 0)); d = ImageDraw.Draw(im)
|
|
2168
|
+
d.polygon([(0, T / 2), (T, 0), (T, T)], fill=(224, 58, 68, 255)); d.rounded_rectangle([T * 0.9, 0, L + T - 1, T - 1], T // 5, fill=(224, 58, 68, 255))
|
|
2169
|
+
for xx in (T * 1.5, L + T * 0.4): d.rectangle([xx, 0, xx + T * 0.35, T - 1], fill=(168, 23, 40, 255))
|
|
2170
|
+
return shadowed(im.rotate(-38, Image.BICUBIC, expand=True), 6, 4, 100)
|
|
2171
|
+
cr = cached(e, 'cr', mk); away = ease_inout((c.lt - 1.1) / 0.3)
|
|
2172
|
+
if away < 1:
|
|
2173
|
+
tx, ty = x0 + cw + away * c.W * 0.6, cy + math.sin(c.lt * 30) * t.height * 0.12 + away * c.H * 0.2
|
|
2174
|
+
place(c, cr, tx + cr.width * 0.47, ty + cr.height * 0.45, 1, 0, al)
|
|
2175
|
+
|
|
2176
|
+
|
|
2177
|
+
@effect('fan-build', 'your reel covers deal into a fan behind your head, one card at a time')
|
|
2178
|
+
def fx_fan_build(c, e):
|
|
2179
|
+
n = int(e.o.get('count', 13)); al = fade(c, e); cw = int(c.W * 0.15)
|
|
2180
|
+
cards = cached(e, 'cards', lambda: [card(vary(e.cards[i % len(e.cards)], i) if e.o.get('images') is None else e.cards[i % len(e.cards)], cw, 0.05) for i in range(n)])
|
|
2181
|
+
px, py, R = c.fx, c.fy + c.fw * 0.1, c.fw * 2.15
|
|
2182
|
+
for i in range(n):
|
|
2183
|
+
t0 = 0.055 * i
|
|
2184
|
+
if c.lt < t0: break
|
|
2185
|
+
q = ease_out((c.lt - t0) / 0.3); a = -95 + (-62 + 124 * i / max(1, n - 1) + 95) * q; r = math.radians(a)
|
|
2186
|
+
place(c, cards[i], px + R * math.sin(r), py - R * math.cos(r), 1, -a, al, behind=True)
|
|
2187
|
+
|
|
2188
|
+
|
|
2189
|
+
# ---------- Adam Digital additions: signature effects ----------
|
|
2190
|
+
import logos
|
|
2191
|
+
|
|
2192
|
+
|
|
2193
|
+
def head_top(e): return e.top if e.top is not None else e.med[1] - e.med[2] * 0.85
|
|
2194
|
+
|
|
2195
|
+
|
|
2196
|
+
@effect('pop-word', 'a huge bold word pops in behind your head, in a brand colour, yellow or white')
|
|
2197
|
+
def fx_pop_word(c, e):
|
|
2198
|
+
word = str(e.o.get('text', 'AI')); u = c.W / 1080
|
|
2199
|
+
col = rgb(e.o.get('color'), None) or logos.brand_color(e.o.get('brand')) or (255, 211, 26)
|
|
2200
|
+
def mk():
|
|
2201
|
+
S = int((440 if e.o.get('size') == 'big' else 245) * u); sp = -6 * u
|
|
2202
|
+
while S > 40 and font('pop', S).getlength(word) + sp * (len(word) - 1) > 1010 * u: S = int(S * 0.94)
|
|
2203
|
+
room = max(c.H * 0.05, head_top(e) - c.H * 0.03) # space above your head
|
|
2204
|
+
for _ in range(2):
|
|
2205
|
+
im = tracked(word, S, 'pop', col, sp); bb = im.getbbox(); gh = (bb[3] - bb[1]) if bb else im.height
|
|
2206
|
+
if gh * 0.65 <= room: break
|
|
2207
|
+
S = max(40, int(S * room / (gh * 0.65)))
|
|
2208
|
+
return shadowed(im.crop(bb) if bb else im, blur=int(26 * u), dy=int(10 * u), alpha=95), gh
|
|
2209
|
+
im, gh = cached(e, 'w', mk)
|
|
2210
|
+
al = clamp(c.lt / 0.06) * fade(c, e, 0.18)
|
|
2211
|
+
if al <= 0: return
|
|
2212
|
+
cy = max(head_top(e) - gh * 0.15, c.H * 0.03 + gh / 2) # your head covers the bottom third of the word
|
|
2213
|
+
place(c, im, c.W / 2 * 0.6 + c.fx * 0.4, cy, 1.35 - 0.35 * ease_back(c.lt / 0.22), 0, al, behind=True)
|
|
2214
|
+
|
|
2215
|
+
|
|
2216
|
+
_warned = set()
|
|
2217
|
+
def warn_once(msg):
|
|
2218
|
+
if msg not in _warned: _warned.add(msg); print('Note:', msg, flush=True)
|
|
2219
|
+
|
|
2220
|
+
|
|
2221
|
+
@effect('logo-link', 'two real brand logos pop in beside your face, joined by a dashed line that runs behind your head')
|
|
2222
|
+
def fx_logo_link(c, e):
|
|
2223
|
+
u = c.W / 1080; T = int(144 * u)
|
|
2224
|
+
names = [n.strip() for n in str(e.o.get('text', 'claude|notion')).split('|') if n.strip()][:2] or ['claude']
|
|
2225
|
+
labels = [s.strip() for s in str(e.o['label']).split('|')] if e.o.get('label') else [logos.title(n) for n in names]
|
|
2226
|
+
custom = [s.strip() for s in str(e.o.get('logo', '')).split('|')]
|
|
2227
|
+
def tile(i):
|
|
2228
|
+
im = rrect(T, T, T * 0.25, (255, 255, 255, 255))
|
|
2229
|
+
src = custom[i] if i < len(custom) and custom[i] else names[i]
|
|
2230
|
+
lg = logos.logo_image(src, int(88 * u))
|
|
2231
|
+
if lg is None:
|
|
2232
|
+
warn_once(f"no bundled logo for '{names[i]}'. Pass logo=path/to/logo.png to show the real one.")
|
|
2233
|
+
lg = fit_text(names[i], T * 0.8, 'popx', int(T * 0.26), fill=INK)
|
|
2234
|
+
im.alpha_composite(lg, ((T - lg.width) // 2, (T - lg.height) // 2))
|
|
2235
|
+
im = shadowed(im, int(16 * u), int(6 * u), 90)
|
|
2236
|
+
lab = text_img(labels[i] if i < len(labels) else names[i], 30 * u, 'popb', (255, 255, 255), shadow=int(7 * u))
|
|
2237
|
+
out = Image.new('RGBA', (max(im.width, lab.width), im.height + int(lab.height * 0.62)), (0, 0, 0, 0))
|
|
2238
|
+
out.alpha_composite(im, ((out.width - im.width) // 2, 0)); out.alpha_composite(lab, ((out.width - lab.width) // 2, im.height - int(lab.height * 0.38)))
|
|
2239
|
+
return out, (out.width - im.width) // 2 + im.width / 2, im.height / 2
|
|
2240
|
+
tiles = cached(e, 'tiles', lambda: [tile(i) for i in range(len(names))])
|
|
2241
|
+
fx_, fy_, fw_ = e.med; y = fy_ + c.H * 0.035; lo, hi = T / 2 + c.W * 0.03, c.W - T / 2 - c.W * 0.03
|
|
2242
|
+
xs = [clamp(fx_ - c.W * 0.344, lo, hi), clamp(fx_ + c.W * 0.344, lo, hi)] if len(names) == 2 else [clamp(fx_ + c.W * 0.344, lo, hi)]
|
|
2243
|
+
out = fade(c, e); tb = min(0.35, e.d * 0.3); starts = [0.0, tb]
|
|
2244
|
+
if len(names) == 2 and c.lt > tb + 0.1: # the dashed link, drawn left to right behind your head
|
|
2245
|
+
q = ease_out((c.lt - tb - 0.1) / 0.4); x0, x1 = xs[0] + T * 0.55, xs[1] - T * 0.55; xe = x0 + (x1 - x0) * q
|
|
2246
|
+
lay = Image.new('RGBA', (c.W, int(30 * u)), (0, 0, 0, 0)); d = ImageDraw.Draw(lay); my = lay.height / 2
|
|
2247
|
+
dash, gap = 22 * u, 16 * u; x = x0 - ((c.lt * 60 * u) % (dash + gap))
|
|
2248
|
+
while x < xe:
|
|
2249
|
+
a, b = max(x, x0), min(x + dash, xe)
|
|
2250
|
+
if b > a: d.line([(a, my), (b, my)], fill=(255, 255, 255, 235), width=max(2, int(6 * u)))
|
|
2251
|
+
x += dash + gap
|
|
2252
|
+
cols = [logos.brand_color(n) or (255, 211, 26) for n in names]
|
|
2253
|
+
for j in range(3):
|
|
2254
|
+
p = (c.lt * 0.55 + j / 3) % 1; dx = x0 + (x1 - x0) * p
|
|
2255
|
+
if dx <= xe: d.ellipse([dx - 7 * u, my - 7 * u, dx + 7 * u, my + 7 * u], fill=cols[j % 2] + (255,))
|
|
2256
|
+
comp(c, to_np(lay), 0, y - lay.height / 2, out, behind=True)
|
|
2257
|
+
for i, (im, ax, ay) in enumerate(tiles):
|
|
2258
|
+
k = ease_back((c.lt - starts[i]) / 0.3) if c.lt > starts[i] else 0
|
|
2259
|
+
if k <= 0: continue
|
|
2260
|
+
place(c, im, xs[i] - ax + im.width / 2, y - ay + im.height / 2, 0.4 + 0.6 * k, 0, clamp((c.lt - starts[i]) / 0.1) * out, guard=True)
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
@effect('card-drop', 'you slide down and a floating card with your screenshot pops in above you')
|
|
2264
|
+
def fx_card_drop(c, e):
|
|
2265
|
+
u = c.W / 1080; cw, ch = int(960 * u), int(700 * c.H / 1920); top = int(150 * c.H / 1920)
|
|
2266
|
+
want = clamp(top + ch + 40 * u - head_top(e), c.H * 0.2, c.H * 0.42) # slide far enough that the card never covers your face
|
|
2267
|
+
k = min(ease_inout(c.lt / 0.3), ease_inout((e.d - c.lt) / 0.3)); dy = want * k
|
|
2268
|
+
if dy > 1:
|
|
2269
|
+
small = cv2.resize(c.img, (c.W // 8, c.H // 8), interpolation=cv2.INTER_AREA)
|
|
2270
|
+
bg = cv2.resize(cv2.GaussianBlur(small, (0, 0), 5), (c.W, c.H), interpolation=cv2.INTER_LINEAR) * 0.55
|
|
2271
|
+
M = np.float32([[1, 0, 0], [0, 1, dy]])
|
|
2272
|
+
c.img = cv2.warpAffine(c.img, M, (c.W, c.H), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
|
|
2273
|
+
c.m = cv2.warpAffine(c.m, M, (c.W, c.H), flags=cv2.INTER_LINEAR); n = int(math.ceil(dy))
|
|
2274
|
+
c.img[:n] = bg[:n]; c.fy += dy
|
|
2275
|
+
al = clamp(c.lt / 0.1) * clamp((e.d - c.lt - 0.08) / 0.2)
|
|
2276
|
+
if al <= 0: return
|
|
2277
|
+
def mk():
|
|
2278
|
+
im = Image.new('RGBA', (cw, ch), (255, 255, 255, 255)); path = e.o.get('image')
|
|
2279
|
+
if path and os.path.exists(str(path)):
|
|
2280
|
+
src = Image.open(str(path)).convert('RGB')
|
|
2281
|
+
s = max(cw / src.width, ch / src.height) if e.o.get('fit') == 'cover' else min(cw / src.width, ch / src.height)
|
|
2282
|
+
src = src.resize((max(1, int(src.width * s)), max(1, int(src.height * s))), Image.LANCZOS)
|
|
2283
|
+
im.paste(src, ((cw - src.width) // 2, (ch - src.height) // 2))
|
|
2284
|
+
else:
|
|
2285
|
+
if path: warn_once(f"card-drop image not found: {path}")
|
|
2286
|
+
t = fit_text(str(e.o.get('text', 'Your screenshot here')), cw * 0.84, 'popx', int(70 * u), fill=INK)
|
|
2287
|
+
im.alpha_composite(t, ((cw - t.width) // 2, (ch - t.height) // 2))
|
|
2288
|
+
m = Image.new('L', (cw, ch), 0); ImageDraw.Draw(m).rounded_rectangle([0, 0, cw - 1, ch - 1], int(30 * u), fill=255); im.putalpha(m)
|
|
2289
|
+
return shadowed(im, int(60 * u), int(22 * u), 115)
|
|
2290
|
+
p = ease_back(c.lt / 0.32); o = clamp((e.d - c.lt) / 0.2)
|
|
2291
|
+
place(c, cached(e, 'card', mk), c.W / 2, top + ch / 2 + (1 - clamp(p)) * 50 * u, (0.88 + 0.12 * p) * (0.94 + 0.06 * o), 0, al)
|
|
2292
|
+
c.cardbot = top + ch
|
|
2293
|
+
|
|
2294
|
+
|
|
2295
|
+
_dotf, _paper = {}, {}
|
|
2296
|
+
def dot_field(W, H, cell):
|
|
2297
|
+
k = (W, H, round(cell, 3))
|
|
2298
|
+
if k not in _dotf:
|
|
2299
|
+
yy, xx = np.mgrid[0:H, 0:W].astype(np.float32)
|
|
2300
|
+
_dotf[k] = np.sqrt(((xx % cell) - cell / 2) ** 2 + ((yy % cell) - cell / 2) ** 2)
|
|
2301
|
+
return _dotf[k]
|
|
2302
|
+
|
|
2303
|
+
|
|
2304
|
+
def paper_bg(W, H):
|
|
2305
|
+
if (W, H) not in _paper:
|
|
2306
|
+
u = W / 1080; d = dot_field(W, H, 6 * u)
|
|
2307
|
+
dots = (np.clip((1.05 * u - d) / max(0.6 * u, 0.5) + 0.5, 0, 1) * 0.12)[..., None]
|
|
2308
|
+
_paper[(W, H)] = np.float32([241, 240, 235]) / 255 * (1 - dots) + np.float32([60, 55, 45]) / 255 * dots
|
|
2309
|
+
return _paper[(W, H)]
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+
@effect('halftone-paper', 'a cream paper page: you cut out bottom-right with a halftone shadow, your words building at the top with red serif keywords')
|
|
2313
|
+
def fx_halftone_paper(c, e):
|
|
2314
|
+
W, H, u = c.W, c.H, c.W / 1080
|
|
2315
|
+
r_in, r_out = ease_out(c.lt / 0.35), ease_out((e.d - c.lt) / 0.25); k = min(r_in, r_out)
|
|
2316
|
+
if k <= 0.01: return
|
|
2317
|
+
cell = 44 * u; wipe = np.clip((cell * 0.75 * k - dot_field(W, H, cell)) / 1.5 + 0.5, 0, 1)
|
|
2318
|
+
fx_, fy_, fw_ = e.med; s = float(e.o.get('scale', 0.62)); xt = W * float(e.o.get('x', 0.68))
|
|
2319
|
+
M = np.float32([[s, 0, xt - s * fx_], [0, s, H - s * H]])
|
|
2320
|
+
pim = cv2.warpAffine(c.img, M, (W, H), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
|
|
2321
|
+
pm = np.clip((cv2.warpAffine(c.m, M, (W, H), flags=cv2.INTER_LINEAR) - 0.25) / 0.5, 0, 1)
|
|
2322
|
+
off = max(1, int(22 * u)); sh = np.zeros_like(pm); sh[off:, off:] = pm[:-off, :-off]
|
|
2323
|
+
gw = max(1, int(W / (12 * u))); hc = W / gw; gh = max(1, int(H / hc))
|
|
2324
|
+
rf = cv2.resize(cv2.resize(sh, (gw, gh), interpolation=cv2.INTER_AREA), (W, H), interpolation=cv2.INTER_NEAREST)
|
|
2325
|
+
dots = np.clip((hc * 0.62 * np.sqrt(rf) - dot_field(W, H, hc)) + 0.5, 0, 1) * (rf > 0.02)
|
|
2326
|
+
a = (dots * 0.88)[..., None]; scene = paper_bg(W, H) * (1 - a) + np.float32([20, 20, 20]) / 255 * a
|
|
2327
|
+
scene = scene * (1 - pm[..., None]) + pim * pm[..., None]
|
|
2328
|
+
c.img = c.img * (1 - wipe[..., None]) + scene * wipe[..., None]; c.m = c.m * (1 - wipe) + pm * wipe
|
|
2329
|
+
if k > 0.5: c.fx, c.fy, c.fw = s * c.fx + xt - s * fx_, s * c.fy + H - s * H, s * c.fw
|
|
2330
|
+
# the words, building at the top
|
|
2331
|
+
def blocks():
|
|
2332
|
+
if e.o.get('text'):
|
|
2333
|
+
ws = str(e.o['text']).split(); t0 = e.start + 0.25
|
|
2334
|
+
return cap_blocks([{'w': w, 's': t0 + i * 0.12, 'e': t0 + i * 0.12 + 0.1} for i, w in enumerate(ws)], 'paper', key_set(e), 3, one=True)
|
|
2335
|
+
return cap_blocks(e.words, 'paper', key_set(e), 3)
|
|
2336
|
+
bl = cached(e, 'blocks', blocks); cur = None
|
|
2337
|
+
for j, (b, bs, be) in enumerate(bl):
|
|
2338
|
+
if bs <= c.t: cur = j
|
|
2339
|
+
if cur is None: return
|
|
2340
|
+
lay = cached(e, ('lay', cur), lambda: paper_layout(bl[cur][0], W, u))
|
|
2341
|
+
for (g, ink_, x, y, ws, key) in lay:
|
|
2342
|
+
q = clamp((c.t - (ws - (0.11 if key else 0.05))) / 0.17)
|
|
2343
|
+
if q <= 0: continue
|
|
2344
|
+
q2 = ease_out(q); al = (0.35 + 0.65 * q2) * k; yy = y + (1 - q2) * 16 * u
|
|
2345
|
+
comp(c, g, x, yy, al * (1 - q2)); comp(c, ink_, x, yy, al * q2)
|
|
2346
|
+
|
|
2347
|
+
|
|
2348
|
+
def paper_layout(block, W, u):
|
|
2349
|
+
x0, y0, maxw, lh = 72 * u, 150 * u, W - 144 * u, 104 * u
|
|
2350
|
+
items, x, y = [], x0, y0
|
|
2351
|
+
fn, fk = font('uim', 82 * u), font('serif', 98 * u); sp = fn.getlength(' ')
|
|
2352
|
+
for w in block:
|
|
2353
|
+
f = fk if w['k'] else fn; wd = f.getlength(w['w'])
|
|
2354
|
+
if x > x0 and x + wd > x0 + maxw: x, y = x0, y + lh
|
|
2355
|
+
cols = ((242, 182, 178), (217, 58, 62)) if w['k'] else ((196, 193, 186), (20, 20, 20))
|
|
2356
|
+
ims = []
|
|
2357
|
+
for col in cols:
|
|
2358
|
+
im = Image.new('RGBA', (int(wd + 20 * u), int(lh * 1.5)), (0, 0, 0, 0))
|
|
2359
|
+
ImageDraw.Draw(im).text((4 * u, lh * 1.05), w['w'], font=f, fill=col + (255,), anchor='ls'); ims.append(to_np(im))
|
|
2360
|
+
items.append((ims[0], ims[1], x - 4 * u, y - lh * 0.2, w['s'], w['k'])); x += wd + sp
|
|
2361
|
+
return items
|
|
2362
|
+
|
|
2363
|
+
|
|
2364
|
+
# ---------- Adam Digital additions: captions ----------
|
|
2365
|
+
STOP = set("a an the and or but so to of in on at for with by from as is are was were be been it its it's this that these those i i'm "
|
|
2366
|
+
"i'll i've you you're your we our they their he she his her my me us them do does did not no yes just like can will "
|
|
2367
|
+
"would could should has have had than then there here what when where who why how all any some more most very really "
|
|
2368
|
+
"also only even about into over up out if".split())
|
|
2369
|
+
CAP = {'clean': (3, 22, 0.3), 'bold': (1, 40, 0.3), 'pill': (3, 16, 0.3), 'grey': (6, 32, 0.5), 'paper': (8, 46, 0.6)} # words, characters, pause
|
|
2370
|
+
|
|
2371
|
+
|
|
2372
|
+
def nword(w): return re.sub(r"[^\w%$+#/'-]", '', w).lower().strip("'")
|
|
2373
|
+
|
|
2374
|
+
|
|
2375
|
+
def key_set(e):
|
|
2376
|
+
k = e.o.get('keywords')
|
|
2377
|
+
return {nword(x) for part in str(k).split('|') for x in part.split() if nword(x)} if k else None
|
|
2378
|
+
|
|
2379
|
+
|
|
2380
|
+
def is_keyword(w, mid, keys):
|
|
2381
|
+
n = nword(w)
|
|
2382
|
+
if not n: return False
|
|
2383
|
+
if keys is not None: return n in keys
|
|
2384
|
+
raw = re.sub(r"[^\w%$+#/'-]", '', w)
|
|
2385
|
+
return any(ch.isdigit() for ch in raw) or (len(raw) >= 2 and raw.isupper()) or (mid and raw[:1].isupper() and n not in STOP)
|
|
2386
|
+
|
|
2387
|
+
|
|
2388
|
+
def cap_blocks(words, style, keys, kmax=1, one=False):
|
|
2389
|
+
"""Group words into caption blocks: [(words, start, end)]; each word gets 'k' = keyword."""
|
|
2390
|
+
mw, mc, gap = CAP[style]; blocks, cur, sent = [], [], True
|
|
2391
|
+
for w in words:
|
|
2392
|
+
t = str(w['w']).strip()
|
|
2393
|
+
if not t: continue
|
|
2394
|
+
if cur and not one and (len(cur) >= mw or len(' '.join(x['w'] for x in cur) + ' ' + t) > mc or w['s'] - cur[-1]['e'] > gap
|
|
2395
|
+
or cur[-1]['w'][-1] in '.,!?;:'):
|
|
2396
|
+
blocks.append(cur); cur = []
|
|
2397
|
+
cur.append(dict(w, w=t, mid=not sent)); sent = t[-1] in '.!?'
|
|
2398
|
+
if cur: blocks.append(cur)
|
|
2399
|
+
out = []
|
|
2400
|
+
for i, b in enumerate(blocks):
|
|
2401
|
+
n = 0
|
|
2402
|
+
for x in b: x['k'] = n < kmax and is_keyword(x['w'], x['mid'], keys); n += x['k']
|
|
2403
|
+
nxt = blocks[i + 1][0]['s'] if i + 1 < len(blocks) else None
|
|
2404
|
+
out.append((b, b[0]['s'] - 0.04, nxt - 0.04 if nxt is not None and nxt - b[-1]['e'] < 0.7 else b[-1]['e'] + 0.3))
|
|
2405
|
+
return out
|
|
2406
|
+
|
|
2407
|
+
|
|
2408
|
+
def soft_shadow(im, blur, alpha, dy=0):
|
|
2409
|
+
a = im.split()[3].point(lambda v: v * alpha // 255); sh = Image.new('RGBA', im.size, (0, 0, 0, 255)); sh.putalpha(a)
|
|
2410
|
+
out = Image.new('RGBA', im.size, (0, 0, 0, 0)); out.paste(sh, (0, dy), sh)
|
|
2411
|
+
return out.filter(ImageFilter.GaussianBlur(blur))
|
|
2412
|
+
|
|
2413
|
+
|
|
2414
|
+
def cap_word_imgs(block, u, style):
|
|
2415
|
+
"""One image per word on a shared baseline, plus each word's x offset and the line width."""
|
|
2416
|
+
if style == 'clean': fs = lambda k: font('didoneib', 84 * u * fit) if k else font('montb', 62 * u * fit); space, maxw = 22 * u, 960 * u
|
|
2417
|
+
else: fs = lambda k: font('popx', (96 if k else 84) * u * fit); space, maxw = 26 * u, 960 * u
|
|
2418
|
+
fit = 1.0
|
|
2419
|
+
txt = [(w['w'].lower() if style == 'clean' else w['w']).rstrip('.,;:') or w['w'] for w in block]
|
|
2420
|
+
width = lambda: sum(fs(w['k']).getlength(t) for w, t in zip(block, txt)) + space * (len(block) - 1)
|
|
2421
|
+
total = width()
|
|
2422
|
+
if total > maxw: fit = maxw / total * 0.98; total = width()
|
|
2423
|
+
asc = max(fs(k).getmetrics()[0] for k in (False, True)); desc = max(fs(k).getmetrics()[1] for k in (False, True))
|
|
2424
|
+
pad = int(40 * u); hgt = asc + desc + 2 * pad; out, x = [], 0.0
|
|
2425
|
+
for w, t in zip(block, txt):
|
|
2426
|
+
f = fs(w['k']); wd = f.getlength(t); im = Image.new('RGBA', (int(wd) + 2 * pad, hgt), (0, 0, 0, 0)); d = ImageDraw.Draw(im)
|
|
2427
|
+
if style == 'clean':
|
|
2428
|
+
d.text((pad, pad + asc), t, font=f, fill=((255, 226, 122) if w['k'] else (255, 255, 255)) + (255,), anchor='ls')
|
|
2429
|
+
im = Image.alpha_composite(Image.alpha_composite(soft_shadow(im, 28 * u, 153), soft_shadow(im, 8 * u, 128)), im)
|
|
2430
|
+
else:
|
|
2431
|
+
if w['k']: d.text((pad + 4 * u, pad + asc + 6 * u), t, font=f, fill=(17, 17, 20, 255), anchor='ls')
|
|
2432
|
+
d.text((pad, pad + asc), t, font=f, fill=((255, 211, 26) if w['k'] else (255, 255, 255)) + (255,), anchor='ls')
|
|
2433
|
+
im = Image.alpha_composite(soft_shadow(im, 14 * u, 140, int(4 * u)), im)
|
|
2434
|
+
out.append((to_np(im) if style == 'clean' else im, x - pad, w['s'])); x += wd + space
|
|
2435
|
+
return out, total, hgt
|
|
2436
|
+
|
|
2437
|
+
|
|
2438
|
+
def cap_pill(text, u, style):
|
|
2439
|
+
if style == 'pill': f, bg, r, h, padx = font('ui7', 64 * u), (22, 22, 28, 158), 20 * u, 88 * u, 22 * u
|
|
2440
|
+
else: f, bg, r, h, padx = font('ui7', 46 * u), (58, 58, 62, 225), 14 * u, None, 20 * u
|
|
2441
|
+
while f.getlength(text) > 900 * u and f.size > 12: f = ImageFont.truetype(f.path, int(f.size * 0.92)); f.set_variation_by_axes([32, 700])
|
|
2442
|
+
asc, desc = f.getmetrics(); h = h or asc + desc + 14 * u; w = f.getlength(text) + 2 * padx; pad = int(16 * u)
|
|
2443
|
+
im = Image.new('RGBA', (int(w) + 2 * pad, int(h) + 2 * pad), (0, 0, 0, 0)); d = ImageDraw.Draw(im)
|
|
2444
|
+
d.rounded_rectangle([pad, pad, pad + w, pad + h], r, fill=bg)
|
|
2445
|
+
txt = Image.new('RGBA', im.size, (0, 0, 0, 0)); ImageDraw.Draw(txt).text((pad + w / 2, pad + h / 2), text, font=f, fill=(255, 255, 255, 255), anchor='mm')
|
|
2446
|
+
im = Image.alpha_composite(im, Image.alpha_composite(soft_shadow(txt, 5 * u, 110, int(2 * u)), txt))
|
|
2447
|
+
return Image.alpha_composite(soft_shadow(im, 6 * u, 90, int(3 * u)), im)
|
|
2448
|
+
|
|
2449
|
+
|
|
2450
|
+
CAP_HIDE = {'halftone-paper', 'checklist', 'liquid-glass-graph', 'tier-list', 'messages', 'tape-label', 'phone-fan', 'broll-split',
|
|
2451
|
+
'split-headline', 'reel-frame', 'place-in-grid', 'headline-box', 'cover-star', 'red-collage', 'over-the-shoulder-zoom',
|
|
2452
|
+
'glass-widgets', 'timeline', 'profile-wall', 'headline-wall', 'pastel-word', 'check-pills'} # these own the lower screen
|
|
2453
|
+
|
|
2454
|
+
|
|
2455
|
+
@effect('captions', 'word-by-word captions in Adam Digital styles: clean (default), bold, pill or grey')
|
|
2456
|
+
def fx_captions(c, e):
|
|
2457
|
+
hide = cached(e, 'hide', lambda: [tuple(float(x) for x in h.split('-')[:2]) for h in str(e.o.get('hide', '')).split('|') if '-' in h])
|
|
2458
|
+
if c.act & CAP_HIDE or any(a <= c.t < b for a, b in hide): return
|
|
2459
|
+
style = e.o.get('style', 'clean'); style = style if style in ('clean', 'bold', 'pill', 'grey') else 'clean'; u = c.W / 1080
|
|
2460
|
+
bl = cached(e, 'blocks', lambda: cap_blocks(e.words, style, key_set(e), 0 if style == 'grey' else 1))
|
|
2461
|
+
j = e.state.get('j', 0)
|
|
2462
|
+
while j + 1 < len(bl) and bl[j + 1][1] <= c.t: j += 1
|
|
2463
|
+
e.state['j'] = j
|
|
2464
|
+
if not bl or not (bl[j][1] <= c.t < bl[j][2]): return
|
|
2465
|
+
b = bl[j][0]
|
|
2466
|
+
fx_, fy_, fw_ = e.med; chin = fy_ + fw_ * 0.75
|
|
2467
|
+
if e.o.get('y') is not None: yc = float(e.o['y']) * c.H
|
|
2468
|
+
elif style == 'clean': yc = clamp(fy_ + fw_ * 1.5, c.H * 0.58, c.H * 0.8)
|
|
2469
|
+
else: yc = c.H * {'bold': 0.77, 'pill': 0.766, 'grey': 0.693}[style]
|
|
2470
|
+
if style in ('clean', 'bold'):
|
|
2471
|
+
words, total, hgt = cached(e, ('w', j), lambda: cap_word_imgs(b, u, style))
|
|
2472
|
+
yc = max(yc, chin + hgt * 0.35) if e.o.get('y') is None else yc
|
|
2473
|
+
if c.cardbot: yc = c.cardbot + hgt * 0.42
|
|
2474
|
+
for n, (im, xo, ws) in enumerate(words):
|
|
2475
|
+
dt = c.t - ws + 0.06
|
|
2476
|
+
if dt < 0 and n: continue
|
|
2477
|
+
al = 1.0 if n == 0 else clamp(dt / 0.08)
|
|
2478
|
+
if style == 'clean':
|
|
2479
|
+
p = 1.0 if n == 0 else ease_back(dt / 0.18); comp(c, im, c.W / 2 - total / 2 + xo, yc - hgt / 2 + (1 - p) * 14 * u, al)
|
|
2480
|
+
else:
|
|
2481
|
+
p = ease_back(max(dt, 0) / 0.12); place(c, im, c.W / 2 - total / 2 + xo + im.width / 2, yc, 0.86 + 0.14 * p, 0, max(al, 0.6))
|
|
2482
|
+
else:
|
|
2483
|
+
im = cached(e, ('p', j), lambda: cap_pill(' '.join(w['w'] for w in b).rstrip('.,;:') if style == 'pill' else ' '.join(w['w'] for w in b), u, style))
|
|
2484
|
+
yc = max(yc, chin + im.height * 0.5) if e.o.get('y') is None else yc
|
|
2485
|
+
if c.cardbot: yc = c.cardbot + im.height * 0.55
|
|
2486
|
+
sc = 0.9 + 0.1 * ease_out((c.t - bl[j][1]) / 0.09) if style == 'pill' else 1.0
|
|
2487
|
+
place(c, im, c.W / 2, yc, sc)
|
|
2488
|
+
|
|
2489
|
+
|
|
2490
|
+
# ---------- video in/out + tracking ----------
|
|
2491
|
+
def probe(path):
|
|
2492
|
+
j = json.loads(subprocess.run(['ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=r_frame_rate:format=duration',
|
|
2493
|
+
'-of', 'json', path], capture_output=True, text=True, check=True).stdout)
|
|
2494
|
+
fr = j['streams'][0]['r_frame_rate']; num, den = fr.split('/'); fps = float(num) / float(den or 1)
|
|
2495
|
+
png = subprocess.run(['ffmpeg', '-v', 'error', '-i', path, '-frames:v', '1', '-f', 'image2pipe', '-vcodec', 'png', '-'], capture_output=True, check=True).stdout
|
|
2496
|
+
h, w = cv2.imdecode(np.frombuffer(png, np.uint8), cv2.IMREAD_COLOR).shape[:2]
|
|
2497
|
+
return (fr if fps <= 30.5 else '30'), min(fps, 30.0), float(j['format']['duration']), w, h
|
|
2498
|
+
|
|
2499
|
+
|
|
2500
|
+
def read_frames(path, W, H, fr):
|
|
2501
|
+
p = subprocess.Popen(['ffmpeg', '-v', 'error', '-i', path, '-vf', f'fps={fr},scale={W}:{H}:flags=bicubic,format=rgb24', '-f', 'rawvideo', '-'],
|
|
2502
|
+
stdout=subprocess.PIPE, bufsize=10 ** 8)
|
|
2503
|
+
n = W * H * 3
|
|
2504
|
+
try:
|
|
2505
|
+
while True:
|
|
2506
|
+
b = p.stdout.read(n)
|
|
2507
|
+
if len(b) < n: break
|
|
2508
|
+
yield np.frombuffer(b, np.uint8).reshape(H, W, 3)
|
|
2509
|
+
finally:
|
|
2510
|
+
if p.poll() is None: p.kill()
|
|
2511
|
+
p.stdout.close(); p.wait()
|
|
2512
|
+
|
|
2513
|
+
|
|
2514
|
+
def guided(I, p, r=8, eps=2e-3):
|
|
2515
|
+
box = lambda x: cv2.boxFilter(x, -1, (2 * r + 1, 2 * r + 1))
|
|
2516
|
+
mI, mp_ = box(I), box(p); a = (box(I * p) - mI * mp_) / (box(I * I) - mI * mI + eps); b = mp_ - a * mI
|
|
2517
|
+
return np.clip(box(a) * I + box(b), 0, 1)
|
|
2518
|
+
|
|
2519
|
+
|
|
2520
|
+
class Tracker:
|
|
2521
|
+
def __init__(self, aw, ah):
|
|
2522
|
+
import mediapipe as mp
|
|
2523
|
+
from mediapipe.tasks.python import vision
|
|
2524
|
+
from mediapipe.tasks.python.core.base_options import BaseOptions
|
|
2525
|
+
self.mp = mp
|
|
2526
|
+
self.seg = vision.ImageSegmenter.create_from_options(vision.ImageSegmenterOptions(
|
|
2527
|
+
base_options=BaseOptions(model_asset_path=os.path.join(ROOT, 'models', 'selfie_segmenter.tflite')),
|
|
2528
|
+
running_mode=vision.RunningMode.VIDEO, output_confidence_masks=True, output_category_mask=False))
|
|
2529
|
+
self.fd = cv2.FaceDetectorYN.create(os.path.join(ROOT, 'models', 'yunet.onnx'), '', (aw, ah), 0.6, 0.3, 20)
|
|
2530
|
+
self.prev = None
|
|
2531
|
+
|
|
2532
|
+
def __call__(self, rgb, ms):
|
|
2533
|
+
img = self.mp.Image(image_format=self.mp.ImageFormat.SRGB, data=np.ascontiguousarray(rgb))
|
|
2534
|
+
ms_ = self.seg.segment_for_video(img, ms).confidence_masks
|
|
2535
|
+
m = ms_[-1].numpy_view().astype(np.float32); m = m.reshape(m.shape[0], m.shape[1])
|
|
2536
|
+
if m.shape[:2] != rgb.shape[:2]: m = cv2.resize(m, (rgb.shape[1], rgb.shape[0]))
|
|
2537
|
+
m = guided(cv2.cvtColor(rgb, cv2.COLOR_RGB2GRAY).astype(np.float32) / 255, m)
|
|
2538
|
+
m = np.clip((m - 0.5) * 1.6 + 0.5, 0, 1)
|
|
2539
|
+
if self.prev is not None: m = 0.65 * m + 0.35 * self.prev
|
|
2540
|
+
self.prev = m
|
|
2541
|
+
_, f = self.fd.detect(cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR))
|
|
2542
|
+
face = None
|
|
2543
|
+
if f is not None and len(f):
|
|
2544
|
+
r = max(f, key=lambda r: r[2] * r[3] * r[-1]); face = (r[0] + r[2] / 2, r[1] + r[3] / 2, r[2])
|
|
2545
|
+
else:
|
|
2546
|
+
rows = np.where((m > 0.5).sum(1) > m.shape[1] * 0.01)[0]
|
|
2547
|
+
if len(rows):
|
|
2548
|
+
top = rows[0]; band = m[top:top + max(4, int(m.shape[0] * 0.06))] > 0.5; xs = np.where(band.any(0))[0]
|
|
2549
|
+
fw = max(8.0, (xs.max() - xs.min()) * 0.8); face = (float(xs.mean()), top + fw * 0.7, fw)
|
|
2550
|
+
return (m * 255).astype(np.uint8), face
|
|
2551
|
+
|
|
2552
|
+
|
|
2553
|
+
def smooth(vals, fps, tau=0.18):
|
|
2554
|
+
idx = [i for i, v in enumerate(vals) if v is not None]
|
|
2555
|
+
if not idx: return None
|
|
2556
|
+
arr = np.array([vals[i] if vals[i] is not None else (np.nan,) * 3 for i in range(len(vals))], np.float64)
|
|
2557
|
+
for k in range(3):
|
|
2558
|
+
col = arr[:, k]; good = ~np.isnan(col); col[~good] = np.interp(np.where(~good)[0], np.where(good)[0], col[good]); arr[:, k] = col
|
|
2559
|
+
a = 1 - math.exp(-1 / (fps * tau)) # forward then backward pass, so the smoothing has no lag
|
|
2560
|
+
for i in range(1, len(arr)): arr[i] = arr[i - 1] + a * (arr[i] - arr[i - 1])
|
|
2561
|
+
for i in range(len(arr) - 2, -1, -1): arr[i] = arr[i + 1] + a * (arr[i] - arr[i + 1])
|
|
2562
|
+
return arr
|
|
2563
|
+
|
|
2564
|
+
|
|
2565
|
+
class Ctx: pass
|
|
2566
|
+
|
|
2567
|
+
|
|
2568
|
+
class Fx:
|
|
2569
|
+
def __init__(self, d, fps):
|
|
2570
|
+
self.name = d['fx']; self.start = float(d.get('start', 0)); self.end = float(d.get('end', 1e9)); self.d = max(0.05, self.end - self.start)
|
|
2571
|
+
self.o = {k: v for k, v in d.items() if k not in ('fx', 'start', 'end')}; self.state = {}; self.cards = []
|
|
2572
|
+
self.words = []; self.med = None; self.top = None
|
|
2573
|
+
|
|
2574
|
+
|
|
2575
|
+
def load_cards(folder, thumbs):
|
|
2576
|
+
out = []
|
|
2577
|
+
if folder and os.path.isdir(folder):
|
|
2578
|
+
for n in sorted(os.listdir(folder)):
|
|
2579
|
+
p = os.path.join(folder, n); ext = n.lower().rsplit('.', 1)[-1]
|
|
2580
|
+
if ext in ('jpg', 'jpeg', 'png', 'webp'): out.append(Image.open(p).convert('RGB'))
|
|
2581
|
+
elif ext in ('mp4', 'mov', 'm4v', 'webm'):
|
|
2582
|
+
cap = cv2.VideoCapture(p); cap.set(cv2.CAP_PROP_POS_MSEC, 1000); ok, fr = cap.read(); cap.release()
|
|
2583
|
+
if ok: out.append(Image.fromarray(cv2.cvtColor(fr, cv2.COLOR_BGR2RGB)))
|
|
2584
|
+
return out or thumbs
|
|
2585
|
+
|
|
2586
|
+
|
|
2587
|
+
WORD_FX = ('captions', 'halftone-paper') # effects that need to know when each word is said
|
|
2588
|
+
|
|
2589
|
+
|
|
2590
|
+
def has_audio(path):
|
|
2591
|
+
r = subprocess.run(['ffprobe', '-v', 'error', '-select_streams', 'a', '-show_entries', 'stream=index', '-of', 'csv=p=0', path],
|
|
2592
|
+
capture_output=True, text=True)
|
|
2593
|
+
return bool(r.stdout.strip())
|
|
2594
|
+
|
|
2595
|
+
|
|
2596
|
+
def main():
|
|
2597
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
2598
|
+
ap.add_argument('args', nargs='*', help='[effect] input.mp4 output.mp4')
|
|
2599
|
+
ap.add_argument('--plan'); ap.add_argument('--start', type=float); ap.add_argument('--end', type=float)
|
|
2600
|
+
ap.add_argument('--text'); ap.add_argument('--images'); ap.add_argument('--opt', action='append', default=[], help='key=value')
|
|
2601
|
+
ap.add_argument('--still', help='comma-separated seconds: save PNG check frames instead of a video')
|
|
2602
|
+
ap.add_argument('--width', type=int, default=1080, help='short side of the output (1080 default, 2160 for 4K)')
|
|
2603
|
+
ap.add_argument('--words', help='a words.json from words.py (default: <video>.words.json, made if missing)')
|
|
2604
|
+
ap.add_argument('--no-sfx', action='store_true', help='no sound effects')
|
|
2605
|
+
ap.add_argument('--sfx-volume', type=float, default=0.0, help='sound effects louder/quieter in dB (e.g. -4)')
|
|
2606
|
+
ap.add_argument('--profile', nargs='*', metavar='NAME HANDLE', help='save your name and handle, or show them')
|
|
2607
|
+
ap.add_argument('--list', action='store_true')
|
|
2608
|
+
a = ap.parse_args()
|
|
2609
|
+
if a.list:
|
|
2610
|
+
for i, (k, (_, d)) in enumerate(EFFECTS.items()): print(f'{i + 1:2d}. {k:22s} {d}')
|
|
2611
|
+
return
|
|
2612
|
+
if a.profile is not None:
|
|
2613
|
+
if len(a.profile) == 2:
|
|
2614
|
+
h = a.profile[1].strip(); json.dump({'name': a.profile[0].strip(), 'handle': h if h.startswith('@') else '@' + h}, open(PROFILE_PATH, 'w'), indent=1)
|
|
2615
|
+
p = load_profile(); print(f"Profile: {p['name']} ({p['handle']})" + ('' if os.path.exists(PROFILE_PATH) else ' [not set yet]'))
|
|
2616
|
+
return
|
|
2617
|
+
sfx_on, sfx_db = not a.no_sfx, a.sfx_volume
|
|
2618
|
+
if a.plan:
|
|
2619
|
+
src, dst = a.args[0], a.args[1]; plan = json.load(open(a.plan))
|
|
2620
|
+
if isinstance(plan, dict):
|
|
2621
|
+
sfx_on = sfx_on and plan.get('sfx', True) is not False; sfx_db = float(plan.get('sfx_volume', sfx_db)); plan = plan.get('effects', [])
|
|
2622
|
+
else:
|
|
2623
|
+
name, src, dst = a.args[0], a.args[1], a.args[2]
|
|
2624
|
+
d = {'fx': name, 'start': a.start or 0.0, 'end': a.end if a.end is not None else 1e9}
|
|
2625
|
+
if a.text: d['text'] = a.text
|
|
2626
|
+
if a.images: d['images'] = a.images
|
|
2627
|
+
for kv in a.opt: k, v = kv.split('=', 1); d[k] = v
|
|
2628
|
+
plan = [d]
|
|
2629
|
+
for d in plan:
|
|
2630
|
+
d['fx'] = ALIASES.get(d['fx'].lower().lstrip('/'), d['fx'].lower().lstrip('/'))
|
|
2631
|
+
if d['fx'] in LOOK_NAMES: d['fx'], look = LOOK_NAMES[d['fx']]; d.setdefault('look', look)
|
|
2632
|
+
if d['fx'] not in EFFECTS: sys.exit(f"Unknown effect '{d['fx']}'. Run --list to see all {len(EFFECTS)}.")
|
|
2633
|
+
fr, fps, dur, sw, sh = probe(src)
|
|
2634
|
+
for d in plan: d['start'] = max(0.0, float(d.get('start', 0))); d['end'] = min(float(d.get('end', 1e9)), dur)
|
|
2635
|
+
if sw <= sh: W = a.width; H = int(round(a.width * sh / sw / 2)) * 2
|
|
2636
|
+
else: H = a.width; W = int(round(a.width * sw / sh / 2)) * 2
|
|
2637
|
+
aw = 540 if sw <= sh else int(round(540 * sw / sh / 2)) * 2; ah = int(round(aw * sh / sw / 2)) * 2
|
|
2638
|
+
fxs = [Fx(d, fps) for d in plan]
|
|
2639
|
+
if any(f.name in WORD_FX for f in fxs) and (a.words or has_audio(src)):
|
|
2640
|
+
import words as words_mod
|
|
2641
|
+
allw = json.load(open(a.words)) if a.words else words_mod.load_or_make(src)
|
|
2642
|
+
for f in fxs: f.words = [w for w in allw if f.start - 0.05 <= w['s'] < f.end]
|
|
2643
|
+
inwin = lambda t: any(f.start - 0.5 <= t < f.end + 0.5 for f in fxs)
|
|
2644
|
+
print(f'Pass 1: tracking you ({len(fxs)} effect{"s" * (len(fxs) > 1)})...', flush=True)
|
|
2645
|
+
trk = Tracker(aw, ah); masks, faces, thumbs = {}, [], []
|
|
2646
|
+
n_thumb = 10; thumb_at = {int(dur * fps * (j + 0.5) / n_thumb) for j in range(n_thumb)}
|
|
2647
|
+
for i, fr_ in enumerate(read_frames(src, aw, ah, fr)):
|
|
2648
|
+
t = i / fps
|
|
2649
|
+
if i in thumb_at: thumbs.append(Image.fromarray(fr_.copy()))
|
|
2650
|
+
if inwin(t):
|
|
2651
|
+
m, f = trk(fr_, int(t * 1000)); masks[i] = m; faces.append(f)
|
|
2652
|
+
else:
|
|
2653
|
+
faces.append(None); trk.prev = None
|
|
2654
|
+
try: trk.seg.close()
|
|
2655
|
+
except Exception: pass
|
|
2656
|
+
sm = smooth(faces, fps)
|
|
2657
|
+
if sm is None: sm = np.tile([aw / 2, ah * 0.33, aw * 0.15], (len(faces), 1))
|
|
2658
|
+
sc = W / aw
|
|
2659
|
+
for f in fxs:
|
|
2660
|
+
if f.name in CARD_FX: f.cards = load_cards(f.o.get('images'), thumbs)
|
|
2661
|
+
rows = sm[max(0, int(f.start * fps)):max(int(f.start * fps) + 1, min(len(sm), int(f.end * fps)))]
|
|
2662
|
+
f.med = tuple(float(v) * sc for v in np.median(rows if len(rows) else sm, axis=0))
|
|
2663
|
+
tops = []
|
|
2664
|
+
for i in range(max(0, int(f.start * fps)), min(len(sm), int(f.end * fps) + 1), 3):
|
|
2665
|
+
m = masks.get(i)
|
|
2666
|
+
if m is None: continue
|
|
2667
|
+
fx_, fy_, fw_ = sm[i]; band = m[:, max(0, int(fx_ - fw_ * 0.35)):int(fx_ + fw_ * 0.35) + 1]
|
|
2668
|
+
r = np.nonzero((band > 128).mean(1) > 0.25)[0]
|
|
2669
|
+
if len(r) and r[0] < fy_: tops.append(r[0])
|
|
2670
|
+
if tops: f.top = float(np.median(tops)) * sc
|
|
2671
|
+
stills = sorted({int(round(float(s) * fps)) for s in a.still.split(',')}) if a.still else None
|
|
2672
|
+
enc = None
|
|
2673
|
+
if not stills:
|
|
2674
|
+
cmd = ['ffmpeg', '-v', 'error', '-y', '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-s', f'{W}x{H}', '-r', str(fr), '-i', '-', '-i', src]
|
|
2675
|
+
import sfx
|
|
2676
|
+
evs = [ev for f in fxs for ev in sfx.events(f.name, f.start, f.end, f.o)] if sfx_on else []
|
|
2677
|
+
if evs:
|
|
2678
|
+
sfx_path = os.path.splitext(dst)[0] + '.sfx.wav'; sfx.write(sfx_path, sfx.track(evs, dur, sfx_db)); cmd += ['-i', sfx_path]
|
|
2679
|
+
print(f'Adding {len(evs)} sound effects.', flush=True)
|
|
2680
|
+
if has_audio(src):
|
|
2681
|
+
cmd += ['-filter_complex', '[1:a:0]aresample=48000,aformat=channel_layouts=stereo[v0];[v0][2:a]amix=inputs=2:duration=first:normalize=0,'
|
|
2682
|
+
'alimiter=limit=0.97:level=disabled[a]', '-map', '0:v', '-map', '[a]']
|
|
2683
|
+
else: cmd += ['-map', '0:v', '-map', '2:a']
|
|
2684
|
+
else: cmd += ['-map', '0:v', '-map', '1:a:0?']
|
|
2685
|
+
enc = subprocess.Popen(cmd + [*h264_encode_args(crf=17, preset='medium'),
|
|
2686
|
+
'-c:a', 'aac', '-b:a', '192k', '-shortest', '-movflags', '+faststart', dst], stdin=subprocess.PIPE)
|
|
2687
|
+
print('Pass 2: adding the effects...', flush=True)
|
|
2688
|
+
for i, frame in enumerate(read_frames(src, W, H, fr)):
|
|
2689
|
+
t = i / fps
|
|
2690
|
+
act = sorted([f for f in fxs if f.start <= t < f.end], key=lambda f: f.name == 'captions') # captions always on top
|
|
2691
|
+
if stills is not None and i not in stills:
|
|
2692
|
+
if i > stills[-1]: break
|
|
2693
|
+
continue
|
|
2694
|
+
if act:
|
|
2695
|
+
c = Ctx(); c.W, c.H, c.t, c.fps = W, H, t, fps; c.act = {f.name for f in act}; c.cardbot = None
|
|
2696
|
+
c.img = frame.astype(np.float32) / 255.0
|
|
2697
|
+
m = masks.get(i)
|
|
2698
|
+
c.m = cv2.resize(m, (W, H), interpolation=cv2.INTER_LINEAR).astype(np.float32) / 255.0 if m is not None else np.zeros((H, W), np.float32)
|
|
2699
|
+
fx_, fy_, fw_ = sm[min(i, len(sm) - 1)]; c.fx, c.fy, c.fw = fx_ * sc, fy_ * sc, max(fw_ * sc, W * 0.05)
|
|
2700
|
+
for f in act:
|
|
2701
|
+
c.lt = t - f.start; EFFECTS[f.name][0](c, f)
|
|
2702
|
+
frame = (np.clip(c.img, 0, 1) * 255 + 0.5).astype(np.uint8)
|
|
2703
|
+
if stills is not None:
|
|
2704
|
+
out = dst if len(stills) == 1 else dst.replace('.png', f'_{t:.2f}.png')
|
|
2705
|
+
cv2.imwrite(out, cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)); print('saved', out)
|
|
2706
|
+
else:
|
|
2707
|
+
enc.stdin.write(frame.tobytes())
|
|
2708
|
+
if i % int(fps * 5) == 0: print(f' {t:5.1f}s / {dur:.1f}s', flush=True)
|
|
2709
|
+
if enc:
|
|
2710
|
+
enc.stdin.close(); enc.wait()
|
|
2711
|
+
sp = os.path.splitext(dst)[0] + '.sfx.wav'
|
|
2712
|
+
if os.path.exists(sp): os.remove(sp)
|
|
2713
|
+
print('Done:', dst)
|
|
2714
|
+
|
|
2715
|
+
|
|
2716
|
+
if __name__ == '__main__':
|
|
2717
|
+
main()
|