"""Brand files of Create RP: wordmark, icons, banners and the FancyMenu title-screen assets. python tools/branding/build.py [emblem_raw.png] Everything is drawn from three sources: Minecraft's own pixel font and block textures (read from the jars, not stored here), the key art illustration (branding/art/keyart.png) and, if given, a raw emblem picture that is snapped to a coarse pixel grid. Output goes to branding/ next to this repo's images. """ import io import json import math import sys import zipfile from pathlib import Path import numpy as np from PIL import Image, ImageEnhance, ImageFilter ROOT = Path(__file__).resolve().parent.parent.parent sys.path.insert(0, str(ROOT / 'tools' / 'signs')) from render import Font # noqa: E402 (the pixel font reader made for the building signs) OUT = ROOT / 'branding' NAME = 'CREATE RP' TAGLINE = 'ДЕРЖАВА ПАРИ Й ШЕСТЕРЕНЬ' ADDRESS = 'create.fulldroper.ks.ua' # palette: brass and brick, as the state quarter is built INK = (38, 24, 16) # outlines CREAM = (243, 229, 196) # small text BRICK = (176, 78, 58) # the red of the state's brick buildings BRASS = [(104, 68, 26), (168, 116, 42), (217, 164, 65), (245, 205, 110)] # dark → light def texture(jar: zipfile.ZipFile, path: str) -> np.ndarray: return np.asarray(Image.open(io.BytesIO(jar.read(path))).convert('RGB'))[:16, :16] def mask_of(font: Font, text: str, bold: bool) -> np.ndarray: """The text as font pixels; bold is Minecraft's own bold: the glyph drawn twice, one pixel apart.""" parts = [] for c in text: g = np.zeros((12, 3), bool) if c == ' ' else font.glyphs[c] if bold and c != ' ': g = np.pad(g, ((0, 0), (0, 1))) | np.pad(g, ((0, 0), (1, 0))) parts += [g, np.zeros((12, 1), bool)] m = np.hstack(parts[:-1]) rows = np.nonzero(m.any(axis=1))[0] return m[rows.min():rows.max() + 1] def shift(m: np.ndarray, dy: int, dx: int) -> np.ndarray: out = np.zeros_like(m) h, w = m.shape out[max(dy, 0):h + min(dy, 0), max(dx, 0):w + min(dx, 0)] = m[max(-dy, 0):h + min(-dy, 0), max(-dx, 0):w + min(-dx, 0)] return out def lettering(mask: np.ndarray, fill, scale: int, depth: int = 1, outline: bool = True) -> Image.Image: """Letters made of whole texels: lit from the top left, a dark side `depth` font pixels deep, an ink outline.""" pad = 1 + depth m = np.pad(mask, pad) h, w = m.shape yy, xx = np.mgrid[0:h, 0:w] if isinstance(fill, np.ndarray): colour = fill[yy % fill.shape[0], xx % fill.shape[1]].astype(np.float32) else: colour = np.broadcast_to(np.array(fill, np.float32), (h, w, 3)).copy() colour[m & ~shift(m, 1, 0)] *= 1.18 # top edge catches the light colour[m & ~shift(m, 0, 1)] *= 1.08 # left edge a little colour[m & ~shift(m, -1, 0)] *= 0.80 # bottom edge in shade side = np.zeros_like(m) for d in range(1, depth + 1): side |= shift(m, d, d) side &= ~m body = m | side edge = np.zeros_like(m) if outline: for dy in (-1, 0, 1): for dx in (-1, 0, 1): edge |= shift(body, dy, dx) edge &= ~body out = np.zeros((h, w, 4), np.float32) out[..., :3] = INK out[side, :3] = np.array(fill.reshape(-1, 3).mean(axis=0) if isinstance(fill, np.ndarray) else fill, np.float32) * 0.45 out[m, :3] = colour[m] out[body | edge, 3] = 255 img = np.clip(out, 0, 255).astype(np.uint8) return Image.fromarray(np.repeat(np.repeat(img, scale, 0), scale, 1), 'RGBA') def stack(images, gap: int, align: str = 'center') -> Image.Image: w = max(i.width for i in images) h = sum(i.height for i in images) + gap * (len(images) - 1) out = Image.new('RGBA', (w, h), (0, 0, 0, 0)) y = 0 for i in images: out.alpha_composite(i, ((w - i.width) // 2 if align == 'center' else 0, y)) y += i.height + gap return out def beside(images, gap: int) -> Image.Image: h = max(i.height for i in images) out = Image.new('RGBA', (sum(i.width for i in images) + gap * (len(images) - 1), h), (0, 0, 0, 0)) x = 0 for i in images: out.alpha_composite(i, (x, h - i.height)) x += i.width + gap return out def gear(n: int, teeth: int = 8) -> Image.Image: """A brass cogwheel on an n x n pixel grid: the simple mark for icons too small for the emblem.""" ss = 8 c = (n * ss - 1) / 2 yy, xx = np.mgrid[0:n * ss, 0:n * ss] x, y = (xx - c) / (n * ss / 2), (yy - c) / (n * ss / 2) r = np.hypot(x, y) shape = r < 0.70 for k in range(teeth): # straight-sided teeth: the same width on the axes and on the diagonals t = 2 * math.pi * k / teeth along, across = x * math.cos(t) + y * math.sin(t), -x * math.sin(t) + y * math.cos(t) shape |= (np.abs(across) < 0.15) & (along > 0.5) & (along < 0.96) shape &= r > 0.30 cover = shape.reshape(n, ss, n, ss).mean(axis=(1, 3)) m = cover >= 0.5 light = ((xx - c) * -0.7 + (yy - c) * -0.7).reshape(n, ss, n, ss).mean(axis=(1, 3)) / (n * ss / 2) # lit from the top left tone = np.clip(np.round(1.6 + light * 1.6), 0, 3).astype(int) rim = m & ~(shift(m, 1, 0) & shift(m, -1, 0) & shift(m, 0, 1) & shift(m, 0, -1)) out = np.zeros((n, n, 4), np.uint8) out[m, :3] = np.array(BRASS)[tone][m] out[rim, :3] = BRASS[0] if n > 16 else BRASS[1] out[m, 3] = 255 return Image.fromarray(out, 'RGBA') def on_plate(mark: Image.Image, size: int, plate=(110, 52, 40)) -> Image.Image: """An icon: the mark on a brick-red square with a dark frame (for places that show no transparency).""" n = mark.width grid = n + 4 out = np.zeros((grid, grid, 4), np.uint8) out[..., :3] = plate out[..., 3] = 255 out[0, :, :3] = out[-1, :, :3] = out[:, 0, :3] = out[:, -1, :3] = INK base = Image.fromarray(out, 'RGBA') base.alpha_composite(mark, (2, 2)) return base.resize((size, size), Image.NEAREST) def pixelate(raw: Image.Image, grid: int) -> Image.Image: """A generated emblem snapped to a grid x grid picture with a hard alpha edge, so it sits beside pixel lettering.""" im = raw.convert('RGBA') a = np.asarray(im)[..., 3] ys, xs = np.nonzero(a > 40) im = im.crop((xs.min(), ys.min(), xs.max() + 1, ys.max() + 1)) side = max(im.size) sq = Image.new('RGBA', (side, side), (0, 0, 0, 0)) sq.alpha_composite(im, ((side - im.width) // 2, (side - im.height) // 2)) small = np.asarray(sq.resize((grid, grid), Image.BOX)).copy() solid = small[..., 3] >= 128 rgb = Image.fromarray(small[..., :3], 'RGB').quantize(64, method=Image.MEDIANCUT).convert('RGB') small[..., :3] = np.asarray(rgb) small[..., 3] = np.where(solid, 255, 0) small[~solid, :3] = INK return Image.fromarray(small, 'RGBA') def cover(im: Image.Image, w: int, h: int, focus_y: float = 0.5) -> Image.Image: s = max(w / im.width, h / im.height) big = im.resize((round(im.width * s), round(im.height * s)), Image.LANCZOS) x = (big.width - w) // 2 y = round((big.height - h) * focus_y) return big.crop((x, y, x + w, y + h)) def shade(im: Image.Image, top: float, bottom: float) -> Image.Image: """Darkens the picture with a vertical gradient (1 = untouched), so light lettering reads on it.""" a = np.asarray(im.convert('RGB')).astype(np.float32) g = np.linspace(top, bottom, a.shape[0], dtype=np.float32)[:, None, None] return Image.fromarray(np.clip(a * g, 0, 255).astype(np.uint8), 'RGB').convert('RGBA') def fit(im: Image.Image, max_w: int, max_h: int) -> Image.Image: """Pixel art is only ever resized by whole factors.""" k = max(1, min(max_w // im.width, max_h // im.height)) return im.resize((im.width * k, im.height * k), Image.NEAREST) # Icons of the title screen, drawn on the 13 px grid of Minecraft's own button icons. Each one redraws an icon of the # FD Icons library (named in the comment). '.' is empty; the other letters are colours from ICON_COLOURS. ICON_COLOURS = { '#': (255, 255, 255), '+': (208, 208, 208), # white and the light grey Minecraft shades its icons with 'G': (58, 200, 18), 'g': (0, 150, 0), # server is online 'R': (224, 64, 58), 'r': (160, 38, 32), # server is offline 'A': (249, 168, 37), 'a': (190, 110, 20), # maintenance 'Y': (255, 216, 61), 'M': (214, 222, 240), # sun and moon in the player list } # Warning icons for the HUD, 16 x 16 with a dark outline, each in yellow (a warning) and red (bad). # C main colour, c its shade, W light, K dark detail. The person and the clock redraw the FD Icons "person" and # "clock"; the library has no train, so the train is drawn here: a steam locomotive from the side, smoke above the # chimney, the cab at the back, two driving wheels under a dark frame. HUD_ICONS = { 'server-load': ''' .WWW.......... WWWWW......... .WWW.......... ..CC.....CCCCC ..CC.....CKKKC .CCCCCCCCCKKKC CCCCCCCCCCCCCC CWCCCCCCCCCCCC cCCCCCCCCCCCCC .KKKKKKKKKKKK. ..cccc...cccc. ..cWWc...cWWc. ..cccc...cccc. .............. ''', 'client-load': ''' .....CCCC..... ....CCCCCC.... ....CWCCCC.... ....CCCCCC.... ....CCCCCC.... .....cccc..... .............. ...CCCCCCCC... ..CCCCCCCCCC.. .CCCCCCCCCCCC. .CCCCCCCCCCCC. .CCCCCCCCCCCC. .cccccccccccc. .............. ''', 'connection': ''' ....CCCCCC.... ..CCCCCCCCCC.. .CCWWWWKWWWCC. .CWWWWWKWWWWC. CCWWWWWKWWWWCC CWWWWWWKWWWWWC CWWWWWWKKKKWWC CWWWWWWWWWWWWC CCWWWWWWWWWWCC .CWWWWWWWWWWC. .CCWWWWWWWWCC. ..CCCCCCCCCC.. ....cccccc.... .............. ''', } HUD_COLOURS = {'yellow': ((255, 204, 51), (196, 140, 20)), 'red': ((226, 62, 50), (150, 30, 24))} SUN_ICON = ''' Y..Y..Y .Y.Y.Y. ..YYY.. YYYYYYY ..YYY.. .Y.Y.Y. Y..Y..Y ''' MOON_ICON = ''' ..MMM.. .MM.... MM..... MM..... MM..... .MM.... ..MMM.. ''' QUIT_ICON = ''' #######....... #............. #............. #.......#..... #.......##.... #..#########.. #..##########. #..#########.. #.......##.... #.......#..... #............. #............. #######....... +++++++....... ''' # sign-out: a door frame with an arrow going out ONLINE_ICON = ''' ....GGGGG.... ..GGGGGGGGG.. .GGGGGGGGGGG. .GGGGGGGG##G. GGGGGGGG###GG GGGGGGG###GGG GG##GG###GGGG GG######GGGGG GGg####GGGGGg .Ggg##GGGGGg. .gGGGGGGGGgg. ..ggGGGGGgg.. ....ggggg.... ''' # check-circle OFFLINE_ICON = ''' ....RRRRR.... ..RRRRRRRRR.. .RRRRRRRRRRR. .RR##RRR##RR. RRR###R###RRR RRRR#####RRRR RRRRR###RRRRR RRRR#####RRRR RRr###R###RRr .Rr##RRR##Rr. .rRRRRRRRRrr. ..rrRRRRRrr.. ....rrrrr.... ''' # close-circle MAINTENANCE_ICON = ''' ........AAA.. .......AAA... ......AAA.... ......AAA...A ......AAAA.AA ......AAAAAAa .....AAAAAAa. ....AAAAaaa.. ...AAAAa..... ..AAAAa...... .AAAAa....... AAAAa........ AAAa......... ''' # wrench def button_icon(rows: str, outline: bool = False, canvas: int = 20, at: int = -1) -> Image.Image: """A picture for a square button: the drawing is centred (or starts at `at`). An icon shown without a button behind it gets a dark outline, so it reads on any background.""" grid = rows.split() at = (canvas - len(grid[0])) // 2 if at < 0 else at im = Image.new('RGBA', (canvas, canvas), (0, 0, 0, 0)) for y, row in enumerate(grid): for x, c in enumerate(row): if c != '.': im.putpixel((at + x, at + y), ICON_COLOURS[c] + (255,)) if outline: solid = np.asarray(im)[..., 3] > 0 near = np.zeros_like(solid) for dy in (-1, 0, 1): for dx in (-1, 0, 1): near |= shift(solid, dy, dx) edge = Image.new('RGBA', im.size, INK + (255,)) edge.putalpha(Image.fromarray(((near & ~solid) * 255).astype(np.uint8))) im = Image.alpha_composite(edge, im) return im def shaded_disc(size: int, inside, colour, rim, lines=None) -> Image.Image: """A small round pixel picture: `inside(x, y)` (centred coordinates, radius 1 = the edge) says what is solid, lit from the top left, a darker rim, and optional `lines(x, y)` drawn lighter on top.""" k, c = 8, (size - 1) / 2 im = np.zeros((size, size, 4), np.float32) for py in range(size): for px in range(size): hits = sum(inside((px - c + (i % k + 0.5) / k - 0.5) / (size / 2), (py - c + (i // k + 0.5) / k - 0.5) / (size / 2)) for i in range(k * k)) if hits * 2 >= k * k: x, y = (px - c) / (size / 2), (py - c) / (size / 2) light = 1.18 - 0.30 * (x + y) rgb = np.array(colour, np.float32) * light if lines and lines(x, y): rgb = np.minimum(rgb * 1.55 + 40, 255) im[py, px] = (*rgb, 255) solid = im[..., 3] > 0 edge = solid & ~(shift(solid, 1, 0) & shift(solid, -1, 0) & shift(solid, 0, 1) & shift(solid, 0, -1)) im[edge, :3] = rim return Image.fromarray(np.clip(im, 0, 255).astype(np.uint8), 'RGBA') def gear_icon(size: int = 14) -> Image.Image: """Settings: a steel gear with eight teeth and a hole.""" def inside(x, y): r, a = math.hypot(x, y), math.atan2(y, x) tooth = (math.degrees(a) % 45) < 21 return 0.34 < r < (0.98 if tooth else 0.74) return shaded_disc(size, inside, (196, 200, 206), (70, 72, 78)) def globe_icon(size: int = 14) -> Image.Image: """Language: a blue globe with a meridian, an oval meridian and three parallels.""" def lines(x, y): oval = 0.55 * math.sqrt(max(0.0, 1 - y * y)) return abs(x) < 0.08 or abs(abs(x) - oval) < 0.08 or abs(y) < 0.08 or abs(abs(y) - 0.52) < 0.08 return shaded_disc(size, lambda x, y: x * x + y * y < 0.97, (58, 108, 196), (24, 46, 100), lines) def on_canvas(icon: Image.Image, canvas: int) -> Image.Image: im = Image.new('RGBA', (canvas, canvas)) im.alpha_composite(icon, ((canvas - icon.width) // 2, (canvas - icon.height) // 2)) return im def casingify(sheet: Image.Image, wood: np.ndarray, frame, face=None) -> Image.Image: """EMI's little grey buttons and panels rebuilt in the look of our buttons. Buttons on EMI's sheet touch each other, so a piece is told apart by its lines, not by gaps: the black lines (and a piece's outer edge) stay; the pixels right next to them — the bevel — become the casing's metal frame; further in, the grey face becomes wood (or `face`), and anything brighter or darker than the face around it is a symbol and is kept. A piece outlined in white is EMI's highlighted state and gets brass. `frame` is (light, dark).""" from collections import deque px = np.asarray(sheet.convert('RGBA')).astype(np.float32) out = px.copy() solid = px[..., 3] > 0 lum = px[..., :3].mean(axis=2) h, w = solid.shape inner = shift(solid, 1, 0) & shift(solid, -1, 0) & shift(solid, 0, 1) & shift(solid, 0, -1) line = solid & ((lum < 45) | ~inner) dist = np.full((h, w), 99, int) near = np.zeros((h, w), np.float32) # brightness of the nearest line q = deque() for y, x in zip(*np.nonzero(line)): dist[y, x], near[y, x] = 0, lum[y, x] q.append((y, x)) while q: y, x = q.popleft() for ny, nx in ((y + 1, x), (y - 1, x), (y, x + 1), (y, x - 1)): if 0 <= ny < h and 0 <= nx < w and solid[ny, nx] and dist[ny, nx] > dist[y, x] + 1: dist[ny, nx], near[ny, nx] = dist[y, x] + 1, near[y, x] q.append((ny, nx)) # pieces smaller than 8 x 8 (dots, little icons) are left alone big = np.zeros((h, w), bool) seen = np.zeros((h, w), bool) for sy, sx in zip(*np.nonzero(solid)): if seen[sy, sx]: continue piece, q = [], deque([(sy, sx)]) seen[sy, sx] = True while q: y, x = q.popleft() piece.append((y, x)) for ny, nx in ((y + 1, x), (y - 1, x), (y, x + 1), (y, x - 1)): if 0 <= ny < h and 0 <= nx < w and solid[ny, nx] and not seen[ny, nx]: seen[ny, nx] = True q.append((ny, nx)) ys, xs = zip(*piece) if max(ys) - min(ys) >= 7 and max(xs) - min(xs) >= 7: big[tuple(zip(*piece))] = True deep = big & (dist >= 2) for y, x in zip(*np.nonzero(big)): d, hot = dist[y, x], near[y, x] > 200 if d == 0: if hot: out[y, x, :3] = BRASS[1] continue window = deep[max(0, y - 6):y + 7, max(0, x - 6):x + 7] face_lum = float(np.median(lum[max(0, y - 6):y + 7, max(0, x - 6):x + 7][window])) if window.any() else lum[y, x] light, dark = (BRASS[3], BRASS[0]) if hot else frame if d == 1: out[y, x, :3] = light if lum[y, x] >= face_lum else dark elif abs(lum[y, x] - face_lum) > 32: # a symbol: kept, white turned to cream r, g, b = px[y, x, :3] if max(r, g, b) - min(r, g, b) < 24: out[y, x, :3] = np.array(CREAM, np.float32) * (lum[y, x] / 255) ** 0.5 else: base = np.array(face, np.float32) if face is not None else wood[y % 16, x % 16] out[y, x, :3] = base * (0.55 if face_lum < 70 else 1.12 if hot else 1.0) return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA') # EMI's buttons.png (EMI 1.1): where each button is, as (x, y, width, height). EMI draws them from these rectangles, # so each one is rebuilt inside its own bounds — a grid over the whole sheet cut the bigger ones apart. EMI_BUTTON_CELLS = ( [(x, y, 12, 12) for y in range(0, 84, 12) for x in range(0, 84, 12)] # small buttons, 3 states each + [(x, y, 20, 20) for x in (164, 184, 204) for y in (0, 20)] # config, tree, "EMI" + [(164, 40, 20, 20), (164, 60, 20, 20)] # the globe button + [(x, y, 16, 16) for x in (224, 240) for y in (0, 16, 32)] # page arrows + [(x, y, 12, 10) for x in (232, 244) for y in (48, 58)] # small up / down ) def casing_buttons(sheet: Image.Image, wood: np.ndarray, brass_wood: np.ndarray, frame, tiles, cells=EMI_BUTTON_CELLS) -> Image.Image: """EMI's buttons rebuilt like ours. Each cell is a 1 px ring, a 1 px bevel and a flat face with a symbol. The ring stays (a white ring — the highlighted state — turns brass), the bevel takes the casing's metal from the block's own edge, a grey face becomes wood (brass casing's wood when highlighted, dimmed when disabled), a coloured face (EMI's green "on") keeps its colour; symbols are kept, grey ones in cream, their dark shadows in dark wood.""" px = np.asarray(sheet.convert('RGBA')).astype(np.float32) out = px.copy() for cx, cy, w, h in cells: c = px[cy:cy + h, cx:cx + w] if c.shape[:2] != (h, w) or (c[..., 3] > 0).sum() < w * h * 0.9: continue # an empty place in the grid lum = c[..., :3].mean(axis=2) ring = np.zeros((h, w), bool) ring[0, :] = ring[-1, :] = ring[:, 0] = ring[:, -1] = True bevel = np.zeros((h, w), bool) bevel[1, 1:-1] = bevel[-2, 1:-1] = bevel[1:-1, 1] = bevel[1:-1, -2] = True inside = ~ring & ~bevel ring_lum = lum[ring].mean() if 90 < ring_lum < 200: continue # not a button hot = ring_lum >= 200 band = inside.copy() # the face just inside the bevel: no symbol reaches there band[3:-3, 3:-3] = False # inside is [2:-2]; keep only its outermost pixels face = np.median(c[band][:, :3], axis=0) face_lum = face.mean() coloured = face.max() - face.min() > 30 dim = face_lum < 70 and not coloured tile = tiles[1] if hot else tiles[0] grain = brass_wood if hot else wood o = out[cy:cy + h, cx:cx + w] if hot: o[ring, :3] = BRASS[1] for y in range(h): for x in range(w): if bevel[y, x]: # the casing's metal, from the block's own edge o[y, x, :3] = (tile[1, 3 + x % 10] if y == 1 else tile[14, 3 + x % 10] if y == h - 2 else tile[3 + y % 10, 1] if x == 1 else tile[3 + y % 10, 14]) elif inside[y, x]: p = c[y, x, :3] if np.abs(p - face).max() <= 28: # the face (by colour: a blue globe is as bright as grey) if not coloured: o[y, x, :3] = grain[(cy + y) % 16, (cx + x) % 16] * (0.5 if dim else 1.0) elif p.max() - p.min() >= 24: # a coloured symbol (the globe, EMI's letters): as it is continue elif p.mean() < face_lum: # a symbol's shadow o[y, x, :3] = grain[(cy + y) % 16, (cx + x) % 16] * 0.4 else: # a grey symbol o[y, x, :3] = np.array(CREAM, np.float32) * (0.55 if dim else 1.0) return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA') def tint(sprite: Image.Image, colour) -> Image.Image: """A grey Minecraft sprite in another colour: brightness and transparency kept.""" px = np.asarray(sprite.convert('RGBA')).astype(np.float32) px[..., :3] = px[..., :3].mean(axis=2, keepdims=True) / 255 * np.array(colour, np.float32) return Image.fromarray(np.clip(px, 0, 255).astype(np.uint8), 'RGBA') def greys_to(sprite: Image.Image, colour) -> Image.Image: """Only the grey pixels of a sprite take the colour (their brightness kept); coloured details stay as they are.""" px = np.asarray(sprite.convert('RGBA')).astype(np.float32) grey = (px[..., :3].max(axis=2) - px[..., :3].min(axis=2)) < 24 px[grey, :3] = px[grey, :3].mean(axis=1, keepdims=True) / 255 * np.array(colour, np.float32) return Image.fromarray(np.clip(px, 0, 255).astype(np.uint8), 'RGBA') def plate(tile: np.ndarray, w: int, h: int, tone: float = 1.0) -> Image.Image: """A small metal plate with a black outline: the slider's handle.""" px = np.zeros((h, w, 3), np.float32) inner = np.tile(tile, (2, 2, 1))[:h - 2, :w - 2].astype(np.float32) * tone inner[0] *= 1.2 inner[:, 0] *= 1.1 inner[-1] *= 0.7 inner[:, -1] *= 0.8 px[1:-1, 1:-1] = inner return Image.fromarray(np.clip(px, 0, 255).astype(np.uint8), 'RGB').convert('RGBA') def casing_button(jar: zipfile.ZipFile, casing: str, tone: float = 1.0, grey: float = 0.0) -> Image.Image: """A 200x20 button sprite built from a Create casing: black outline, the casing's 3 px metal frame, its wood inside. The wood is tiled with the block's own 16 px period and the sprite is nine-sliced with a 4 px border, so the 192 px middle (12 tiles) repeats without a seam on buttons of any width.""" tile = texture(jar, f'assets/create/textures/block/{casing}.png')[..., :3].astype(int) sheet = np.asarray(Image.open(io.BytesIO( jar.read(f'assets/create/textures/block/{casing}_connected.png'))).convert('RGBA')).astype(int) cells = [sheet[ty:ty + 16, tx:tx + 16] for ty in range(0, sheet.shape[0], 16) for tx in range(0, sheet.shape[1], 16)] # the plain wood is the opaque tile of the connected sheet with the least contrast: every other one has frame in it wood = min((c for c in cells if c[..., 3].min() == 255), key=lambda c: c[..., :3].std())[..., :3] px = np.zeros((20, 200, 3), int) px[1:19, 1:199] = np.tile(wood, (2, 13, 1))[2:20, :198] # wood everywhere inside the outline for i in range(3): # frame rows and columns, taken from the block's edges px[1 + i, 1:199] = np.tile(tile[i, 3:13], (20, 1))[:198] px[18 - i, 1:199] = np.tile(tile[15 - i, 3:13], (20, 1))[:198] px[1:19, 1 + i] = np.tile(tile[3:13, i], (2, 1))[:18] px[1:19, 198 - i] = np.tile(tile[3:13, 15 - i], (2, 1))[:18] for (y, x), (ty, tx) in (((1, 1), (0, 0)), ((1, 196), (0, 13)), ((16, 1), (13, 0)), ((16, 196), (13, 13))): px[y:y + 3, x:x + 3] = tile[ty:ty + 3, tx:tx + 3] # the four corners px[1:19, 1:199] = px[1:19, 1:199] * tone mean = px.mean(axis=2, keepdims=True) px = np.clip(px * (1 - grey) + mean * grey, 0, 255) return Image.fromarray(px.astype(np.uint8), 'RGB').convert('RGBA') BUTTON_META = '{"gui": {"scaling": {"type": "nine_slice", "width": 200, "height": 20, "border": 4}}}\n' def main() -> None: mc_jar, create_jar, key_art = sys.argv[1], sys.argv[2], Path(sys.argv[3]) emblem_raw = Path(sys.argv[4]) if len(sys.argv) > 4 else None emi_jar = sys.argv[5] if len(sys.argv) > 5 else None # EMI's panels are recoloured when its jar is given with zipfile.ZipFile(mc_jar) as mc, zipfile.ZipFile(create_jar) as cr: font = Font(mc) brass = texture(cr, 'assets/create/textures/block/brass_block.png') casing_tile = texture(cr, 'assets/create/textures/block/andesite_casing.png').astype(int) sheet = np.asarray(Image.open(io.BytesIO(cr.read('assets/create/textures/block/andesite_casing_connected.png'))).convert('RGBA')).astype(int) cells = [sheet[ty:ty + 16, tx:tx + 16] for ty in range(0, sheet.shape[0], 16) for tx in range(0, sheet.shape[1], 16)] casing_wood = min((c for c in cells if c[..., 3].min() == 255), key=lambda c: c[..., :3].std())[..., :3] * 0.8 sheet = np.asarray(Image.open(io.BytesIO(cr.read('assets/create/textures/block/brass_casing_connected.png'))).convert('RGBA')).astype(int) cells = [sheet[ty:ty + 16, tx:tx + 16] for ty in range(0, sheet.shape[0], 16) for tx in range(0, sheet.shape[1], 16)] brass_wood = min((c for c in cells if c[..., 3].min() == 255), key=lambda c: c[..., :3].std())[..., :3] * 1.1 # sprites of Minecraft's widgets, by their path under assets/minecraft/textures/gui/ vanilla = lambda path: Image.open(io.BytesIO(mc.read('assets/minecraft/textures/gui/' + path))).convert('RGBA') gui = {'sprites/widget/button.png': casing_button(cr, 'andesite_casing', tone=0.82), 'sprites/widget/button_highlighted.png': casing_button(cr, 'brass_casing', tone=1.12), 'sprites/widget/button_disabled.png': casing_button(cr, 'andesite_casing', tone=0.42, grey=0.6), 'sprites/widget/slider.png': casing_button(cr, 'andesite_casing', tone=0.45, grey=0.3), 'sprites/widget/slider_highlighted.png': casing_button(cr, 'brass_casing', tone=0.6), 'sprites/widget/slider_handle.png': plate(brass, 8, 20, 0.92), 'sprites/widget/slider_handle_highlighted.png': plate(brass, 8, 20, 1.15), 'sprites/widget/text_field_highlighted.png': tint(vanilla('sprites/widget/text_field_highlighted.png'), BRASS[3]), 'sprites/widget/scroller.png': tint(vanilla('sprites/widget/scroller.png'), BRASS[3]), 'sprites/icon/language.png': on_canvas(globe_icon(13), 15)} for name, (top, bottom) in (('header', (BRASS[0], BRASS[2])), ('footer', (BRASS[2], BRASS[0]))): line = Image.new('RGBA', (32, 2), top + (255,)) line.paste(bottom + (255,), (0, 1, 32, 2)) gui[f'{name}_separator.png'] = gui[f'inworld_{name}_separator.png'] = line casing = [p for p in gui if 'casing' in p or p.endswith(('button.png', 'button_highlighted.png', 'button_disabled.png', 'slider.png', 'slider_highlighted.png'))] meta = {p: (BUTTON_META if p in casing else mc.read('assets/minecraft/textures/gui/' + p + '.mcmeta').decode()) for p in gui if p in casing or 'assets/minecraft/textures/gui/' + p + '.mcmeta' in mc.namelist()} for d in ('logo', 'icons', 'banners', 'menu'): (OUT / d).mkdir(parents=True, exist_ok=True) # --- wordmark: CREATE in brass, RP in brick red, the motto underneath ------------------------- def wordmark(s: int) -> Image.Image: return beside([lettering(mask_of(font, 'CREATE', True), brass, s, depth=1), lettering(mask_of(font, 'RP', True), BRICK, s, depth=1)], gap=s * 2) def motto(s: int, colour=CREAM) -> Image.Image: return lettering(mask_of(font, TAGLINE, False), colour, s, depth=0) def mono(s: int, colour) -> Image.Image: return lettering(mask_of(font, NAME, True), colour, s, depth=0, outline=False) wordmark(12).save(OUT / 'logo' / 'wordmark.png') stack([wordmark(12), motto(4)], gap=20).save(OUT / 'logo' / 'logo.png') mono(12, (255, 255, 255)).save(OUT / 'logo' / 'wordmark-white.png') mono(12, INK).save(OUT / 'logo' / 'wordmark-dark.png') # --- marks and icons -------------------------------------------------------------------------- emblem = pixelate(Image.open(emblem_raw), 128) if emblem_raw and emblem_raw.exists() else None if emblem: emblem.resize((512, 512), Image.NEAREST).save(OUT / 'logo' / 'emblem.png') gear(32).resize((512, 512), Image.NEAREST).save(OUT / 'logo' / 'gear.png') on_plate(gear(28), 64).save(OUT / 'icons' / 'server-icon.png') # Minecraft server list: exactly 64x64 on_plate(gear(28), 512).save(OUT / 'icons' / 'avatar-512.png') # Gitea, Discord, the modpack gear(16).save(OUT / 'icons' / 'favicon-16x16.png') # game window icon gear(32).save(OUT / 'icons' / 'favicon-32x32.png') # --- banners ---------------------------------------------------------------------------------- art = Image.open(key_art).convert('RGB') night = np.asarray(art.resize((64, 36))).mean() < 70 # a night frame is dark enough: shade it only a little mark = emblem if emblem else gear(32) def banner(w: int, h: int, name: str, extra: str = '', focus_y: float = 0.5) -> None: base = shade(cover(art, w, h, focus_y), *((0.80, 1.0) if night else (0.55, 0.85))) logo = fit(wordmark(1), int(w * 0.62), int(h * 0.26)) s = logo.width // wordmark(1).width lines = [logo, fit(motto(1), int(w * 0.62), max(8, s * 4))] if extra: lines.append(fit(lettering(mask_of(font, extra, False), BRASS[3], 1, depth=0), int(w * 0.5), max(8, s * 4))) block = stack(lines, gap=max(6, s * 2)) base.alpha_composite(block, ((w - block.width) // 2, int(h * 0.10))) addr = fit(lettering(mask_of(font, ADDRESS, False), CREAM, 1, depth=0), int(w * 0.45), max(8, s * 3)) base.alpha_composite(addr, ((w - addr.width) // 2, h - addr.height - int(h * 0.06))) base.convert('RGB').save(OUT / 'banners' / name, quality=92) banner(960, 540, 'discord-banner.png') banner(1280, 720, 'launch.png', extra='ВІДКРИТТЯ СЕРВЕРА') banner(1200, 630, 'invite.png', extra='ПРИЄДНУЙСЯ') banner(1280, 320, 'wiki-cover.png', focus_y=0.55) # --- FancyMenu: title screen background, the logo it shows, window icons ------------------------- shade(cover(art, 1920, 1080), *((0.95, 1.0) if night else (0.80, 0.92))).convert('RGB').save(OUT / 'menu' / 'background.png') shade(cover(art, 1920, 1080), 0.42, 0.42).convert('RGB').save(OUT / 'menu' / 'background_dim.png') # behind "Connecting…" stack([wordmark(8), motto(3)], gap=12).save(OUT / 'menu' / 'logo.png') # --- every button of the game: andesite casing, brass casing under the cursor --------------------------------- # EMI: its grey recipe panels and slots in cream, its small buttons in brass if emi_jar: with zipfile.ZipFile(emi_jar) as emi, zipfile.ZipFile(create_jar) as cr2: andesite = (tuple(int(v) for v in casing_tile[1, 8]), tuple(int(v) for v in casing_tile[14, 8])) brass_tile = texture(cr2, 'assets/create/textures/block/brass_casing.png').astype(int) for name, make in (('buttons', lambda s: casing_buttons(s, casing_wood, brass_wood, andesite, (casing_tile, brass_tile))), ('background', lambda s: casingify(s, casing_wood, andesite, face=(222, 208, 178))), ('widgets', lambda s: greys_to(s, CREAM))): sprite = Image.open(io.BytesIO(emi.read(f'assets/emi/textures/gui/{name}.png'))) target = OUT / 'resources' / 'emi' / 'textures' / 'gui' / f'{name}.png' target.parent.mkdir(parents=True, exist_ok=True) make(sprite).save(target) # the player list (Tab) as an andesite casing — drawn by the createrp_client mod with these two GUI sprites sprites = OUT / 'resources' / 'createrp' / 'textures' / 'gui' / 'sprites' sprites.mkdir(parents=True, exist_ok=True) Image.fromarray(np.clip(casing_wood / 0.8 * 0.55, 0, 255).astype(np.uint8), 'RGB').save(sprites / 'tab_wood.png') (sprites / 'tab_wood.png.mcmeta').write_text('{"gui": {"scaling": {"type": "tile", "width": 16, "height": 16}}}\n', encoding='utf-8', newline='\n') frame = np.zeros((32, 32, 4), np.uint8) frame[..., 3] = 255 frame[4:28, 4:28, 3] = 0 # the middle shows the wood and the list for i in range(3): frame[1 + i, 1:31, :3] = np.tile(casing_tile[i, 3:13], (4, 1))[:30] frame[30 - i, 1:31, :3] = np.tile(casing_tile[15 - i, 3:13], (4, 1))[:30] frame[1:31, 1 + i, :3] = np.tile(casing_tile[3:13, i], (4, 1))[:30] frame[1:31, 30 - i, :3] = np.tile(casing_tile[3:13, 15 - i], (4, 1))[:30] for (y, x), (ty, tx) in (((1, 1), (0, 0)), ((1, 28), (0, 13)), ((28, 1), (13, 0)), ((28, 28), (13, 13))): frame[y:y + 3, x:x + 3, :3] = casing_tile[ty:ty + 3, tx:tx + 3] Image.fromarray(frame, 'RGBA').save(sprites / 'tab_frame.png') # a player's row: a cell sunk into the casing — andesite rim lit from below (shadow on top and left, light on the # bottom and right), inside the same wood, darker. 34 px wide so the 32 px middle repeats the 16 px wood seamlessly. rim_light, rim_dark = casing_tile[1, 8], casing_tile[14, 8] row = np.zeros((8, 34, 4), np.uint8) row[..., 3] = 255 row[1:7, 1:33, :3] = np.clip(np.tile(casing_wood / 0.8, (1, 3, 1))[2:8, :32] * 0.45, 0, 255) row[0, :, :3] = np.clip(rim_dark * 0.7, 0, 255) row[:, 0, :3] = np.clip(rim_dark * 0.7, 0, 255) row[7, 1:, :3] = rim_light row[1:, 33, :3] = rim_light Image.fromarray(row, 'RGBA').save(sprites / 'tab_row.png') (sprites / 'tab_row.png.mcmeta').write_text( '{"gui": {"scaling": {"type": "nine_slice", "width": 34, "height": 8, "border": 1}}}\n', encoding='utf-8', newline='\n') (sprites / 'tab_frame.png.mcmeta').write_text( '{"gui": {"scaling": {"type": "nine_slice", "width": 32, "height": 32, "border": 4}}}\n', encoding='utf-8', newline='\n') # branding/resources//… goes into the game as kubejs/assets//… for path, sprite in gui.items(): target = OUT / 'resources' / 'minecraft' / 'textures' / 'gui' / path target.parent.mkdir(parents=True, exist_ok=True) sprite.save(target) if path in meta: target.with_name(target.name + '.mcmeta').write_text(meta[path], encoding='utf-8', newline='\n') # --- the player list (Tab): pictures shown as characters of a font of ours, createrp:tab ------------------------- # Drawn three texels per GUI pixel, so they are pixel for pixel at GUI scale 3. The bridge mod sends the characters. tab_logo = stack([wordmark(6), motto(3)], gap=9) line = Image.new('RGBA', (tab_logo.width, 21)) for x in range(tab_logo.width // 10, tab_logo.width - tab_logo.width // 10): for y in range(9, 12): line.putpixel((x, y), BRASS[2] + (255,)) for y in range(12, 15): line.putpixel((x, y), BRASS[0] + (255,)) cog = gear(7).resize((21, 21), Image.NEAREST) line.alpha_composite(cog, ((line.width - 21) // 2, 0)) header = stack([tab_logo, line], gap=9) header = stack([header, Image.new('RGBA', (1, -header.height % 3))], gap=0) font_dir = OUT / 'resources' / 'createrp' (font_dir / 'textures' / 'font').mkdir(parents=True, exist_ok=True) (font_dir / 'font').mkdir(parents=True, exist_ok=True) header.save(font_dir / 'textures' / 'font' / 'tab_header.png') providers = [{'type': 'bitmap', 'file': 'createrp:font/tab_header.png', 'height': header.height // 3, 'ascent': header.height // 3 - 2, 'chars': ['\ue000']}] for char, name, rows in (('\ue001', 'sun', SUN_ICON), ('\ue002', 'moon', MOON_ICON)): icon = button_icon(rows, canvas=8, at=0).resize((24, 24), Image.NEAREST) icon.save(font_dir / 'textures' / 'font' / f'tab_{name}.png') providers.append({'type': 'bitmap', 'file': f'createrp:font/tab_{name}.png', 'height': 8, 'ascent': 7, 'chars': [char]}) (font_dir / 'font' / 'tab.json').write_text(json.dumps({'providers': providers}, indent=2), encoding='utf-8', newline='\n') print('player list header:', header.size, '-> GUI', header.width // 3, 'x', header.height // 3) # --- warning icons for the HUD: branding/hud/-.png, 16 x 16 ------------------------------------ (OUT / 'hud').mkdir(parents=True, exist_ok=True) for colour, (main, dim) in HUD_COLOURS.items(): # not 'shade': that name is a function used above ICON_COLOURS.update({'C': main, 'c': dim, 'W': (245, 240, 225), 'K': (40, 30, 25)}) for name, rows in HUD_ICONS.items(): button_icon(rows, outline=True, canvas=16, at=1).save(OUT / 'hud' / f'{name}-{colour}.png') button_icon(QUIT_ICON, canvas=24).save(OUT / 'menu' / 'quit.png') # the corner buttons are 24 x 24 on_canvas(gear_icon(14), 24).save(OUT / 'menu' / 'settings.png') for name, rows in (('online', ONLINE_ICON), ('offline', OFFLINE_ICON), ('maintenance', MAINTENANCE_ICON)): button_icon(rows, outline=True, at=4).save(OUT / 'menu' / f'status-{name}.png') print('done:', ', '.join(sorted(str(p.relative_to(OUT)).replace('\\', '/') for p in OUT.rglob('*.png')))) if __name__ == '__main__': main()