"""Regenera los PNG originales de Level02 con Pillow. Uso: python tools/generate_city_art.py Pillow solo se necesita para regenerar arte; Godot utiliza los PNG exportados. Se dibuja sobre una cuadricula de baja resolucion y se amplia con NEAREST.""" from __future__ import annotations import random from pathlib import Path from PIL import Image, ImageDraw, ImageFont ROOT = Path(__file__).resolve().parents[1] / 'assets' / 'city' ROOT.mkdir(parents=True, exist_ok=True) SCALE = 2 W, H = 512, 640 # 1024x1280 unidades tras ampliar sin suavizado. INK = '#171d31' SKY = ['#181e38', '#242844', '#32334f', '#4d4159', '#67505d'] FAR = ['#2b3048', '#30354e', '#353a53', '#3c3c54'] MID = ['#424358', '#4b495e', '#545065', '#5c5265'] NEAR = ['#51546a', '#5b576d', '#64596d', '#656273', '#565b70'] WINDOW_DARK = ['#292f47', '#34384c', '#373a50'] WINDOW_LIT = ['#e5b878', '#edcf91', '#ad9da0', '#ae8e78'] FONT_PATH = Path(__file__).resolve().parents[1] / 'assets' / 'fonts' / 'PixelOperator8.ttf' def image(mode='RGBA'): return Image.new(mode, (W, H), (0, 0, 0, 0)) def save(img, name, multiplier=SCALE): img.resize((img.width * multiplier, img.height * multiplier), Image.Resampling.NEAREST).save(ROOT / name, optimize=True) def blocks(d, x0, y0, x1, y1, fill, highlight=None, shadow=None): d.rectangle((x0, y0, x1, y1), fill=fill) if shadow: d.rectangle((x1 - 3, y0 + 3, x1, y1), fill=shadow) if highlight: d.rectangle((x0 + 2, y0 + 2, x1 - 5, y0 + 4), fill=highlight) def windows(d, x0, top, x1, bottom, rng, lit_probability, tiny=False): ww, wh = (3, 6) if tiny else (7, 10) dx, dy = (12, 16) if tiny else (19, 23) for yy in range(top + 20, bottom - wh - 15, dy): for xx in range(x0 + 9, x1 - ww - 6, dx): if rng.random() > .90: continue color = rng.choice(WINDOW_LIT) if rng.random() < lit_probability else rng.choice(WINDOW_DARK) d.rectangle((xx, yy, xx + ww, yy + wh), fill=color) if not tiny: d.line((xx + ww // 2, yy, xx + ww // 2, yy + wh), fill='#404057', width=2) d.rectangle((xx - 1, yy + wh + 1, xx + ww + 1, yy + wh + 2), fill='#35384c') # El fondo es totalmente opaco para evitar huecos transparentes al saltar alto. sky = Image.new('RGB', (W, H), SKY[-1]); d = ImageDraw.Draw(sky) for yy in range(H): s = yy / H stops = [0, .24, .47, .7, 1] for i in range(4): if stops[i] <= s <= stops[i + 1]: t = (s - stops[i]) / (stops[i + 1] - stops[i]) ca = tuple(bytes.fromhex(SKY[i][1:])); cb = tuple(bytes.fromhex(SKY[i+1][1:])) rgb = tuple(round(a * (1 - t) + b * t) for a,b in zip(ca,cb)) d.line((0,yy,W,yy),fill=rgb) break rng = random.Random(8173) for i in range(110): x,y = rng.randrange(W), rng.randrange(0,275) color = rng.choice(('#aaafc8','#888fad','#797f9d')) d.rectangle((x,y,x+(i%19==0),y+(i%23==0)),fill=color) # Resplandor desplazado y disco palido: tenues para no distraer del juego. for rad, col in [(55,'#524b69'), (42,'#655a74'),(30,'#847588'),(22,'#c2a39e')]: d.ellipse((410-rad,178-rad,410+rad,178+rad), fill=col) save(sky,'sky.png') # Siluetas de nubes: capa de parallax independiente con desplazamiento lento. clouds = image(); d=ImageDraw.Draw(clouds); rng=random.Random(97) for cx,cy,rw,rh in [(90,218,65,18),(300,340,82,19),(482,280,55,17),(196,419,67,17)]: for k in range(9): x = cx - rw + k * rw // 4 by = cy + rng.randint(-4,4) radius = rng.randint(rh-4,rh+8) d.rectangle((x,by-radius//2,x+rw//4+15,by+rh),fill='#48465d') d.ellipse((x,by-radius,x+2*radius,by+radius),fill='#55516a') d.rectangle((cx-rw+12,cy+rh,cx+rw+4,cy+rh+6), fill='#4e4c63') for ii in range(4): xx=cx-rw+25+ii*rw//3 d.rectangle((xx,cy+rh-3,xx+18,cy+rh-1),fill='#79738b') save(clouds,'clouds.png') # Siluetas de edificios repetibles en la union horizontal de 1024 unidades. far=image(); d=ImageDraw.Draw(far); rng=random.Random(190) x=0 while x85: d.rectangle((x+ww//2-15,y-17,x+ww//2+23,y-8),fill='#36394e') d.rectangle((x+ww//2-12,y-24,x+ww//2+20,y-18),fill='#5f6074') x=xx+1 save(mid,'skyline_mid.png') # Las fachadas son PNG transparentes reutilizables. Se colocan individualmente # en el editor sin regenerar una imagen enorme de todo el fondo. font=ImageFont.truetype(str(FONT_PATH), 11) if FONT_PATH.exists() else ImageFont.load_default() styles=[ ('SALA RUIDO', 108, 245, '#565369', '#8f596a'), ('GIRA 24H', 94, 207, '#5d5871', '#666e81'), ('NOISE SHOP', 132, 272, '#595b70', '#7a586e'), ('LOCAL 404', 112, 223, '#625969', '#af766a'), ('THRASH FM', 139, 295, '#56596e', '#73778e'), ('REHEARSAL', 120, 257, '#5d566e', '#86717c'), ] for idx,(sign,bw,bh,main,accent) in enumerate(styles): rng=random.Random(900+idx); img=Image.new('RGBA',(bw,bh),(0,0,0,0)); dd=ImageDraw.Draw(img) # Volumen principal y ladrillos pixelados. dd.rectangle((3,11,bw-3,bh-1),fill=main) dd.rectangle((0,7,bw-1,13),fill='#30364b') dd.rectangle((4,14,bw-6,17),fill='#787388') for yy in range(25,bh-19,12): for xx in range(7+(yy//12%2)*5,bw-7,19): dd.line((xx, yy,xx+11,yy),fill='#6a657a',width=1) windows(dd,2,15,bw-3,bh,rng,.45) # Escaparate, persianas enrollables y cartel de neon. dd.rectangle((8,bh-49,bw-9,bh-2),fill='#30344b') dd.rectangle((bw//2-15,bh-45,bw//2+14,bh-3),fill='#515064') dd.rectangle((bw//2-12,bh-43,bw//2+11,bh-6),fill='#242a40') dd.line((bw//2,bh-42,bw//2,bh-6),fill='#81798d',width=2) signw=min(bw-13, len(sign)*7 + 10) lx=(bw-signw)//2 dd.rectangle((lx,28,lx+signw,49), fill='#242a41') dd.rectangle((lx+2,30,lx+signw-2,47), outline=accent, width=2) if signw>20: bbox=dd.textbbox((0,0),sign,font=font) tw=bbox[2]-bbox[0] # Los textos demasiado largos se recortan deliberadamente. dd.text(((bw-tw)//2,32),sign,font=font,fill='#f7ca85') # Ventilacion, antena y salida de incendios. dd.rectangle((bw-20,1,bw-16,11),fill='#31384d') dd.rectangle((bw-26,1,bw-9,3),fill='#747082') dd.rectangle((bw-10,bh//2,bw-4,bh//2+41),fill='#3a4056') for yy in range(bh//2,bh//2+41,10): dd.line((bw-17,yy,bw-3,yy),fill='#777a8a',width=2) save(img,f'facade_{idx+1:02d}.png') # Texturas de terreno dibujadas pixel a pixel y repetibles en X/Y. road=Image.new('RGBA',(64,64),'#292f40');d=ImageDraw.Draw(road);rng=random.Random(87) for gy in range(0,64,16): for gx in range(0,64,32): xx=gx+((gy//16)%2)*12 d.line((xx,gy,xx+27,gy),fill='#3c4153',width=2) d.line((xx+2,gy+3,xx+2,gy+15),fill='#21283a') for i in range(33): x,y=rng.randrange(64),rng.randrange(64) d.rectangle((x,y,x+rng.randint(1,3),y+1),fill=rng.choice(('#3b3f50','#242b3a','#414456'))) save(road,'asphalt.png') curb=Image.new('RGBA',(64,12),'#777484'); d=ImageDraw.Draw(curb) d.rectangle((0,0,63,2),fill='#aea1a0');d.rectangle((0,3,63,6),fill='#8d8894');d.rectangle((0,9,63,11),fill='#3c4054') d.line((31,4,31,10),fill='#47495b',width=2) save(curb,'curb.png') pl=Image.new('RGBA',(64,12),'#51566c'); d=ImageDraw.Draw(pl) d.rectangle((0,0,63,2),fill='#bab4b3');d.rectangle((0,3,63,8),fill='#74798b') d.rectangle((0,9,63,11),fill='#30374d') for x in (4,27,50): d.rectangle((x,4,x+3,7), fill='#292f43') save(pl,'walkway.png') barrier=Image.new('RGBA',(24,80),'#303447'); d=ImageDraw.Draw(barrier) d.rectangle((0,0,23,3),fill='#e9be83') d.rectangle((2,6,21,77),fill='#444958') for y in (13,34,55): d.polygon([(2,y),(12,y-10),(22,y-10),(22,y-3),(9,y+6),(2,y+6)], fill='#b77e63') d.rectangle((0,77,23,79),fill='#202838') save(barrier,'barrier.png') # Decoracion compacta de acera, repetida con moderacion en la escena. lamp=Image.new('RGBA',(48,176),(0,0,0,0));d=ImageDraw.Draw(lamp) d.rectangle((25,27,28,175),fill='#373e56') d.rectangle((17,24,34,31),fill='#4f5267') d.rectangle((7,11,43,20),fill='#2b344a') d.rectangle((9,13,40,18),fill='#e4bd83') d.rectangle((13,20,36,25),fill='#676579') d.rectangle((19,172,35,175),fill='#353b4d') save(lamp,'streetlamp.png') print(f'Generated {len(list(ROOT.glob("*.png")))} original PNG assets in {ROOT}')