@clipen/clipen-cli 1.0.0 → 1.0.1

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.
Files changed (127) hide show
  1. package/README.md +60 -50
  2. package/package.json +7 -4
  3. package/pyproject.toml +18 -2
  4. package/requirements/dev.txt +2 -0
  5. package/src/clipen/__init__.py +1 -1
  6. package/src/clipen/analysis/__init__.py +7 -7
  7. package/src/clipen/analysis/artifacts.py +4 -10
  8. package/src/clipen/analysis/audio.py +10 -8
  9. package/src/clipen/analysis/evidence_service.py +345 -167
  10. package/src/clipen/analysis/image_similarity.py +5 -14
  11. package/src/clipen/analysis/keyframes.py +5 -17
  12. package/src/clipen/analysis/models.py +5 -7
  13. package/src/clipen/analysis/qwen_worker.py +19 -54
  14. package/src/clipen/analysis/resources.py +2 -1
  15. package/src/clipen/analysis/runtime.py +1 -3
  16. package/src/clipen/analysis/service.py +16 -48
  17. package/src/clipen/analysis/setup.py +11 -25
  18. package/src/clipen/analysis/setup_cli.py +5 -15
  19. package/src/clipen/analysis/storage.py +96 -278
  20. package/src/clipen/analysis/transcription.py +40 -82
  21. package/src/clipen/analysis/visual.py +109 -48
  22. package/src/clipen/annotations/__init__.py +5 -2
  23. package/src/clipen/annotations/models.py +1 -1
  24. package/src/clipen/annotations/storage.py +132 -84
  25. package/src/clipen/annotations/suggestions.py +3 -8
  26. package/src/clipen/asr_release.py +4 -11
  27. package/src/clipen/bootstrap.py +65 -54
  28. package/src/clipen/{planning/models.py → candidates.py} +29 -47
  29. package/src/clipen/cli.py +2 -2
  30. package/src/clipen/controller/app.py +401 -214
  31. package/src/clipen/controller/server.py +28 -38
  32. package/src/clipen/domain/__init__.py +1 -1
  33. package/src/clipen/domain/media_time.py +3 -10
  34. package/src/clipen/domain/timeline.py +45 -47
  35. package/src/clipen/domain/validation.py +0 -1
  36. package/src/clipen/editing/__init__.py +1 -1
  37. package/src/clipen/editing/agent_models.py +4 -11
  38. package/src/clipen/editing/agent_repository.py +391 -170
  39. package/src/clipen/editing/agent_tools.py +180 -99
  40. package/src/clipen/editing/alignment.py +92 -52
  41. package/src/clipen/editing/alignment_setup.py +118 -70
  42. package/src/clipen/editing/alignment_worker.py +11 -9
  43. package/src/clipen/editing/change_report.py +95 -38
  44. package/src/clipen/editing/compiler.py +0 -1
  45. package/src/clipen/editing/component_looks.py +58 -34
  46. package/src/clipen/editing/component_review.py +34 -38
  47. package/src/clipen/editing/coordinator.py +213 -90
  48. package/src/clipen/editing/editorial_review.py +217 -95
  49. package/src/clipen/editing/evidence_jobs.py +457 -200
  50. package/src/clipen/editing/history_changes.py +129 -68
  51. package/src/clipen/editing/music_choices.py +8 -5
  52. package/src/clipen/editing/production_catalog.py +573 -136
  53. package/src/clipen/editing/production_limits.py +43 -17
  54. package/src/clipen/editing/production_media.py +376 -167
  55. package/src/clipen/editing/production_preview.py +322 -129
  56. package/src/clipen/editing/production_progress.py +164 -69
  57. package/src/clipen/editing/production_requirements.py +106 -39
  58. package/src/clipen/editing/production_tools.py +1064 -462
  59. package/src/clipen/editing/program_audio.py +211 -81
  60. package/src/clipen/editing/program_direction.py +59 -25
  61. package/src/clipen/editing/program_story.py +83 -45
  62. package/src/clipen/editing/program_subtitles.py +194 -96
  63. package/src/clipen/editing/programme_review.py +98 -50
  64. package/src/clipen/editing/prompt_history.py +64 -27
  65. package/src/clipen/editing/recut.py +65 -25
  66. package/src/clipen/editing/refinement_references.py +176 -86
  67. package/src/clipen/editing/resolve_export.py +449 -218
  68. package/src/clipen/editing/resolve_titles.py +162 -105
  69. package/src/clipen/editing/skill_tools.py +530 -154
  70. package/src/clipen/editing/source_dialogue.py +177 -67
  71. package/src/clipen/editing/speech_coverage.py +42 -22
  72. package/src/clipen/editing/speech_quality.py +6 -1
  73. package/src/clipen/editing/tool_receipts.py +78 -32
  74. package/src/clipen/editing/versions.py +122 -64
  75. package/src/clipen/editing/visual_preview.py +157 -61
  76. package/src/clipen/editing/workbench.py +104 -42
  77. package/src/clipen/finishing/audio.py +69 -30
  78. package/src/clipen/finishing/catalog.py +176 -93
  79. package/src/clipen/finishing/models.py +1 -1
  80. package/src/clipen/finishing/renderer.py +33 -14
  81. package/src/clipen/mcp_editing/__main__.py +3 -1
  82. package/src/clipen/mcp_editing/server.py +77 -34
  83. package/src/clipen/media/__init__.py +3 -3
  84. package/src/clipen/media/discovery.py +7 -20
  85. package/src/clipen/media/models.py +7 -18
  86. package/src/clipen/media/preview.py +14 -24
  87. package/src/clipen/media/probe.py +16 -44
  88. package/src/clipen/media/service.py +6 -19
  89. package/src/clipen/media/storage.py +33 -81
  90. package/src/clipen/music_vocabulary.py +33 -4
  91. package/src/clipen/power.py +8 -3
  92. package/src/clipen/projects/__init__.py +1 -1
  93. package/src/clipen/projects/deletion.py +19 -32
  94. package/src/clipen/projects/finishing_schema.py +3 -1
  95. package/src/clipen/projects/models.py +2 -5
  96. package/src/clipen/projects/picker.py +13 -37
  97. package/src/clipen/projects/service.py +8 -24
  98. package/src/clipen/projects/storage.py +226 -246
  99. package/src/clipen/provider_registry.py +4 -2
  100. package/src/clipen/providers/account.py +86 -35
  101. package/src/clipen/providers/claude.py +59 -25
  102. package/src/clipen/providers/claude_editing.py +14 -7
  103. package/src/clipen/providers/codex.py +73 -118
  104. package/src/clipen/providers/codex_editing.py +2 -2
  105. package/src/clipen/providers/editing_agent.py +19 -17
  106. package/src/clipen/providers/recovery.py +7 -8
  107. package/src/clipen/rendering/cover.py +18 -5
  108. package/src/clipen/rendering/custom_components.py +167 -79
  109. package/src/clipen/rendering/custom_render.py +62 -41
  110. package/src/clipen/rendering/production_effects.py +77 -45
  111. package/src/clipen/rendering/program_components.py +134 -73
  112. package/src/clipen/rendering/program_creator.py +432 -277
  113. package/src/clipen/rendering/program_identities.py +277 -182
  114. package/src/clipen/rendering/program_motion.py +140 -95
  115. package/src/clipen/rendering/program_studio.py +175 -116
  116. package/src/clipen/rendering/program_styles.py +231 -145
  117. package/src/clipen/rendering/program_subtitles.py +71 -34
  118. package/src/clipen/rendering/renderer.py +150 -121
  119. package/src/clipen/rendering/storage.py +9 -22
  120. package/src/clipen/rendering/titles.py +193 -86
  121. package/src/clipen/skills/__init__.py +1 -0
  122. package/src/clipen/skills/catalog.py +151 -55
  123. package/src/clipen/skills/library.py +13 -7
  124. package/src/clipen/skills/package.py +46 -23
  125. package/src/clipen/skills/visual_styles.py +29 -18
  126. package/src/clipen/workspace.py +15 -44
  127. package/src/clipen/planning/__init__.py +0 -9
@@ -11,115 +11,164 @@ popped, then composited at its footprint. Layout returns that footprint, so
11
11
  collision and safe-area checks cover every frame of the animation (pointer and
12
12
  circle targets are drawn separately at their target).
