a2a-source-edit: write agent.py

This commit is contained in:
a2a-cloud
2026-07-18 17:01:47 +00:00
parent 1b70097416
commit 48837a7456

View File

@@ -330,8 +330,8 @@ def _slugify(value: str) -> str:
return slug or "game-asset" return slug or "game-asset"
def _scale(unit: float, n: float) -> str: def _scale(unit: float, amount: float) -> str:
return f"{n * unit:.2f}" return f"{amount * unit:.2f}"
def _render_svg( def _render_svg(
@@ -382,7 +382,10 @@ def _render_svg(
def _asset_body(asset_type: str, style: str, primary: str, accent: str, dark: str, stroke: int, unit: float, pattern: int) -> str: def _asset_body(asset_type: str, style: str, primary: str, accent: str, dark: str, stroke: int, unit: float, pattern: int) -> str:
fill = "none" if style == "outline" else primary fill = "none" if style == "outline" else primary
common = f'stroke="{dark}" stroke-width="{stroke}" stroke-linejoin="round" stroke-linecap="round"' common = f'stroke="{dark}" stroke-width="{stroke}" stroke-linejoin="round" stroke-linecap="round"'
p = lambda n: _scale(unit, n)
def p(amount: float) -> str:
return _scale(unit, amount)
if asset_type == "character": if asset_type == "character":
return ( return (
f'<circle cx="{p(8)}" cy="{p(4.2)}" r="{p(2.1)}" fill="{fill}" {common}/>' f'<circle cx="{p(8)}" cy="{p(4.2)}" r="{p(2.1)}" fill="{fill}" {common}/>'
@@ -393,9 +396,10 @@ def _asset_body(asset_type: str, style: str, primary: str, accent: str, dark: st
spike_points: list[str] = [] spike_points: list[str] = []
for i in range(7): for i in range(7):
spike_points.append(f'{p(2 + i * 2)},{p(7 + ((pattern + i) % 3))}') spike_points.append(f'{p(2 + i * 2)},{p(7 + ((pattern + i) % 3))}')
spike_points_text = " ".join(spike_points)
return ( return (
f'<polygon points="{p(8)},{p(2)} {p(14)},{p(8)} {p(11)},{p(14)} {p(5)},{p(14)} {p(2)},{p(8)}" fill="{fill}" {common}/>' f'<polygon points="{p(8)},{p(2)} {p(14)},{p(8)} {p(11)},{p(14)} {p(5)},{p(14)} {p(2)},{p(8)}" fill="{fill}" {common}/>'
f'<polyline points="{" ".join(spike_points)}" fill="none" stroke="{accent}" stroke-width="{stroke}"/>' f'<polyline points="{spike_points_text}" fill="none" stroke="{accent}" stroke-width="{stroke}"/>'
f'<circle cx="{p(6)}" cy="{p(8)}" r="{p(.55)}" fill="{dark}"/><circle cx="{p(10)}" cy="{p(8)}" r="{p(.55)}" fill="{dark}"/>' f'<circle cx="{p(6)}" cy="{p(8)}" r="{p(.55)}" fill="{dark}"/><circle cx="{p(10)}" cy="{p(8)}" r="{p(.55)}" fill="{dark}"/>'
) )
if asset_type == "item": if asset_type == "item":