askrobots / network-computer-flutter
Public
One Flutter client for network-computer: drive a remote Linux/Mac desktop from Android, iPhone, iPad, or desktop over WebRTC.
Dan Quellhorst
No colour (compare) in ⋯: the desk's picture in grey on this device
c74471a
1 month, 3 weeks ago
History
make_icon.py · 3.2 KB · 78 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """Draws the app icon (1024x1024) and writes every iOS size. |
| 3 | python3 tool/make_icon.py (needs Pillow) |
| 4 | A blue screen with a pointer on it, on a dark ground, with two signal arcs: |
| 5 | a computer you drive from here, over the network. iOS rounds the corners.""" |
| 6 | import os |
| 7 | from PIL import Image, ImageDraw, ImageFilter |
| 8 | |
| 9 | S = 4 * 1024 # draw big, shrink: smooth edges |
| 10 | BG_TOP, BG_BOTTOM = (22, 30, 48), (8, 10, 16) |
| 11 | BLUE_TOP, BLUE_BOTTOM = (98, 160, 255), (52, 104, 230) |
| 12 | WHITE = (255, 255, 255) |
| 13 | |
| 14 | |
| 15 | def lerp(a, b, t): |
| 16 | return tuple(round(x + (y - x) * t) for x, y in zip(a, b)) |
| 17 | |
| 18 | |
| 19 | def vgradient(size, top, bottom): |
| 20 | w, h = size |
| 21 | col = Image.new("RGB", (1, h)) |
| 22 | for y in range(h): |
| 23 | col.putpixel((0, y), lerp(top, bottom, y / (h - 1))) |
| 24 | return col.resize((w, h)) |
| 25 | |
| 26 | |
| 27 | def u(v): |
| 28 | return round(v * S / 1024) |
| 29 | |
| 30 | |
| 31 | img = vgradient((S, S), BG_TOP, BG_BOTTOM) |
| 32 | d = ImageDraw.Draw(img) |
| 33 | |
| 34 | # the screen: a filled rounded rectangle with a slightly lighter bezel |
| 35 | sx0, sy0, sx1, sy1 = u(170), u(250), u(854), u(700) |
| 36 | glow = Image.new("L", (S, S), 0) |
| 37 | ImageDraw.Draw(glow).rounded_rectangle((sx0, sy0, sx1, sy1), radius=u(56), fill=150) |
| 38 | glow = glow.filter(ImageFilter.GaussianBlur(u(60))) |
| 39 | img.paste(Image.new("RGB", (S, S), (60, 110, 230)), (0, 0), glow) |
| 40 | d = ImageDraw.Draw(img) |
| 41 | d.rounded_rectangle((sx0 - u(18), sy0 - u(18), sx1 + u(18), sy1 + u(18)), radius=u(72), fill=(44, 54, 78)) |
| 42 | screen = vgradient((sx1 - sx0, sy1 - sy0), BLUE_TOP, BLUE_BOTTOM) |
| 43 | mask = Image.new("L", screen.size, 0) |
| 44 | ImageDraw.Draw(mask).rounded_rectangle((0, 0, screen.size[0] - 1, screen.size[1] - 1), radius=u(48), fill=255) |
| 45 | img.paste(screen, (sx0, sy0), mask) |
| 46 | |
| 47 | # stand |
| 48 | d.rounded_rectangle((u(462), u(716), u(562), u(792)), radius=u(10), fill=(44, 54, 78)) |
| 49 | d.rounded_rectangle((u(362), u(786), u(662), u(826)), radius=u(20), fill=(44, 54, 78)) |
| 50 | |
| 51 | # the pointer, white with a soft shadow, a little right of center |
| 52 | px, py, k = u(470), u(345), u(1) |
| 53 | arrow = [(0, 0), (0, 250), (62, 196), (108, 296), (152, 276), (108, 180), (190, 180)] |
| 54 | pts = [(px + x * k, py + y * k) for x, y in arrow] |
| 55 | shadow = Image.new("L", (S, S), 0) |
| 56 | ImageDraw.Draw(shadow).polygon([(x + u(10), y + u(14)) for x, y in pts], fill=120) |
| 57 | shadow = shadow.filter(ImageFilter.GaussianBlur(u(14))) |
| 58 | img.paste(Image.new("RGB", (S, S), (10, 20, 60)), (0, 0), shadow) |
| 59 | d = ImageDraw.Draw(img) |
| 60 | d.polygon(pts, fill=WHITE) |
| 61 | |
| 62 | # two signal arcs above the screen's top-right corner |
| 63 | cx, cy = u(800), u(215) |
| 64 | for r, wdt in ((u(70), u(26)), (u(130), u(26))): |
| 65 | d.arc((cx - r, cy - r, cx + r, cy + r), start=-150, end=-30, fill=(150, 200, 255), width=wdt) |
| 66 | d.ellipse((cx - u(20), cy - u(20), cx + u(20), cy + u(20)), fill=(150, 200, 255)) |
| 67 | |
| 68 | icon = img.resize((1024, 1024), Image.LANCZOS) |
| 69 | here = os.path.dirname(os.path.abspath(__file__)) |
| 70 | out = os.path.join(here, "..", "ios", "Runner", "Assets.xcassets", "AppIcon.appiconset") |
| 71 | icon.save(os.path.join(here, "icon-1024.png")) |
| 72 | for name in os.listdir(out): |
| 73 | if name.startswith("Icon-App-") and name.endswith(".png"): |
| 74 | spec = name[len("Icon-App-"):-4] # e.g. 20x20@3x, 83.5x83.5@2x |
| 75 | pt, scale = spec.split("@") |
| 76 | px_size = round(float(pt.split("x")[0]) * int(scale[:-1])) |
| 77 | icon.resize((px_size, px_size), Image.LANCZOS).save(os.path.join(out, name)) |
| 78 | print("icon written") |