13
13
  """
14
+
14
15
  import math
15
16
  from pathlib import Path
16
17
 
17
18
  from PIL import Image, ImageDraw, ImageFilter
18
19
 
20
+ from .program_styles import draw_style_text, load_style_font, styled_text_length
19
21
  from .titles import TitleRenderError
20
- from .program_styles import load_style_font, styled_text_length, draw_style_text
21
22
 
22
- HERO = {'program_title', 'headline', 'impact', 'chapter', 'burst'}
23
- POP = {'impact', 'burst', 'reaction', 'headline', 'program_title'}
24
- SIZES = {'program_title': .105, 'headline': .082, 'chapter': .038, 'impact': .13, 'burst': .1,
25
- 'reaction': .096, 'location': .036, 'person': .056, 'fact': .062, 'pointer': .052, 'circle': .05}
26
- TILT = {'impact': -4, 'reaction': -5, 'burst': 4}
23
+ HERO = {"program_title", "headline", "impact", "chapter", "burst"}
24
+ POP = {"impact", "burst", "reaction", "headline", "program_title"}
25
+ SIZES = {
26
+ "program_title": 0.105,
27
+ "headline": 0.082,
28
+ "chapter": 0.038,
29
+ "impact": 0.13,
30
+ "burst": 0.1,
31
+ "reaction": 0.096,
32
+ "location": 0.036,
33
+ "person": 0.056,
34
+ "fact": 0.062,
35
+ "pointer": 0.052,
36
+ "circle": 0.05,
37
+ }
38
+ TILT = {"impact": -4, "reaction": -5, "burst": 4}
27
39
  POP_SLACK = 1.08
28
- GROUPS = {'program_title': 'title', 'headline': 'title', 'location': 'tag', 'chapter': 'tag',
29
- 'impact': 'sticker', 'reaction': 'sticker', 'burst': 'sticker',
30
- 'fact': 'info', 'person': 'info', 'pointer': 'info', 'circle': 'info'}
31
- DEFAULT_LOOK = {'title': 'outline', 'tag': 'shadow', 'sticker': 'sticker', 'info': 'outline'}
40
+ GROUPS = {
41
+ "program_title": "title",
42
+ "headline": "title",
43
+ "location": "tag",
44
+ "chapter": "tag",
45
+ "impact": "sticker",
46
+ "reaction": "sticker",
47
+ "burst": "sticker",
48
+ "fact": "info",
49
+ "person": "info",
50
+ "pointer": "info",
51
+ "circle": "info",
52
+ }
53
+ DEFAULT_LOOK = {"title": "outline", "tag": "shadow", "sticker": "sticker", "info": "outline"}
32
54
 
33
55
 
34
56
  def _row(fill, stroke=None, outer=None, track=0, shadow=None):
35
- return {'fill': fill, 'stroke': stroke, 'outer': outer, 'track': track, 'shadow': shadow}
57
+ return {"fill": fill, "stroke": stroke, "outer": outer, "track": track, "shadow": shadow}
36
58
 
37
59
 
38
60
  # Row styles are (primary, detail). Colours name palette entries, optionally
39
61
  # with an alpha multiplier. A look may add a shape behind the text, extras
40
62
  # drawn around single rows, a tilt and a row arrangement.
41
63
  LOOKS = {
42
- ('title', 'outline'): {'rows': (_row('paper', ('ink', .13)), _row('accent', ('ink', .14))), 'split': True},
43
- ('title', 'block'): {'rows': (_row('paper', ('ink', .05)), _row('ink')), 'shape': 'block'},
44
- ('title', 'serif'): {'rows': (_row('paper', track=.16, shadow='soft'), _row(('paper', .88), track=.22, shadow='soft')),
45
- 'extras': ('rule_below',), 'detail_scale': .4, 'row_gap': .24},
46
- ('title', 'pill'): {'rows': (_row('paper'), _row(('paper', .92))), 'shape': 'pill'},
47
- ('title', 'doodle'): {'rows': (_row('paper', ('ink', .05), shadow='hard:accent'), _row('paper', ('ink', .08))),
48
- 'extras': ('squiggle',), 'split': True, 'row_gap': .26},
49
- ('title', 'panel'): {'rows': (_row('paper'), _row('accent')), 'shape': 'panel'},
50
- ('title', 'bar'): {'rows': (_row('paper', ('ink', .1)), _row('paper', ('ink', .12))), 'extras': ('highlight',)},
51
- ('title', 'rules'): {'rows': (_row('accent', track=.06, shadow='deep'), _row('paper', track=.3, shadow='deep')),
52
- 'extras': ('rules',), 'detail_scale': .4},
53
- ('title', 'meme'): {'rows': (_row('paper', ('secondary', .15), ('ink', .09)), _row('accent', ('ink', .14)))},
54
- ('tag', 'shadow'): {'rows': (_row('paper', ('ink', .06), shadow='drop'),), 'join': ' | '},
55
- ('tag', 'tape'): {'rows': (_row('ink'),), 'join': ' ', 'shape': 'tape', 'tilt': -2},
56
- ('tag', 'label'): {'rows': (_row('paper'),), 'join': ' ', 'shape': 'label'},
57
- ('tag', 'rules'): {'rows': (_row('paper', track=.24, shadow='deep'),), 'join': ' ', 'extras': ('rules',)},
58
- ('tag', 'dot'): {'rows': (_row('paper', ('ink', .1)),), 'join': '|', 'extras': ('dot',)},
59
- ('tag', 'keycap'): {'rows': (_row('ink'), _row('paper')), 'inline': True, 'boxes': ('accent', ('ink', .82)),
60
- 'detail_scale': 1.},
61
- ('tag', 'chip'): {'rows': (_row('ink'),), 'join': ' ', 'shape': 'chip'},
62
- ('tag', 'flag'): {'rows': (_row('ink'),), 'join': '|', 'shape': 'flag'},
63
- ('tag', 'meme'): {'rows': (_row('ink'),), 'join': ' ', 'shape': 'memebox', 'tilt': -2},
64
- ('sticker', 'sticker'): {'rows': (_row('accent', ('ink', .10), ('paper', .24)), _row('paper', ('ink', .14)))},
65
- ('sticker', 'burst'): {'rows': (_row('paper', ('ink', .1)), _row('ink')), 'shape': 'burst'},
66
- ('sticker', 'quiet'): {'rows': (_row('paper', track=.1, shadow='soft'), _row(('paper', .85), track=.2, shadow='soft')),
67
- 'tilt': 0},
68
- ('sticker', 'bubble'): {'rows': (_row('ink'), _row(('ink', .7))), 'shape': 'bubble', 'tilt': -3},
69
- ('sticker', 'doodle'): {'rows': (_row('accent', ('paper', .1), shadow='soft'), _row('paper', shadow='soft')),
70
- 'extras': ('sparkles',)},
71
- ('sticker', 'pill'): {'rows': (_row('ink'), _row(('ink', .75))), 'shape': 'pill', 'tilt': 0},
72
- ('sticker', 'stamp'): {'rows': (_row('accent'), _row('accent')), 'shape': 'stamp', 'tilt': -7},
73
- ('sticker', 'glow'): {'rows': (_row('accent', track=.08, shadow='glow'), _row('paper', track=.16, shadow='deep')),
74
- 'tilt': 0},
75
- ('sticker', 'meme'): {'rows': (_row('accent', ('ink', .11), ('paper', .2), shadow='hard:secondary'),
76
- _row('paper', ('ink', .14)))},
77
- ('info', 'outline'): {'rows': (_row('accent', ('ink', .12)), _row('paper', ('ink', .12)))},
78
- ('info', 'label'): {'rows': (_row('paper'), _row('ink')), 'boxes': ('ink', 'accent')},
79
- ('info', 'quiet'): {'rows': (_row('paper', track=.06, shadow='soft'), _row(('paper', .82), shadow='soft')),
80
- 'extras': ('vline',)},
81
- ('info', 'price'): {'rows': (_row('ink'), _row('accent')), 'shape': 'price'},
82
- ('info', 'doodle'): {'rows': (_row('paper', ('ink', .05), shadow='hard:accent'), _row('paper', ('ink', .1)))},
83
- ('info', 'callout'): {'rows': (_row('paper'), _row('accent')), 'shape': 'panel'},
84
- ('info', 'verdict'): {'rows': (_row('paper', ('ink', .12)), _row('paper', ('ink', .12))), 'extras': ('icon',)},
85
- ('info', 'name'): {'rows': (_row('accent', track=.04, shadow='deep'), _row('paper', shadow='deep')),
86
- 'extras': ('underline',), 'row_gap': .2},
87
- ('info', 'meme'): {'rows': (_row('paper', ('ink', .14)), _row('accent', ('ink', .14)))},
64
+ ("title", "outline"): {"rows": (_row("paper", ("ink", 0.13)), _row("accent", ("ink", 0.14))), "split": True},
65
+ ("title", "block"): {"rows": (_row("paper", ("ink", 0.05)), _row("ink")), "shape": "block"},
66
+ ("title", "serif"): {
67
+ "rows": (_row("paper", track=0.16, shadow="soft"), _row(("paper", 0.88), track=0.22, shadow="soft")),
68
+ "extras": ("rule_below",),
69
+ "detail_scale": 0.4,
70
+ "row_gap": 0.24,
71
+ },
72
+ ("title", "pill"): {"rows": (_row("paper"), _row(("paper", 0.92))), "shape": "pill"},
73
+ ("title", "doodle"): {
74
+ "rows": (_row("paper", ("ink", 0.05), shadow="hard:accent"), _row("paper", ("ink", 0.08))),
75
+ "extras": ("squiggle",),
76
+ "split": True,
77
+ "row_gap": 0.26,
78
+ },
79
+ ("title", "panel"): {"rows": (_row("paper"), _row("accent")), "shape": "panel"},
80
+ ("title", "bar"): {"rows": (_row("paper", ("ink", 0.1)), _row("paper", ("ink", 0.12))), "extras": ("highlight",)},
81
+ ("title", "rules"): {
82
+ "rows": (_row("accent", track=0.06, shadow="deep"), _row("paper", track=0.3, shadow="deep")),
83
+ "extras": ("rules",),
84
+ "detail_scale": 0.4,
85
+ },
86
+ ("title", "meme"): {"rows": (_row("paper", ("secondary", 0.15), ("ink", 0.09)), _row("accent", ("ink", 0.14)))},
87
+ ("tag", "shadow"): {"rows": (_row("paper", ("ink", 0.06), shadow="drop"),), "join": " | "},
88
+ ("tag", "tape"): {"rows": (_row("ink"),), "join": " ", "shape": "tape", "tilt": -2},
89
+ ("tag", "label"): {"rows": (_row("paper"),), "join": " ", "shape": "label"},
90
+ ("tag", "rules"): {"rows": (_row("paper", track=0.24, shadow="deep"),), "join": " ", "extras": ("rules",)},
91
+ ("tag", "dot"): {"rows": (_row("paper", ("ink", 0.1)),), "join": "|", "extras": ("dot",)},
92
+ ("tag", "keycap"): {
93
+ "rows": (_row("ink"), _row("paper")),
94
+ "inline": True,
95
+ "boxes": ("accent", ("ink", 0.82)),
96
+ "detail_scale": 1.0,
97
+ },
98
+ ("tag", "chip"): {"rows": (_row("ink"),), "join": " ", "shape": "chip"},
99
+ ("tag", "flag"): {"rows": (_row("ink"),), "join": "|", "shape": "flag"},
100
+ ("tag", "meme"): {"rows": (_row("ink"),), "join": " ", "shape": "memebox", "tilt": -2},
101
+ ("sticker", "sticker"): {"rows": (_row("accent", ("ink", 0.10), ("paper", 0.24)), _row("paper", ("ink", 0.14)))},
102
+ ("sticker", "burst"): {"rows": (_row("paper", ("ink", 0.1)), _row("ink")), "shape": "burst"},
103
+ ("sticker", "quiet"): {
104
+ "rows": (_row("paper", track=0.1, shadow="soft"), _row(("paper", 0.85), track=0.2, shadow="soft")),
105
+ "tilt": 0,
106
+ },
107
+ ("sticker", "bubble"): {"rows": (_row("ink"), _row(("ink", 0.7))), "shape": "bubble", "tilt": -3},
108
+ ("sticker", "doodle"): {
109
+ "rows": (_row("accent", ("paper", 0.1), shadow="soft"), _row("paper", shadow="soft")),
110
+ "extras": ("sparkles",),
111
+ },
112
+ ("sticker", "pill"): {"rows": (_row("ink"), _row(("ink", 0.75))), "shape": "pill", "tilt": 0},
113
+ ("sticker", "stamp"): {"rows": (_row("accent"), _row("accent")), "shape": "stamp", "tilt": -7},
114
+ ("sticker", "glow"): {
115
+ "rows": (_row("accent", track=0.08, shadow="glow"), _row("paper", track=0.16, shadow="deep")),
116
+ "tilt": 0,
117
+ },
118
+ ("sticker", "meme"): {
119
+ "rows": (_row("accent", ("ink", 0.11), ("paper", 0.2), shadow="hard:secondary"), _row("paper", ("ink", 0.14)))
120
+ },
121
+ ("info", "outline"): {"rows": (_row("accent", ("ink", 0.12)), _row("paper", ("ink", 0.12)))},
122
+ ("info", "label"): {"rows": (_row("paper"), _row("ink")), "boxes": ("ink", "accent")},
123
+ ("info", "quiet"): {
124
+ "rows": (_row("paper", track=0.06, shadow="soft"), _row(("paper", 0.82), shadow="soft")),
125
+ "extras": ("vline",),
126
+ },
127
+ ("info", "price"): {"rows": (_row("ink"), _row("accent")), "shape": "price"},
128
+ ("info", "doodle"): {"rows": (_row("paper", ("ink", 0.05), shadow="hard:accent"), _row("paper", ("ink", 0.1)))},
129
+ ("info", "callout"): {"rows": (_row("paper"), _row("accent")), "shape": "panel"},
130
+ ("info", "verdict"): {"rows": (_row("paper", ("ink", 0.12)), _row("paper", ("ink", 0.12))), "extras": ("icon",)},
131
+ ("info", "name"): {
132
+ "rows": (_row("accent", track=0.04, shadow="deep"), _row("paper", shadow="deep")),
133
+ "extras": ("underline",),
134
+ "row_gap": 0.2,
135
+ },
136
+ ("info", "meme"): {"rows": (_row("paper", ("ink", 0.14)), _row("accent", ("ink", 0.14)))},
88
137
  }
89
138
  # A verdict reads as a drawback when the label starts like one.
90
- CONS = ('缺點', '缺', '扣分', '不推', '踩雷')
139
+ CONS = ("缺點", "缺", "扣分", "不推", "踩雷")
91
140
 
92
141
 
93
142
  def is_creator(profile):
94
- return profile.get('presets', {}).get('appearance', {}).get('skin') == 'creator'
143
+ return profile.get("presets", {}).get("appearance", {}).get("skin") == "creator"
95
144
 
96
145
 
97
146
  def _appearance(profile):
98
- return profile['presets'].get('appearance', {})
147
+ return profile["presets"].get("appearance", {})
99
148
 
100
149
 
101
150
  def _look(profile):
102
- group = GROUPS[profile['component_id']]
103
- name = _appearance(profile).get('looks', {}).get(group, DEFAULT_LOOK[group])
151
+ group = GROUPS[profile["component_id"]]
152
+ name = _appearance(profile).get("looks", {}).get(group, DEFAULT_LOOK[group])
104
153
  if (group, name) not in LOOKS:
105
- raise TitleRenderError('program_component_unknown_look')
154
+ raise TitleRenderError("program_component_unknown_look")
106
155
  return group, name, LOOKS[group, name]
107
156
 
108
157
 
109
158
  def _motion(profile):
110
- return _appearance(profile).get('motion_style', 'pop')
159
+ return _appearance(profile).get("motion_style", "pop")
111
160
 
112
161
 
113
162
  def frames(profile):
114
- motion = profile['presets']['motion']
163
+ motion = profile["presets"]["motion"]
115
164
  appearance = _appearance(profile)
116
- hero = profile['component_id'] in HERO
117
- entry = appearance.get('hero_entry_frames', motion['entry_frames']) if hero else motion['entry_frames']
118
- exit_frames = appearance.get('hero_exit_frames', motion['exit_frames']) if hero else motion['exit_frames']
165
+ hero = profile["component_id"] in HERO
166
+ entry = appearance.get("hero_entry_frames", motion["entry_frames"]) if hero else motion["entry_frames"]
167
+ exit_frames = appearance.get("hero_exit_frames", motion["exit_frames"]) if hero else motion["exit_frames"]
119
168
  return max(1, entry), max(1, exit_frames)
120
169
 
121
170
 
122
- def _rgba(palette, name, alpha=1.):
171
+ def _rgba(palette, name, alpha=1.0):
123
172
  r, g, b, a = palette[name]
124
173
  return r, g, b, round(a * alpha)
125
174
 
@@ -127,7 +176,7 @@ def _rgba(palette, name, alpha=1.):
127
176
  def _color(palette, spec):
128
177
  if spec is None:
129
178
  return None
130
- name, alpha = (spec, 1.) if isinstance(spec, str) else spec
179
+ name, alpha = (spec, 1.0) if isinstance(spec, str) else spec
131
180
  return _rgba(palette, name, alpha)
132
181
 
133
182
 
@@ -146,9 +195,9 @@ def _draw_text(pen, x, y, value, font, fill, stroke=0, stroke_fill=None, track=0
146
195
  draw_style_text(pen, (x, y), value, font, fill, stroke, stroke_fill)
147
196
  return
148
197
  # Keep one baseline for the line; each glyph would otherwise sit on its own top edge.
149
- top = font.getbbox(value, anchor='ls')[1]
198
+ top = font.getbbox(value, anchor="ls")[1]
150
199
  for character in value:
151
- lift = 0 if character.isspace() else font.getbbox(character, anchor='ls')[1] - top
200
+ lift = 0 if character.isspace() else font.getbbox(character, anchor="ls")[1] - top
152
201
  draw_style_text(pen, (x, y + lift), character, font, fill, stroke, stroke_fill)
153
202
  x += styled_text_length(character, font) + font.size * track
154
203
 
@@ -157,10 +206,18 @@ def _shadow(font, shadow, palette):
157
206
  """A row shadow as (colour, offset, blur) in pixels, or None."""
158
207
  if not shadow:
159
208
  return None
160
- blur = round(font.size * {'glow': .16, 'deep': .1, 'soft': .07}[shadow]) if shadow in {'soft', 'deep', 'glow'} else 0
161
- offset = round(font.size * (.07 if shadow.startswith('hard') else .04 if shadow in {'soft', 'deep'} else .06))
162
- colour = {'drop': _rgba(palette, 'ink', .47), 'soft': _rgba(palette, 'ink', .6), 'deep': _rgba(palette, 'ink', .9),
163
- 'glow': _rgba(palette, 'accent', .75)}.get(shadow) or _rgba(palette, shadow.split(':')[1])
209
+ blur = (
210
+ round(font.size * {"glow": 0.16, "deep": 0.1, "soft": 0.07}[shadow])
211
+ if shadow in {"soft", "deep", "glow"}
212
+ else 0
213
+ )
214
+ offset = round(font.size * (0.07 if shadow.startswith("hard") else 0.04 if shadow in {"soft", "deep"} else 0.06))
215
+ colour = {
216
+ "drop": _rgba(palette, "ink", 0.47),
217
+ "soft": _rgba(palette, "ink", 0.6),
218
+ "deep": _rgba(palette, "ink", 0.9),
219
+ "glow": _rgba(palette, "accent", 0.75),
220
+ }.get(shadow) or _rgba(palette, shadow.split(":")[1])
164
221
  return colour, offset, blur
165
222
 
166
223
 
@@ -168,37 +225,37 @@ def _row_image(value, font, spec, palette, text=True):
168
225
  """One line of type with its outline, outer ring and shadow, plus the margin used.
