|
| 1 | +"""Generate multi-agents.png for LevelCode README.""" |
| 2 | + |
| 3 | +from PIL import Image, ImageDraw, ImageFont |
| 4 | +import math |
| 5 | +import os |
| 6 | + |
| 7 | +WIDTH, HEIGHT = 800, 800 |
| 8 | +BG_COLOR = (15, 15, 30) |
| 9 | +CENTER = (WIDTH // 2, HEIGHT // 2) |
| 10 | +ORBIT_RADIUS = 250 |
| 11 | + |
| 12 | +# Agent definitions matching the original: (name, color_rgb) |
| 13 | +AGENTS = [ |
| 14 | + ("researcher", (0, 220, 255)), |
| 15 | + ("thinker", (255, 230, 0)), |
| 16 | + ("reviewer", (0, 230, 100)), |
| 17 | + ("planner", (255, 160, 0)), |
| 18 | + ("file-picker", (170, 80, 255)), |
| 19 | + ("editor", (255, 80, 120)), |
| 20 | +] |
| 21 | + |
| 22 | + |
| 23 | +def load_font(size, bold=False): |
| 24 | + candidates = ( |
| 25 | + ["C:/Windows/Fonts/segoeuib.ttf", "C:/Windows/Fonts/arialbd.ttf"] |
| 26 | + if bold |
| 27 | + else ["C:/Windows/Fonts/segoeui.ttf", "C:/Windows/Fonts/arial.ttf"] |
| 28 | + ) |
| 29 | + for p in candidates: |
| 30 | + if os.path.exists(p): |
| 31 | + return ImageFont.truetype(p, size) |
| 32 | + return ImageFont.load_default() |
| 33 | + |
| 34 | + |
| 35 | +def draw_soft_glow(draw, cx, cy, radius, color, intensity=20, layers=5): |
| 36 | + """Draw a subtle soft glow behind a node.""" |
| 37 | + for i in range(layers, 0, -1): |
| 38 | + r = radius + i * 4 |
| 39 | + alpha = int(intensity * (1 - i / (layers + 1))) |
| 40 | + c = (color[0] // 4, color[1] // 4, color[2] // 4) |
| 41 | + draw.ellipse([cx - r, cy - r, cx + r, cy + r], fill=c) |
| 42 | + |
| 43 | + |
| 44 | +def draw_robot(draw, cx, cy, size, color): |
| 45 | + """Draw a cute minimalist robot character matching the original style.""" |
| 46 | + # Head - rounded rectangle with thick border |
| 47 | + pad = 4 |
| 48 | + x1, y1 = cx - size, cy - size |
| 49 | + x2, y2 = cx + size, cy + size |
| 50 | + # Fill (dark tinted) |
| 51 | + fill = (color[0] // 8, color[1] // 8, color[2] // 8) |
| 52 | + draw.rounded_rectangle([x1, y1, x2, y2], radius=14, fill=fill, outline=color, width=5) |
| 53 | + |
| 54 | + # Sparkle eye (4-point star) - left |
| 55 | + eye_y = cy - size // 4 |
| 56 | + eo = size // 3 # eye offset |
| 57 | + es = size // 5 # eye sparkle size |
| 58 | + for offset in [-eo, eo]: |
| 59 | + ex = cx + offset |
| 60 | + draw.polygon( |
| 61 | + [(ex, eye_y - es), (ex + es * 0.6, eye_y), (ex, eye_y + es), (ex - es * 0.6, eye_y)], |
| 62 | + fill=color, |
| 63 | + ) |
| 64 | + |
| 65 | + # Mouth - simple horizontal bar |
| 66 | + my = cy + size // 3 |
| 67 | + mw = size // 3 |
| 68 | + draw.rounded_rectangle( |
| 69 | + [cx - mw, my - 3, cx + mw, my + 3], radius=2, fill=color |
| 70 | + ) |
| 71 | + |
| 72 | + # Antenna |
| 73 | + at = y1 - 16 |
| 74 | + draw.line([(cx, y1), (cx, at)], fill=color, width=3) |
| 75 | + draw.ellipse([cx - 4, at - 4, cx + 4, at + 4], fill=color) |
| 76 | + |
| 77 | + # Arms - short angled lines |
| 78 | + arm_y = cy + 2 |
| 79 | + al = 18 |
| 80 | + draw.line([(x1 - 2, arm_y), (x1 - al, arm_y - 12)], fill=color, width=4) |
| 81 | + draw.line([(x2 + 2, arm_y), (x2 + al, arm_y - 12)], fill=color, width=4) |
| 82 | + # Hands (small circles) |
| 83 | + draw.ellipse([x1 - al - 5, arm_y - 17, x1 - al + 5, arm_y - 7], fill=color) |
| 84 | + draw.ellipse([x2 + al - 5, arm_y - 17, x2 + al + 5, arm_y - 7], fill=color) |
| 85 | + |
| 86 | + # Legs |
| 87 | + ly = y2 + 2 |
| 88 | + ll = 20 |
| 89 | + sp = size // 3 |
| 90 | + draw.line([(cx - sp, ly), (cx - sp - 3, ly + ll)], fill=color, width=4) |
| 91 | + draw.line([(cx + sp, ly), (cx + sp + 3, ly + ll)], fill=color, width=4) |
| 92 | + # Feet |
| 93 | + draw.rounded_rectangle( |
| 94 | + [cx - sp - 12, ly + ll - 2, cx - sp + 5, ly + ll + 8], radius=3, fill=color |
| 95 | + ) |
| 96 | + draw.rounded_rectangle( |
| 97 | + [cx + sp - 5, ly + ll - 2, cx + sp + 12, ly + ll + 8], radius=3, fill=color |
| 98 | + ) |
| 99 | + |
| 100 | + |
| 101 | +def draw_dotted_line(draw, x1, y1, x2, y2, color, gap=8): |
| 102 | + """Draw a dotted connection line.""" |
| 103 | + dist = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) |
| 104 | + dots = int(dist / gap) |
| 105 | + for i in range(dots): |
| 106 | + t = i / dots |
| 107 | + # Fade: stronger near center, lighter near edges |
| 108 | + if t < 0.25 or t > 0.75: |
| 109 | + continue |
| 110 | + x = x1 + (x2 - x1) * t |
| 111 | + y = y1 + (y2 - y1) * t |
| 112 | + r = 2 |
| 113 | + draw.ellipse([x - r, y - r, x + r, y + r], fill=color) |
| 114 | + |
| 115 | + |
| 116 | +def main(): |
| 117 | + img = Image.new("RGB", (WIDTH, HEIGHT), BG_COLOR) |
| 118 | + draw = ImageDraw.Draw(img) |
| 119 | + |
| 120 | + label_font = load_font(22, bold=True) |
| 121 | + center_font = load_font(24, bold=True) |
| 122 | + |
| 123 | + # Calculate positions |
| 124 | + positions = [] |
| 125 | + for i in range(len(AGENTS)): |
| 126 | + angle = (2 * math.pi * i / len(AGENTS)) - math.pi / 2 |
| 127 | + ax = CENTER[0] + int(ORBIT_RADIUS * math.cos(angle)) |
| 128 | + ay = CENTER[1] + int(ORBIT_RADIUS * math.sin(angle)) |
| 129 | + positions.append((ax, ay)) |
| 130 | + |
| 131 | + # Draw subtle orbit ring (dashed) |
| 132 | + segs = 180 |
| 133 | + for i in range(segs): |
| 134 | + if i % 5 < 2: |
| 135 | + continue |
| 136 | + a1 = 2 * math.pi * i / segs |
| 137 | + a2 = 2 * math.pi * (i + 1) / segs |
| 138 | + sx = CENTER[0] + int(ORBIT_RADIUS * math.cos(a1)) |
| 139 | + sy = CENTER[1] + int(ORBIT_RADIUS * math.sin(a1)) |
| 140 | + ex = CENTER[0] + int(ORBIT_RADIUS * math.cos(a2)) |
| 141 | + ey = CENTER[1] + int(ORBIT_RADIUS * math.sin(a2)) |
| 142 | + draw.line([(sx, sy), (ex, ey)], fill=(35, 35, 55), width=1) |
| 143 | + |
| 144 | + # Draw connection lines from center to each agent |
| 145 | + for i, (ax, ay) in enumerate(positions): |
| 146 | + color = AGENTS[i][1] |
| 147 | + faded = (color[0] // 3, color[1] // 3, color[2] // 3) |
| 148 | + draw_dotted_line(draw, CENTER[0], CENTER[1], ax, ay, faded) |
| 149 | + |
| 150 | + # Draw center: LevelCode orchestrator |
| 151 | + center_color = (220, 220, 240) |
| 152 | + draw_soft_glow(draw, CENTER[0], CENTER[1], 52, center_color, intensity=15) |
| 153 | + draw_robot(draw, CENTER[0], CENTER[1], 50, center_color) |
| 154 | + |
| 155 | + # Center label below |
| 156 | + txt = "LevelCode" |
| 157 | + bbox = draw.textbbox((0, 0), txt, font=center_font) |
| 158 | + tw = bbox[2] - bbox[0] |
| 159 | + lx = CENTER[0] - tw // 2 |
| 160 | + ly = CENTER[1] + 82 |
| 161 | + # Colored dot |
| 162 | + draw.ellipse([lx - 14, ly + 5, lx - 6, ly + 13], fill=center_color) |
| 163 | + draw.text((lx, ly), txt, fill=center_color, font=center_font) |
| 164 | + |
| 165 | + # Draw each agent |
| 166 | + for i, (name, color) in enumerate(AGENTS): |
| 167 | + ax, ay = positions[i] |
| 168 | + draw_soft_glow(draw, ax, ay, 38, color, intensity=12) |
| 169 | + draw_robot(draw, ax, ay, 36, color) |
| 170 | + |
| 171 | + # Label positioning - push outward from center |
| 172 | + angle = math.atan2(ay - CENTER[1], ax - CENTER[0]) |
| 173 | + bbox = draw.textbbox((0, 0), name, font=label_font) |
| 174 | + tw = bbox[2] - bbox[0] |
| 175 | + th = bbox[3] - bbox[1] |
| 176 | + |
| 177 | + # Place label further out along the angle |
| 178 | + label_dist = 68 |
| 179 | + lx = ax + int(label_dist * math.cos(angle)) - tw // 2 |
| 180 | + ly = ay + int(label_dist * math.sin(angle)) - th // 2 |
| 181 | + |
| 182 | + # Dot + text |
| 183 | + draw.ellipse([lx - 14, ly + th // 2 - 4, lx - 6, ly + th // 2 + 4], fill=color) |
| 184 | + draw.text((lx, ly), name, fill=color, font=label_font) |
| 185 | + |
| 186 | + out = os.path.join(os.path.dirname(os.path.abspath(__file__)), "multi-agents.png") |
| 187 | + img.save(out, "PNG") |
| 188 | + print(f"Saved: {out}") |
| 189 | + |
| 190 | + |
| 191 | +if __name__ == "__main__": |
| 192 | + main() |
0 commit comments