extends RefCounted ## Pinta fachadas simples de casas de bairro para os planos distantes, e as ## texturas de asfalto e calçada. Tudo determinístico a partir de uma seed. ## ## As fachadas distantes são geradas uma vez por `tools/generate_backgrounds.gd` ## e salvas em assets/backgrounds/. Se os PNGs não existirem, a cena gera as ## mesmas imagens em memória (mesma função, mesmas seeds). const FACADE_SIZE := Vector2i(256, 192) const FACADE_VARIANTS := 8 const WALL_COLORS := [ Color("#E9C46A"), Color("#F4A261"), Color("#9BC1BC"), Color("#E5989B"), Color("#A8DADC"), Color("#F1EDE4"), Color("#B5C99A"), Color("#CDB4DB"), Color("#FFD6A5"), Color("#D9CAB3"), ] const BRICK := Color("#B8673F") static func facade_file_name(variant: int) -> String: return "facade_%02d.png" % variant ## Fachada opaca (sem transparência): casa de laje com platibanda, comum em ## bairros brasileiros. Variantes ímpares podem ser de tijolo aparente. static func paint_facade(variant: int) -> Image: var rng := RandomNumberGenerator.new() rng.seed = 7919 * (variant + 1) var w := FACADE_SIZE.x var h := FACADE_SIZE.y var img := Image.create(w, h, false, Image.FORMAT_RGB8) var brick := variant % 4 == 3 var wall: Color = BRICK if brick else WALL_COLORS[rng.randi() % WALL_COLORS.size()] img.fill(wall) if brick: for y in range(0, h, 6): img.fill_rect(Rect2i(0, y, w, 1), wall.darkened(0.25)) _noise(img, rng, 0.05) # Platibanda (faixa do topo) e caixa d'água ocasional. var parapet := int(h * 0.12) img.fill_rect(Rect2i(0, 0, w, parapet), wall.lightened(0.18) if not brick else Color("#C9C2B5")) img.fill_rect(Rect2i(0, parapet, w, 3), wall.darkened(0.3)) # Dois andares em parte das variantes. var floors := 2 if rng.randf() < 0.6 else 1 var floor_h := (h - parapet) / floors for f in floors: var top := parapet + f * floor_h var is_ground := f == floors - 1 var windows := 2 + rng.randi() % 2 var slot := w / (windows + (1 if is_ground else 0)) for i in windows + (1 if is_ground else 0): var cx := int(slot * (i + 0.5)) if is_ground and i == int((windows + 1) / 2): # Porta ou portão de garagem. var dw := int(slot * 0.45) var dh := int(floor_h * 0.78) var door_color := Color("#6B4F3A") if rng.randf() < 0.5 else Color("#7C8288") img.fill_rect(Rect2i(cx - dw / 2 - 2, top + floor_h - dh - 2, dw + 4, dh + 2), Color("#EDEDED")) img.fill_rect(Rect2i(cx - dw / 2, top + floor_h - dh, dw, dh), door_color) continue var ww := int(slot * 0.5) var wh := int(floor_h * 0.42) var wy := top + int(floor_h * 0.25) img.fill_rect(Rect2i(cx - ww / 2 - 3, wy - 3, ww + 6, wh + 6), Color("#F2F2F2")) img.fill_rect(Rect2i(cx - ww / 2, wy, ww, wh), Color("#2F3E4E").lerp(Color("#5B7A99"), rng.randf() * 0.5)) img.fill_rect(Rect2i(cx - 1, wy, 2, wh), Color("#F2F2F2")) if not is_ground: # Linha da laje entre andares. img.fill_rect(Rect2i(0, top + floor_h - 3, w, 3), wall.darkened(0.22)) # Rodapé img.fill_rect(Rect2i(0, h - 6, w, 6), wall.darkened(0.35)) return img static func paint_asphalt(seed_value: int) -> Image: var rng := RandomNumberGenerator.new() rng.seed = seed_value var img := Image.create(256, 256, false, Image.FORMAT_RGB8) img.fill(Color(0.29, 0.29, 0.3)) _noise(img, rng, 0.07) # Remendos discretos para dar referência de movimento. for i in 6: var r := Rect2i(rng.randi_range(0, 200), rng.randi_range(0, 200), rng.randi_range(20, 56), rng.randi_range(14, 40)) img.fill_rect(r, Color(0.25, 0.25, 0.26).lerp(Color(0.34, 0.34, 0.35), rng.randf())) _noise(img, rng, 0.03) img.generate_mipmaps() return img static func paint_sidewalk(seed_value: int) -> Image: var rng := RandomNumberGenerator.new() rng.seed = seed_value var img := Image.create(256, 256, false, Image.FORMAT_RGB8) img.fill(Color(0.74, 0.72, 0.68)) _noise(img, rng, 0.05) # Juntas das placas de concreto (a textura cobre 2 m x 2 m). for k in [0, 128]: img.fill_rect(Rect2i(k, 0, 3, 256), Color(0.55, 0.53, 0.5)) img.fill_rect(Rect2i(0, k, 256, 3), Color(0.55, 0.53, 0.5)) img.generate_mipmaps() return img static func _noise(img: Image, rng: RandomNumberGenerator, amount: float) -> void: for y in img.get_height(): for x in img.get_width(): var c := img.get_pixel(x, y) var n := (rng.randf() - 0.5) * 2.0 * amount img.set_pixel(x, y, Color(clampf(c.r + n, 0, 1), clampf(c.g + n, 0, 1), clampf(c.b + n, 0, 1)))