169
226
 
170
227
  Without text the row keeps its size but stays empty, so shapes around it land where they would."""
171
- stroke_color, stroke_ratio = spec['stroke'] or (None, 0)
172
- outer_color, outer_ratio = spec['outer'] or (None, 0)
228
+ stroke_color, stroke_ratio = spec["stroke"] or (None, 0)
229
+ outer_color, outer_ratio = spec["outer"] or (None, 0)
173
230
  inner, ring = _stroke(font, stroke_ratio), _stroke(font, stroke_ratio) + _stroke(font, outer_ratio)
174
- shadow = _shadow(font, spec['shadow'], palette)
231
+ shadow = _shadow(font, spec["shadow"], palette)
175
232
  colour, offset, blur = shadow or (None, 0, 0)
176
233
  margin = ring + blur * 3 + offset + 2
177
- width, height = _length(value, font, spec['track']), font.size * 1.18
178
- image = Image.new('RGBA', (math.ceil(width + margin * 2), math.ceil(height + margin * 2)))
234
+ width, height = _length(value, font, spec["track"]), font.size * 1.18
235
+ image = Image.new("RGBA", (math.ceil(width + margin * 2), math.ceil(height + margin * 2)))
179
236
  if not text:
180
237
  return image, margin, width, height
181
238
  if shadow:
182
- layer = Image.new('RGBA', image.size)
183
- dx = 0 if spec['shadow'] == 'glow' else offset
184
- _draw_text(ImageDraw.Draw(layer), margin + dx, margin + dx, value, font, colour, ring, colour, spec['track'])
239
+ layer = Image.new("RGBA", image.size)
240
+ dx = 0 if spec["shadow"] == "glow" else offset
241
+ _draw_text(ImageDraw.Draw(layer), margin + dx, margin + dx, value, font, colour, ring, colour, spec["track"])
185
242
  if blur:
186
243
  layer = layer.filter(ImageFilter.GaussianBlur(blur))
187
244
  image.alpha_composite(layer)
188
245
  pen = ImageDraw.Draw(image)
189
- fill = _color(palette, spec['fill'])
246
+ fill = _color(palette, spec["fill"])
190
247
  if outer_color:
191
248
  outer = _color(palette, outer_color)
192
- _draw_text(pen, margin, margin, value, font, outer, ring, outer, spec['track'])
193
- _draw_text(pen, margin, margin, value, font, fill, inner, _color(palette, stroke_color), spec['track'])
249
+ _draw_text(pen, margin, margin, value, font, outer, ring, outer, spec["track"])
250
+ _draw_text(pen, margin, margin, value, font, fill, inner, _color(palette, stroke_color), spec["track"])
194
251
  return image, margin, width, height
195
252
 
196
253
 
197
254
  def _texts(item, look, group):
198
- primary, _, detail = item.text.partition('\n')
199
- if 'join' in look:
200
- return [primary + (look['join'] + detail if detail else '')], False
201
- rows = primary.split('・', 1) if look.get('split') and '・' in primary else [primary]
255
+ primary, _, detail = item.text.partition("\n")
256
+ if "join" in look:
257
+ return [primary + (look["join"] + detail if detail else "")], False
258
+ rows = primary.split("・", 1) if look.get("split") and "・" in primary else [primary]
202
259
  return [r for r in rows if r] + ([detail] if detail else []), bool(detail)
203
260
 
204
261
 
@@ -206,41 +263,45 @@ def _assemble(item, profile, font_path, size, look, group, text=True):
206
263
  """Lay rows out (stacked or side by side) and return the canvas, each row's text box and its type.
207
264
 
208
265
  A row's type is (text, font, spec, origin): origin is where the text is drawn on the canvas."""
209
- palette = profile['presets']['palette']
210
- kind = profile['component_id']
266
+ palette = profile["presets"]["palette"]
267
+ kind = profile["component_id"]
211
268
  texts, has_detail = _texts(item, look, group)
212
269
  font = load_style_font(font_path, size, profile)
213
- default_scale = .62 if kind in {'program_title', 'headline'} else .7
214
- small = load_style_font(font_path, max(10, round(size * look.get('detail_scale', default_scale))), profile, role='detail')
215
- primary_spec, detail_spec = look['rows'][0], look['rows'][-1]
270
+ default_scale = 0.62 if kind in {"program_title", "headline"} else 0.7
271
+ small = load_style_font(
272
+ font_path, max(10, round(size * look.get("detail_scale", default_scale))), profile, role="detail"
273
+ )
274
+ primary_spec, detail_spec = look["rows"][0], look["rows"][-1]
216
275
  rows, types = [], []
217
276
  for index, value in enumerate(texts):
218
277
  is_detail = has_detail and index == len(texts) - 1
219
278
  face, spec = (small, detail_spec) if is_detail else (font, primary_spec)
220
279
  rows.append(_row_image(value, face, spec, palette, text))
221
280
  types.append((value, face, spec))
222
- boxes = look.get('boxes')
223
- pad_x, pad_y = (round(size * .34), round(size * .12)) if boxes else (0, 0)
224
- gap = (pad_x * 2 + round(size * .2)) if look.get('inline') else pad_y * 2 + round(size * look.get('row_gap', 0))
281
+ boxes = look.get("boxes")
282
+ pad_x, pad_y = (round(size * 0.34), round(size * 0.12)) if boxes else (0, 0)
283
+ gap = (pad_x * 2 + round(size * 0.2)) if look.get("inline") else pad_y * 2 + round(size * look.get("row_gap", 0))
225
284
  outer = max(margin for _, margin, _, _ in rows)
226
- if look.get('inline'):
285
+ if look.get("inline"):
227
286
  width = sum(w for _, _, w, _ in rows) + gap * (len(rows) - 1)
228
287
  height = max(h for _, _, _, h in rows)
229
288
  else:
230
289
  width = max(w for _, _, w, _ in rows)
231
290
  height = sum(h for _, _, _, h in rows) + gap * (len(rows) - 1)
232
291
  edge = outer + max(pad_x, pad_y)
233
- canvas = Image.new('RGBA', (math.ceil(width + edge * 2), math.ceil(height + edge * 2)))
292
+ canvas = Image.new("RGBA", (math.ceil(width + edge * 2), math.ceil(height + edge * 2)))
234
293
  rects, cursor = [], edge
235
294
  for image, margin, w, h in rows:
236
- x, y = (cursor, edge + (height - h) / 2) if look.get('inline') else (edge, cursor)
295
+ x, y = (cursor, edge + (height - h) / 2) if look.get("inline") else (edge, cursor)
237
296
  rects.append((x, y, x + w, y + h))
238
- cursor += (w if look.get('inline') else h) + gap
297
+ cursor += (w if look.get("inline") else h) + gap
239
298
  if boxes:
240
299
  pen = ImageDraw.Draw(canvas)
241
300
  for (x0, y0, x1, y1), colour, (_, _, _, h) in zip(rects, boxes, rows):
242
- radius = round(h * (.22 if look.get('inline') else .08))
243
- pen.rounded_rectangle((x0 - pad_x, y0 - pad_y, x1 + pad_x, y1 + pad_y * .4), radius, fill=_color(palette, colour))
301
+ radius = round(h * (0.22 if look.get("inline") else 0.08))
302
+ pen.rounded_rectangle(
303
+ (x0 - pad_x, y0 - pad_y, x1 + pad_x, y1 + pad_y * 0.4), radius, fill=_color(palette, colour)
304
+ )
244
305
  placed = []
245
306
  for (image, margin, _, _), (x, y, _, _), row in zip(rows, rects, types):
246
307
  canvas.alpha_composite(image, (round(x - margin), round(y - margin)))
@@ -253,169 +314,226 @@ def _shape(canvas, rects, size, look, palette, has_detail=False, con=False, crop
253
314
 
254
315
  Returns the image, where the canvas origin landed on it, and the crop used; pass that crop back
255
316
  to cut a second drawing of the same component (one without type) identically."""
256
- name = look.get('shape')
257
- extras = look.get('extras', ())
317
+ name = look.get("shape")
318
+ extras = look.get("extras", ())
258
319
  if not name and not extras:
259
320
  return canvas, (0, 0), None
260
321
  grow = round(size * 1.1)
261
- out = Image.new('RGBA', (canvas.width + grow * 2, canvas.height + grow * 2))
322
+ out = Image.new("RGBA", (canvas.width + grow * 2, canvas.height + grow * 2))
262
323
  pen = ImageDraw.Draw(out)
263
324
  rects = [(x0 + grow, y0 + grow, x1 + grow, y1 + grow) for x0, y0, x1, y1 in rects]
264
325
  x0, y0 = min(r[0] for r in rects), min(r[1] for r in rects)
265
326
  x1, y1 = max(r[2] for r in rects), max(r[3] for r in rects)
266
- paper, ink, accent = (_rgba(palette, n) for n in ('paper', 'ink', 'accent'))
327
+ paper, ink, accent = (_rgba(palette, n) for n in ("paper", "ink", "accent"))
267
328
  s = size
268
- if name == 'block':
269
- skew = (y1 - y0) * .2
270
- bx0, by0, bx1, by1 = x0 - s * .3, y0 - s * .04, x1 + s * .3 + skew, y1 + s * .02
271
- poly = lambda dx, dy: [(bx0 + skew + dx, by0 + dy), (bx1 + dx, by0 + dy), (bx1 - skew + dx, by1 + dy), (bx0 + dx, by1 + dy)]
272
- pen.polygon(poly(s * .09, s * .09), fill=ink)
329
+ if name == "block":
330
+ skew = (y1 - y0) * 0.2
331
+ bx0, by0, bx1, by1 = x0 - s * 0.3, y0 - s * 0.04, x1 + s * 0.3 + skew, y1 + s * 0.02
332
+ poly = lambda dx, dy: [
333
+ (bx0 + skew + dx, by0 + dy),
334
+ (bx1 + dx, by0 + dy),
335
+ (bx1 - skew + dx, by1 + dy),
336
+ (bx0 + dx, by1 + dy),
337
+ ]
338
+ pen.polygon(poly(s * 0.09, s * 0.09), fill=ink)
273
339
  pen.polygon(poly(0, 0), fill=accent)
274
- elif name == 'pill':
275
- box = (x0 - s * .42, y0 - s * .06, x1 + s * .42, y1 + s * .02)
340
+ elif name == "pill":
341
+ box = (x0 - s * 0.42, y0 - s * 0.06, x1 + s * 0.42, y1 + s * 0.02)
276
342
  radius = (box[3] - box[1]) / 2
277
- pen.rounded_rectangle(tuple(v + s * .07 for v in box), radius, fill=ink)
343
+ pen.rounded_rectangle(tuple(v + s * 0.07 for v in box), radius, fill=ink)
278
344
  pen.rounded_rectangle(box, radius, fill=accent)
279
- elif name == 'panel':
280
- box = (x0 - s * .55, y0 - s * .16, x1 + s * .45, y1 + s * .08)
281
- pen.rounded_rectangle(box, round(s * .22), fill=_rgba(palette, 'ink', .8))
282
- pen.rounded_rectangle((box[0] + s * .16, box[1] + s * .2, box[0] + s * .26, box[3] - s * .2), round(s * .05), fill=accent)
283
- elif name == 'tape':
284
- bx0, by0, bx1, by1 = x0 - s * .4, y0 - s * .08, x1 + s * .4, y1 + s * .02
285
- teeth, depth = 5, s * .12
345
+ elif name == "panel":
346
+ box = (x0 - s * 0.55, y0 - s * 0.16, x1 + s * 0.45, y1 + s * 0.08)
347
+ pen.rounded_rectangle(box, round(s * 0.22), fill=_rgba(palette, "ink", 0.8))
348
+ pen.rounded_rectangle(
349
+ (box[0] + s * 0.16, box[1] + s * 0.2, box[0] + s * 0.26, box[3] - s * 0.2), round(s * 0.05), fill=accent
350
+ )
351
+ elif name == "tape":
352
+ bx0, by0, bx1, by1 = x0 - s * 0.4, y0 - s * 0.08, x1 + s * 0.4, y1 + s * 0.02
353
+ teeth, depth = 5, s * 0.12
286
354
  left = [(bx0 + (depth if n % 2 else 0), by0 + (by1 - by0) * n / teeth) for n in range(teeth + 1)]
287
355
  right = [(bx1 - (depth if n % 2 else 0), by1 - (by1 - by0) * n / teeth) for n in range(teeth + 1)]
288
- pen.polygon(left + right, fill=_rgba(palette, 'paper', .88))
289
- elif name == 'label':
290
- box = (x0 - s * .55, y0 - s * .1, x1 + s * .35, y1 + s * .02)
356
+ pen.polygon(left + right, fill=_rgba(palette, "paper", 0.88))
357
+ elif name == "label":
358
+ box = (x0 - s * 0.55, y0 - s * 0.1, x1 + s * 0.35, y1 + s * 0.02)
291
359
  pen.rectangle(box, fill=ink)
292
- pen.rectangle((box[0] + s * .16, box[1] + s * .32, box[0] + s * .34, box[3] - s * .3), fill=accent)
293
- elif name == 'chip':
294
- box = (x0 - s * .55, y0 - s * .1, x1 + s * .35, y1 + s * .02)
295
- pen.rounded_rectangle(box, round(s * .25), fill=paper)
296
- pen.rounded_rectangle((box[0] + s * .16, box[1] + s * .28, box[0] + s * .3, box[3] - s * .26), round(s * .07), fill=accent)
297
- elif name == 'flag':
298
- bx0, by0, bx1, by1 = x0 - s * .35, y0 - s * .1, x1 + s * .7, y1 + s * .02
299
- pen.polygon([(bx0, by0), (bx1, by0), (bx1 - s * .32, (by0 + by1) / 2), (bx1, by1), (bx0, by1)], fill=accent)
300
- elif name == 'memebox':
301
- pen.rectangle((x0 - s * .22, y0 - s * .02, x1 + s * .22, y1 - s * .02), fill=accent)
302
- elif name == 'burst':
303
- cx, cy = (x0 + x1) / 2, (y0 + y1) / 2 - s * .04
304
- rx, ry = (x1 - x0) / 2 + s * .62, (y1 - y0) / 2 + s * .5
360
+ pen.rectangle((box[0] + s * 0.16, box[1] + s * 0.32, box[0] + s * 0.34, box[3] - s * 0.3), fill=accent)
361
+ elif name == "chip":
362
+ box = (x0 - s * 0.55, y0 - s * 0.1, x1 + s * 0.35, y1 + s * 0.02)
363
+ pen.rounded_rectangle(box, round(s * 0.25), fill=paper)
364
+ pen.rounded_rectangle(
365
+ (box[0] + s * 0.16, box[1] + s * 0.28, box[0] + s * 0.3, box[3] - s * 0.26), round(s * 0.07), fill=accent
366
+ )
367
+ elif name == "flag":
368
+ bx0, by0, bx1, by1 = x0 - s * 0.35, y0 - s * 0.1, x1 + s * 0.7, y1 + s * 0.02
369
+ pen.polygon([(bx0, by0), (bx1, by0), (bx1 - s * 0.32, (by0 + by1) / 2), (bx1, by1), (bx0, by1)], fill=accent)
370
+ elif name == "memebox":
371
+ pen.rectangle((x0 - s * 0.22, y0 - s * 0.02, x1 + s * 0.22, y1 - s * 0.02), fill=accent)
372
+ elif name == "burst":
373
+ cx, cy = (x0 + x1) / 2, (y0 + y1) / 2 - s * 0.04
374
+ rx, ry = (x1 - x0) / 2 + s * 0.62, (y1 - y0) / 2 + s * 0.5
375
+
305
376
  def star(scale):
306
377
  points = []
307
378
  for n in range(28):
308
- r = (1 if n % 2 == 0 else .76 + .06 * math.sin(n * 1.7)) * scale
379
+ r = (1 if n % 2 == 0 else 0.76 + 0.06 * math.sin(n * 1.7)) * scale
309
380
  a = -math.pi / 2 + math.pi * n / 14
310
381
  points.append((cx + rx * r * math.cos(a), cy + ry * r * math.sin(a)))
311
382
  return points
383
+
312
384
  pen.polygon(star(1.07), fill=ink)
313
- pen.polygon(star(1.), fill=accent)
314
- elif name == 'bubble':
315
- box = (x0 - s * .45, y0 - s * .14, x1 + s * .45, y1 + s * .06)
316
- line = s * .07
317
- tail = [(box[0] + s * .5, box[3] - s * .1), (box[0] + s * .1, box[3] + s * .5), (box[0] + s * 1.05, box[3] - s * .1)]
318
- radius = round((box[3] - box[1]) * .42)
385
+ pen.polygon(star(1.0), fill=accent)
386
+ elif name == "bubble":
387
+ box = (x0 - s * 0.45, y0 - s * 0.14, x1 + s * 0.45, y1 + s * 0.06)
388
+ line = s * 0.07
389
+ tail = [
390
+ (box[0] + s * 0.5, box[3] - s * 0.1),
391
+ (box[0] + s * 0.1, box[3] + s * 0.5),
392
+ (box[0] + s * 1.05, box[3] - s * 0.1),
393
+ ]
394
+ radius = round((box[3] - box[1]) * 0.42)
319
395
  pen.rounded_rectangle(tuple(v + d for v, d in zip(box, (-line, -line, line, line))), radius + line, fill=ink)
320
- pen.polygon([(tail[0][0] - line, tail[0][1]), (tail[1][0] - line * .8, tail[1][1] + line * 1.4), (tail[2][0] + line, tail[2][1])], fill=ink)
396
+ pen.polygon(
397
+ [
398
+ (tail[0][0] - line, tail[0][1]),
399
+ (tail[1][0] - line * 0.8, tail[1][1] + line * 1.4),
400
+ (tail[2][0] + line, tail[2][1]),
401
+ ],
402
+ fill=ink,
403
+ )
321
404
  pen.rounded_rectangle(box, radius, fill=paper)
322
405
  pen.polygon(tail, fill=paper)
323
- elif name == 'stamp':
324
- pen.rectangle((x0 - s * .38, y0 - s * .16, x1 + s * .38, y1 + s * .08), outline=accent, width=max(2, round(s * .08)))
325
- pen.rectangle((x0 - s * .24, y0 - s * .05, x1 + s * .24, y1 - s * .03), outline=accent, width=max(1, round(s * .03)))
326
- elif name == 'price':
327
- bx0, by0, bx1, by1 = x0 - s * .3, y0 - s * .12, x1 + s * .4, y1 + s * .04
328
- tip = bx0 - s * .5
406
+ elif name == "stamp":
407
+ pen.rectangle(
408
+ (x0 - s * 0.38, y0 - s * 0.16, x1 + s * 0.38, y1 + s * 0.08), outline=accent, width=max(2, round(s * 0.08))
409
+ )
410
+ pen.rectangle(
411
+ (x0 - s * 0.24, y0 - s * 0.05, x1 + s * 0.24, y1 - s * 0.03), outline=accent, width=max(1, round(s * 0.03))
412
+ )
413
+ elif name == "price":
414
+ bx0, by0, bx1, by1 = x0 - s * 0.3, y0 - s * 0.12, x1 + s * 0.4, y1 + s * 0.04
415
+ tip = bx0 - s * 0.5
329
416
  outline = [(tip, (by0 + by1) / 2), (bx0, by0), (bx1, by0), (bx1, by1), (bx0, by1)]
330
- line = s * .05
331
- pen.polygon([(tip - line * 1.5, (by0 + by1) / 2), (bx0 - line * .4, by0 - line), (bx1 + line, by0 - line),
332
- (bx1 + line, by1 + line), (bx0 - line * .4, by1 + line)], fill=ink)
417
+ line = s * 0.05
418
+ pen.polygon(
419
+ [
420
+ (tip - line * 1.5, (by0 + by1) / 2),
421
+ (bx0 - line * 0.4, by0 - line),
422
+ (bx1 + line, by0 - line),
423
+ (bx1 + line, by1 + line),
424
+ (bx0 - line * 0.4, by1 + line),
425
+ ],
426
+ fill=ink,
427
+ )
333
428
  pen.polygon(outline, fill=paper)
334
- hole = (bx0 - s * .12, (by0 + by1) / 2)
335
- pen.ellipse((hole[0] - s * .08, hole[1] - s * .08, hole[0] + s * .08, hole[1] + s * .08), fill=ink)
429
+ hole = (bx0 - s * 0.12, (by0 + by1) / 2)
430
+ pen.ellipse((hole[0] - s * 0.08, hole[1] - s * 0.08, hole[0] + s * 0.08, hole[1] + s * 0.08), fill=ink)
336
431
  out.alpha_composite(canvas, (grow, grow))
337
432
  _extras(pen, rects, extras, s, palette, out, has_detail, con)
338
- box = crop or out.getchannel('A').getbbox()
433
+ box = crop or out.getchannel("A").getbbox()
339
434
  if not box:
340
435
  return out, (grow, grow), None
341
436
  return out.crop(box), (grow - box[0], grow - box[1]), box
342
437
 
343
438
 
344
439
  def _extras(pen, rects, extras, s, palette, out, has_detail, con):
345
- paper, ink, accent = (_rgba(palette, n) for n in ('paper', 'ink', 'accent'))
440
+ paper, ink, accent = (_rgba(palette, n) for n in ("paper", "ink", "accent"))
346
441
  first, last = rects[0], rects[-1]
347
442
  titles = rects[:-1] if has_detail else rects
348
- x0, y0, x1, y1 = min(r[0] for r in rects), min(r[1] for r in rects), max(r[2] for r in rects), max(r[3] for r in rects)
443
+ x0, y0, x1, y1 = (
444
+ min(r[0] for r in rects),
445
+ min(r[1] for r in rects),
446
+ max(r[2] for r in rects),
447
+ max(r[3] for r in rects),
448
+ )
349
449
  for extra in extras:
350
- if extra == 'rule_below' and len(rects) > 1:
351
- y = first[3] + s * .02
352
- pen.line((x0 + s * .04, y, x0 + (x1 - x0) * .3, y), fill=paper, width=max(1, round(s * .03)))
353
- elif extra == 'rules':
450
+ if extra == "rule_below" and len(rects) > 1:
451
+ y = first[3] + s * 0.02
452
+ pen.line((x0 + s * 0.04, y, x0 + (x1 - x0) * 0.3, y), fill=paper, width=max(1, round(s * 0.03)))
453
+ elif extra == "rules":
354
454
  r = last
355
- y = (r[1] + r[3]) / 2 + s * .02
356
- length, gap = s * .9, s * .3
357
- width = max(1, round(s * .025))
455
+ y = (r[1] + r[3]) / 2 + s * 0.02
456
+ length, gap = s * 0.9, s * 0.3
457
+ width = max(1, round(s * 0.025))
358
458
  colour = accent if len(rects) > 1 else paper
359
459
  pen.line((r[0] - gap - length, y, r[0] - gap, y), fill=colour, width=width)
360
460
  pen.line((r[2] + gap, y, r[2] + gap + length, y), fill=colour, width=width)
361
- elif extra == 'highlight':
461
+ elif extra == "highlight":
362
462
  # A marker stroke behind the lower half of each title row.
363
- layer = Image.new('RGBA', out.size)
463
+ layer = Image.new("RGBA", out.size)
364
464
  mark = ImageDraw.Draw(layer)
365
465
  for r in titles:
366
466
  h = r[3] - r[1]
367
- mark.rectangle((r[0] - s * .12, r[1] + h * .52, r[2] + s * .12, r[1] + h * .95), fill=accent)
467
+ mark.rectangle((r[0] - s * 0.12, r[1] + h * 0.52, r[2] + s * 0.12, r[1] + h * 0.95), fill=accent)
368
468
  layer.alpha_composite(out)
369
469
  out.paste(layer)
370
- elif extra == 'squiggle':
470
+ elif extra == "squiggle":
371
471
  target = titles[-1]
372
- y, amplitude, period = target[3] + s * .02, s * .07, s * .55
373
- points = [(target[0] + t, y + amplitude * math.sin(t / period * 2 * math.pi))
374
- for t in range(0, max(2, round(target[2] - target[0])), 3)]
375
- pen.line(points, fill=accent, width=max(2, round(s * .08)), joint='curve')
376
- elif extra == 'underline':
377
- y = first[3] + s * .02
378
- pen.line((first[0], y, first[2], y), fill=accent, width=max(1, round(s * .04)))
379
- elif extra == 'dot':
380
- cx, cy, r = first[0] - s * .42, (first[1] + first[3]) / 2 + s * .02, s * .17
472
+ y, amplitude, period = target[3] + s * 0.02, s * 0.07, s * 0.55
473
+ points = [
474
+ (target[0] + t, y + amplitude * math.sin(t / period * 2 * math.pi))
475
+ for t in range(0, max(2, round(target[2] - target[0])), 3)
476
+ ]
477
+ pen.line(points, fill=accent, width=max(2, round(s * 0.08)), joint="curve")
478
+ elif extra == "underline":
479
+ y = first[3] + s * 0.02
480
+ pen.line((first[0], y, first[2], y), fill=accent, width=max(1, round(s * 0.04)))
481
+ elif extra == "dot":
482
+ cx, cy, r = first[0] - s * 0.42, (first[1] + first[3]) / 2 + s * 0.02, s * 0.17
381
483
  pen.ellipse((cx - r, cy - r, cx + r, cy + r), fill=accent)
382
- elif extra == 'vline':
383
- x = x0 - s * .35
384
- pen.line((x, y0 + s * .12, x, y1 - s * .05), fill=paper, width=max(1, round(s * .04)))
385
- elif extra == 'sparkles':
386
- for (cx, cy), angles in (((x1 + s * .05, y0 + s * .05), (-75, -40, -5)), ((x0 - s * .05, y1 - s * .1), (105, 140, 175))):
484
+ elif extra == "vline":
485
+ x = x0 - s * 0.35
486
+ pen.line((x, y0 + s * 0.12, x, y1 - s * 0.05), fill=paper, width=max(1, round(s * 0.04)))
487
+ elif extra == "sparkles":
488
+ for (cx, cy), angles in (
489
+ ((x1 + s * 0.05, y0 + s * 0.05), (-75, -40, -5)),
490
+ ((x0 - s * 0.05, y1 - s * 0.1), (105, 140, 175)),
491
+ ):
387
492
  for angle in angles:
388
493
  a = math.radians(angle)
389
- start = (cx + s * .18 * math.cos(a), cy + s * .18 * math.sin(a))
390
- end = (cx + s * .5 * math.cos(a), cy + s * .5 * math.sin(a))
391
- _brush(pen, [start, end], s * .045, ink)
392
- _brush(pen, [start, end], s * .022, paper)
393
- elif extra == 'icon':
494
+ start = (cx + s * 0.18 * math.cos(a), cy + s * 0.18 * math.sin(a))
495
+ end = (cx + s * 0.5 * math.cos(a), cy + s * 0.5 * math.sin(a))
496
+ _brush(pen, [start, end], s * 0.045, ink)
497
+ _brush(pen, [start, end], s * 0.022, paper)
498
+ elif extra == "icon":
394
499
  # A check for a strength, a cross for a drawback.
395
500
  r = first
396
501
  h = r[3] - r[1]
397
- box = (r[0] - h * 1.05, r[1] + h * .04, r[0] - h * .2, r[1] + h * .89)
398
- pen.rounded_rectangle(box, round(h * .16), fill=_rgba(palette, 'secondary' if con else 'accent'), outline=ink,
399
- width=max(1, round(s * .05)))
502
+ box = (r[0] - h * 1.05, r[1] + h * 0.04, r[0] - h * 0.2, r[1] + h * 0.89)
503
+ pen.rounded_rectangle(
504
+ box,
505
+ round(h * 0.16),
506
+ fill=_rgba(palette, "secondary" if con else "accent"),
507
+ outline=ink,
508
+ width=max(1, round(s * 0.05)),
509
+ )
400
510
  bx0, by0, bx1, by1 = box
401
- w = max(2, round(s * .11))
511
+ w = max(2, round(s * 0.11))
402
512
  if con:
403
- inset = (bx1 - bx0) * .28
513
+ inset = (bx1 - bx0) * 0.28
404
514
  pen.line((bx0 + inset, by0 + inset, bx1 - inset, by1 - inset), fill=paper, width=w)
405
515
  pen.line((bx0 + inset, by1 - inset, bx1 - inset, by0 + inset), fill=paper, width=w)
406
516
  else:
407
- pen.line([(bx0 + (bx1 - bx0) * .24, by0 + (by1 - by0) * .52), (bx0 + (bx1 - bx0) * .43, by0 + (by1 - by0) * .72),
408
- (bx0 + (bx1 - bx0) * .78, by0 + (by1 - by0) * .3)], fill=paper, width=w, joint='curve')
517
+ pen.line(
518
+ [
519
+ (bx0 + (bx1 - bx0) * 0.24, by0 + (by1 - by0) * 0.52),
520
+ (bx0 + (bx1 - bx0) * 0.43, by0 + (by1 - by0) * 0.72),
521
+ (bx0 + (bx1 - bx0) * 0.78, by0 + (by1 - by0) * 0.3),
522
+ ],
523
+ fill=paper,
524
+ width=w,
525
+ joint="curve",
526
+ )
409
527
 
410
528
 
411
529
  def _compose(item, profile, font_path, size, text=True, crop=None):
412
530
  """The component drawn on its own canvas, its look, its rows' type and where the canvas origin landed."""
413
531
  group, name, look = _look(profile)
414
- if (group, name) == ('sticker', 'sticker') and profile['component_id'] == 'burst':
415
- look = {'rows': (_row('paper', ('accent', .12), ('ink', .22)), _row('paper', ('ink', .14)))}
532
+ if (group, name) == ("sticker", "sticker") and profile["component_id"] == "burst":
533
+ look = {"rows": (_row("paper", ("accent", 0.12), ("ink", 0.22)), _row("paper", ("ink", 0.14)))}
416
534
  canvas, rects, font_size, has_detail, rows = _assemble(item, profile, font_path, size, look, group, text)
417
535
  con = item.text.lstrip().startswith(CONS)
418
- image, origin, box = _shape(canvas, rects, font_size, look, profile['presets']['palette'], has_detail, con, crop)
536
+ image, origin, box = _shape(canvas, rects, font_size, look, profile["presets"]["palette"], has_detail, con, crop)
419
537
  return image, look, rows, origin, box
420
538
 
421
539
 
@@ -425,7 +543,7 @@ def _content(item, profile, font_path, size):
425
543
 
426
544
 
427
545
  def _tilted(image, kind, look):
428
- angle = look.get('tilt', TILT.get(kind, 0) if GROUPS[kind] == 'sticker' else 0)
546
+ angle = look.get("tilt", TILT.get(kind, 0) if GROUPS[kind] == "sticker" else 0)
429
547
  return image.rotate(angle, resample=Image.Resampling.BICUBIC, expand=True) if angle else image
430
548
 
431
549
 
@@ -435,44 +553,44 @@ def _base(timeline):
435
553
 
436
554
 
437
555
  def _size(timeline, profile, scale):
438
- kind = profile['component_id']
556
+ kind = profile["component_id"]
439
557
  appearance = _appearance(profile)
440
558
  # type_scale enlarges every component (short-form video); hero_scale only the big ones.
441
- factor = appearance.get('type_scale', 1.) * (appearance.get('hero_scale', 1.) if kind in HERO else 1.)
559
+ factor = appearance.get("type_scale", 1.0) * (appearance.get("hero_scale", 1.0) if kind in HERO else 1.0)
442
560
  return max(11, round(_base(timeline) * SIZES[kind] * factor * scale))
443
561
 
444
562
 
445
563
  def _pops(profile):
446
- return profile['component_id'] in POP and _motion(profile) in {'pop', 'punch', 'bounce', 'stamp'}
564
+ return profile["component_id"] in POP and _motion(profile) in {"pop", "punch", "bounce", "stamp"}
447
565
 
448
566
 
449
567
  def _fit(font_path, timeline, item, profile):
450
- kind = profile['component_id']
568
+ kind = profile["component_id"]
451
569
  w, h = timeline.width, timeline.height
452
- x, y = round(w * profile['x']), round(h * profile['y'])
453
- limit = min(w * (.86 if kind in HERO else .62), w * .95 - x)
454
- scale = 1.
570
+ x, y = round(w * profile["x"]), round(h * profile["y"])
571
+ limit = min(w * (0.86 if kind in HERO else 0.62), w * 0.95 - x)
572
+ scale = 1.0
455
573
  while True:
456
574
  image, look = _content(item, profile, font_path, _size(timeline, profile, scale))
457
575
  content = _tilted(image, kind, look)
458
- slack = POP_SLACK if _pops(profile) else 1.
459
- rise = 0 if _pops(profile) else _base(timeline) * .012
576
+ slack = POP_SLACK if _pops(profile) else 1.0
577
+ rise = 0 if _pops(profile) else _base(timeline) * 0.012
460
578
  width, height = math.ceil(content.width * slack), math.ceil(content.height * slack + rise)
461
- if (width <= limit and y + height <= h * .77) or scale <= .6:
579
+ if (width <= limit and y + height <= h * 0.77) or scale <= 0.6:
462
580
  break
463
- scale -= .05
464
- if width > limit or y + height > h * .77:
465
- raise TitleRenderError('program_component_overflow')
581
+ scale -= 0.05
582
+ if width > limit or y + height > h * 0.77:
583
+ raise TitleRenderError("program_component_overflow")
466
584
  return (x, y, x + width, y + height), content, scale
467
585
 
468
586
 
469
587
  def layout(draw, font_path, timeline, item, profile):
470
588
  box, _, scale = _fit(font_path, timeline, item, profile)
471
- pad = max(6, round(_base(timeline) * .016))
589
+ pad = max(6, round(_base(timeline) * 0.016))
472
590
  return box, load_style_font(font_path, _size(timeline, profile, scale), profile), pad
473
591
 
474
592
 
475
- _BUNDLED_FONTS = Path(__file__).parent / 'fonts'
593
+ _BUNDLED_FONTS = Path(__file__).parent / "fonts"
476
594
 
477
595
 
478
596
  def editable(font_path, timeline, item, profile):
@@ -482,52 +600,71 @@ def editable(font_path, timeline, item, profile):
482
600
  this. Each row gives its text, face, pixel size, tracking, fill, shadow and the frame point
483
601
  where its baseline starts. None when the type cannot be rebuilt faithfully elsewhere: a
484
602
  tilted component, an outlined row, or a face that only Clipen carries."""
485
- kind = profile['component_id']
603
+ kind = profile["component_id"]
486
604
  group, _, look = _look(profile)
487
- if look.get('tilt', TILT.get(kind, 0) if group == 'sticker' else 0):
605
+ if look.get("tilt", TILT.get(kind, 0) if group == "sticker" else 0):
488
606
  return None
489
607
  (x, y, right, bottom), _, scale = _fit(font_path, timeline, item, profile)
490
608
  size = _size(timeline, profile, scale)
491
609
  image, look, rows, origin, box = _compose(item, profile, font_path, size)
492
- if any(spec['stroke'] or spec['outer'] or Path(getattr(face, 'path', '')).parent == _BUNDLED_FONTS
493
- for _, face, spec, _ in rows):
610
+ if any(
611
+ spec["stroke"] or spec["outer"] or Path(getattr(face, "path", "")).parent == _BUNDLED_FONTS
612
+ for _, face, spec, _ in rows
613
+ ):
494
614
  return None
495
615
  bare, *_ = _compose(item, profile, font_path, size, text=False, crop=box)
496
616
  # Where draw_graphic rests the component once its entrance has finished.
497
- left, top = (x + ((right - x) - image.width) // 2, y + ((bottom - y) - image.height) // 2) if _pops(profile) else (x, y)
498
- picture = Image.new('RGBA', (timeline.width, timeline.height))
617
+ left, top = (
618
+ (x + ((right - x) - image.width) // 2, y + ((bottom - y) - image.height) // 2) if _pops(profile) else (x, y)
619
+ )
620
+ picture = Image.new("RGBA", (timeline.width, timeline.height))
499
621
  picture.alpha_composite(bare, (max(0, left), max(0, top)))
500
- palette = profile['presets']['palette']
622
+ palette = profile["presets"]["palette"]
501
623
  types = []
502
624
  for value, face, spec, (ox, oy) in rows:
503
625
  family, style = face.getname()
504
- shadow = _shadow(face, spec['shadow'], palette)
505
- types.append({'text': value, 'family': family, 'style': style, 'size': face.size, 'track': spec['track'],
506
- 'fill': list(_color(palette, spec['fill'])),
507
- 'x': left + origin[0] + ox, 'baseline': top + origin[1] + oy - face.getbbox(value, anchor='ls')[1],
508
- 'shadow': shadow and {'colour': list(shadow[0]), 'offset': 0 if spec['shadow'] == 'glow' else shadow[1],
509
- 'blur': shadow[2]}})
510
- return {'rows': types, 'picture': picture if picture.getbbox() else None}
626
+ shadow = _shadow(face, spec["shadow"], palette)
627
+ types.append(
628
+ {
629
+ "text": value,
630
+ "family": family,
631
+ "style": style,
632
+ "size": face.size,
633
+ "track": spec["track"],
634
+ "fill": list(_color(palette, spec["fill"])),
635
+ "x": left + origin[0] + ox,
636
+ "baseline": top + origin[1] + oy - face.getbbox(value, anchor="ls")[1],
637
+ "shadow": shadow
638
+ and {
639
+ "colour": list(shadow[0]),
640
+ "offset": 0 if spec["shadow"] == "glow" else shadow[1],
641
+ "blur": shadow[2],
642
+ },
643
+ }
644
+ )
645
+ return {"rows": types, "picture": picture if picture.getbbox() else None}
511
646
 
512
647
 
513
648
  def _pop(progress):
514
649
  """Settle from 70% to full size with an overshoot capped by the footprint slack."""
515
650
  if progress >= 1:
516
- return 1.
651
+ return 1.0
517
652
  c1 = 1.70158
518
653
  t = progress - 1
519
- back = 1 + (c1 + 1) * t ** 3 + c1 * t ** 2
520
- return max(.7, min(POP_SLACK, .7 + .3 * back))
654
+ back = 1 + (c1 + 1) * t**3 + c1 * t**2
655
+ return max(0.7, min(POP_SLACK, 0.7 + 0.3 * back))
521
656
 
522
657
 
523
658
  def _scaled(content, sx, sy):
524
- return content.resize((max(1, round(content.width * sx)), max(1, round(content.height * sy))), Image.Resampling.BICUBIC)
659
+ return content.resize(
660
+ (max(1, round(content.width * sx)), max(1, round(content.height * sy))), Image.Resampling.BICUBIC
661
+ )
525
662
 
526
663
 
527
664
  def _faded(image, opacity):
528
665
  if opacity >= 1:
529
666
  return image
530
- alpha = image.getchannel('A').point(lambda value: round(value * opacity))
667
+ alpha = image.getchannel("A").point(lambda value: round(value * opacity))
531
668
  image = image.copy()
532
669
  image.putalpha(alpha)
533
670
  return image
@@ -538,56 +675,60 @@ def _wiped(image, progress, steps=None):
538
675
  if progress >= 1:
539
676
  return image
540
677
  amount = math.floor(progress * steps) / steps if steps else progress
541
- mask = Image.new('L', image.size, 0)
678
+ mask = Image.new("L", image.size, 0)
542
679
  ImageDraw.Draw(mask).rectangle((0, 0, round(image.width * amount), image.height), fill=255)
543
- alpha = Image.composite(image.getchannel('A'), mask, mask)
680
+ alpha = Image.composite(image.getchannel("A"), mask, mask)
544
681
  image = image.copy()
545
682
  image.putalpha(alpha)
546
683
  return image
547
684
 
548
685
 
549
686
  def draw_graphic(draw, font_path, timeline, item, profile, relative_frame=None):
550
- kind = profile['component_id']
687
+ kind = profile["component_id"]
551
688
  motion = _motion(profile)
552
689
  (x, y, right, bottom), content, _ = _fit(font_path, timeline, item, profile)
553
690
  entry, exit_frames = frames(profile)
554
691
  relative = entry if relative_frame is None else relative_frame
555
- progress = min(1., max(0., (relative + 1) / entry))
556
- leaving = min(1., max(0., (item.duration_frames - relative) / exit_frames))
692
+ progress = min(1.0, max(0.0, (relative + 1) / entry))
693
+ leaving = min(1.0, max(0.0, (item.duration_frames - relative) / exit_frames))
557
694
  ease = 1 - (1 - progress) ** 3
558
695
  pops = _pops(profile)
559
- opacity = min(min(1., progress * (2.5 if pops else 1.4)), leaving)
560
- if motion == 'fade':
696
+ opacity = min(min(1.0, progress * (2.5 if pops else 1.4)), leaving)
697
+ if motion == "fade":
561
698
  opacity = min(ease, leaving)
562
699
  if pops:
563
- if motion == 'bounce':
700
+ if motion == "bounce":
564
701
  # Drop in squashed, stretch, then settle, all inside the footprint slack.
565
- stretch = 1 + .08 * math.sin(progress * math.pi * 1.5) * (1 - progress) if progress < 1 else 1.
566
- sized = _scaled(content, min(POP_SLACK, 2 - stretch) * (.75 + .25 * ease), min(POP_SLACK, stretch) * (.75 + .25 * ease))
567
- elif motion == 'stamp':
702
+ stretch = 1 + 0.08 * math.sin(progress * math.pi * 1.5) * (1 - progress) if progress < 1 else 1.0
703
+ sized = _scaled(
704
+ content,
705
+ min(POP_SLACK, 2 - stretch) * (0.75 + 0.25 * ease),
706
+ min(POP_SLACK, stretch) * (0.75 + 0.25 * ease),
707
+ )
708
+ elif motion == "stamp":
568
709
  # Thud down from slightly large to rest.
569
710
  sized = _scaled(content, *(POP_SLACK - (POP_SLACK - 1) * ease,) * 2)
570
711
  else:
571
712
  sized = _scaled(content, *(_pop(progress),) * 2)
572
713
  left = x + ((right - x) - sized.width) // 2
573
714
  top = y + ((bottom - y) - sized.height) // 2
574
- if motion == 'punch' and progress < 1:
715
+ if motion == "punch" and progress < 1:
575
716
  # A short shake that decays inside the slack.
576
717
  room = ((right - x) - sized.width) // 2
577
718
  left += round(math.sin(relative * 2.6) * room * (1 - progress))
578
719
  else:
579
720
  sized = content
580
721
  left = x
581
- top = y + round((1 - ease) * _base(timeline) * .012) # a short rise within the footprint
582
- if motion == 'write':
722
+ top = y + round((1 - ease) * _base(timeline) * 0.012) # a short rise within the footprint
723
+ if motion == "write":
583
724
  sized = _wiped(sized, progress, steps=max(4, len(item.text)))
584
- elif motion == 'slide':
725
+ elif motion == "slide":
585
726
  sized = _wiped(sized, ease)
586
727
  sized = _faded(sized, opacity)
587
- canvas = getattr(draw, '_image', None)
728
+ canvas = getattr(draw, "_image", None)
588
729
  if canvas is not None:
589
730
  canvas.alpha_composite(sized, (max(0, left), max(0, top)))
590
- if kind in {'pointer', 'circle'} and 'target' in profile:
731
+ if kind in {"pointer", "circle"} and "target" in profile:
591
732
  _target(draw, timeline, profile, (x, y, right, bottom), ease, opacity)
592
733
  return x, y, right, bottom
593
734
 
@@ -605,45 +746,59 @@ def _marker(draw, strokes, width, paper, ink):
605
746
  for points in strokes:
606
747
  _brush(draw, points, width * 1.3, ink)
607
748
  for points in strokes:
608
- _brush(draw, points, width * .66, paper)
749
+ _brush(draw, points, width * 0.66, paper)
609
750
 
610
751
 
611
752
  def _target(draw, timeline, profile, bounds, ease, opacity):
612
- palette = profile['presets']['palette']
613
- clean = _appearance(profile).get('arrow') == 'clean'
614
- paper, ink = _rgba(palette, 'paper', opacity), _rgba(palette, 'ink', opacity)
753
+ palette = profile["presets"]["palette"]
754
+ clean = _appearance(profile).get("arrow") == "clean"
755
+ paper, ink = _rgba(palette, "paper", opacity), _rgba(palette, "ink", opacity)
615
756
  if clean:
616
757
  # Interface-style callouts: one accent line without a dark outline.
617
- paper, ink = _rgba(palette, 'accent', opacity), _rgba(palette, 'accent', opacity)
618
- target = profile['target']
619
- tx, ty = target['x'] * timeline.width, target['y'] * timeline.height
620
- radius = target['radius'] * min(timeline.width, timeline.height)
621
- width = max(4., _base(timeline) * (.007 if clean else .0105))
622
- if profile['component_id'] == 'circle':
758
+ paper, ink = _rgba(palette, "accent", opacity), _rgba(palette, "accent", opacity)
759
+ target = profile["target"]
760
+ tx, ty = target["x"] * timeline.width, target["y"] * timeline.height
761
+ radius = target["radius"] * min(timeline.width, timeline.height)
762
+ width = max(4.0, _base(timeline) * (0.007 if clean else 0.0105))
763
+ if profile["component_id"] == "circle":
623
764
  # A slightly uneven hand-drawn loop, or a true circle for clean callouts.
624
- wobble, turn = (0, 2.) if clean else (.06, 2.15)
765
+ wobble, turn = (0, 2.0) if clean else (0.06, 2.15)
625
766
  steps = max(2, round(48 * ease))
626
- loop = [(tx + radius * (1 + wobble * math.sin(n * .7)) * math.cos(-math.pi / 2 + turn * math.pi * n / 48),
627
- ty + radius * (1 + wobble * math.sin(n * .7)) * math.sin(-math.pi / 2 + turn * math.pi * n / 48)) for n in range(steps + 1)]
767
+ loop = [
768
+ (
769
+ tx + radius * (1 + wobble * math.sin(n * 0.7)) * math.cos(-math.pi / 2 + turn * math.pi * n / 48),
770
+ ty + radius * (1 + wobble * math.sin(n * 0.7)) * math.sin(-math.pi / 2 + turn * math.pi * n / 48),
771
+ )
772
+ for n in range(steps + 1)
773
+ ]
628
774
  _marker(draw, [loop], width, paper, ink)
629
775
  return
630
776
  x, y, right, bottom = bounds
631
777
  # Leave from the label side facing the target, and bow the path like a quick hand stroke.
632
778
  start = (right + width * 2, (y + bottom) / 2) if tx >= (x + right) / 2 else (x - width * 2, (y + bottom) / 2)
633
- gap = radius * .9
634
- distance = math.hypot(tx - start[0], ty - start[1]) or 1.
779
+ gap = radius * 0.9
780
+ distance = math.hypot(tx - start[0], ty - start[1]) or 1.0
635
781
  end = (tx - (tx - start[0]) / distance * gap, ty - (ty - start[1]) / distance * gap)
636
- bend = 0 if clean else .22 * distance
637
- control = ((start[0] + end[0]) / 2 + (end[1] - start[1]) / distance * bend,
638
- (start[1] + end[1]) / 2 - (end[0] - start[0]) / distance * bend)
782
+ bend = 0 if clean else 0.22 * distance
783
+ control = (
784
+ (start[0] + end[0]) / 2 + (end[1] - start[1]) / distance * bend,
785
+ (start[1] + end[1]) / 2 - (end[0] - start[0]) / distance * bend,
786
+ )
639
787
  steps = max(2, round(32 * ease))
640
- curve = [((1 - t) ** 2 * start[0] + 2 * (1 - t) * t * control[0] + t ** 2 * end[0],
641
- (1 - t) ** 2 * start[1] + 2 * (1 - t) * t * control[1] + t ** 2 * end[1])
642
- for t in (n / 32 for n in range(steps + 1))]
788
+ curve = [
789
+ (
790
+ (1 - t) ** 2 * start[0] + 2 * (1 - t) * t * control[0] + t**2 * end[0],
791
+ (1 - t) ** 2 * start[1] + 2 * (1 - t) * t * control[1] + t**2 * end[1],
792
+ )
793
+ for t in (n / 32 for n in range(steps + 1))
794
+ ]
643
795
  strokes = [curve]
644
- if ease > .85:
796
+ if ease > 0.85:
645
797
  tip = curve[-1]
646
798
  angle = math.atan2(tip[1] - curve[-3][1], tip[0] - curve[-3][0])
647
799
  length = width * (4 if clean else 5.5)
648
- strokes += [[tip, (tip[0] - length * math.cos(angle + side), tip[1] - length * math.sin(angle + side))] for side in (-.6, .6)]
800
+ strokes += [
801
+ [tip, (tip[0] - length * math.cos(angle + side), tip[1] - length * math.sin(angle + side))]
802
+ for side in (-0.6, 0.6)
803
+ ]
649
804
  _marker(draw, strokes, width, paper, ink)