import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np

fig, (ax_prof, ax_plan) = plt.subplots(2, 1, figsize=(14, 10), facecolor='#1e222b')

# Setup axes
for ax in [ax_prof, ax_plan]:
    ax.set_facecolor('#14171f')
    ax.tick_params(colors='#8e9aaf', labelsize=9)
    for spine in ax.spines.values():
        spine.set_color('#3a4150')

# ==================== 1. PERFIL LONGITUDINAL ====================
ax_prof.set_title("1. PERFIL LONGITUDINAL E ELEVAÇÃO (Saveiro 31.5ft - Matheus Silva)", color='#00adb5', fontsize=13, fontweight='bold', pad=12)
ax_prof.set_xlim(-0.8, 10.5)
ax_prof.set_ylim(-1.8, 3.2)
ax_prof.set_xlabel("Comprimento (m) [0 = Painel de Popa | 9.60 = Roda de Proa]", color='#8e9aaf', fontsize=9)
ax_prof.set_ylabel("Altura / Calado (m)", color='#8e9aaf', fontsize=9)

# Linha d'água
ax_prof.axhline(0, color='#00bcd4', linestyle='--', linewidth=1.5, label="Linha d'Água (WL)")

# Casco (Perfil)
x_deck = np.array([0.0, 2.0, 5.0, 8.0, 9.60])
y_deck = np.array([0.80, 0.65, 0.50, 0.75, 1.15]) # Borda livre

x_bottom = np.array([0.0, 1.2, 3.5, 7.0, 9.60])
y_bottom = np.array([0.1, -0.45, -0.85, -0.60, 1.15])

# Desenho casco perfil
ax_prof.plot(x_deck, y_deck, color='#eeeeee', linewidth=2)
ax_prof.plot(x_bottom, y_bottom, color='#eeeeee', linewidth=2)
ax_prof.plot([0, 0], [0.1, 0.80], color='#eeeeee', linewidth=2) # Painel popa

# Casaria / Cabine (Trunk Cabin)
x_cab = [3.6, 3.8, 7.6, 7.9]
y_cab = [0.55, 1.25, 1.10, 0.75]
ax_prof.fill(x_cab, y_cab, color='#2d4059', alpha=0.85, edgecolor='#00adb5', linewidth=1.5)
# Vigias
for vx in [4.3, 5.1, 5.9, 6.7]:
    ax_prof.add_patch(patches.Ellipse((vx, 0.90), 0.35, 0.18, color='#00bcd4', alpha=0.7))

# Quilha corrida e lastro
x_keel = [1.5, 2.5, 6.5, 7.2]
y_keel = [-0.5, -1.10, -1.10, -0.60]
ax_prof.fill(x_keel, y_keel, color='#e84545', alpha=0.8, edgecolor='#ffffff', linewidth=1.2)
ax_prof.text(4.5, -0.85, "Quilha Corrida & Lastro (1.400 kg)", color='#ffffff', fontsize=9, fontweight='bold', ha='center')

# Leme e Hélice
ax_prof.add_patch(patches.Rectangle((-0.3, -1.05), 0.3, 1.5, color='#8d5524', edgecolor='#fff'))
ax_prof.plot([1.2, 1.5], [-0.55, -0.55], color='#f9d342', linewidth=3)
ax_prof.scatter([1.3], [-0.55], color='#f9d342', s=120, zorder=5)
ax_prof.text(1.3, -0.35, "Hélice", color='#f9d342', fontsize=8, ha='center')
ax_prof.text(-0.15, 0.6, "Leme", color='#ffffff', fontsize=8, ha='center')

# Motor
ax_prof.add_patch(patches.Rectangle((2.8, -0.2), 0.9, 0.65, color='#ff5722', alpha=0.9, edgecolor='#fff'))
ax_prof.text(3.25, 0.1, "Motor\n40 HP", color='#fff', fontsize=8, fontweight='bold', ha='center', va='center')

# Textos Perfil
ax_prof.text(8.5, 0.4, "Cama Proa (V)", color='#00adb5', fontsize=8.5, ha='center')
ax_prof.text(6.0, 0.4, "Salão / Mesa", color='#00adb5', fontsize=8.5, ha='center')
ax_prof.text(4.5, 0.2, "WC / Cozinha", color='#00adb5', fontsize=8.5, ha='center')
ax_prof.text(1.8, 0.2, "Cockpit / Pesca", color='#00adb5', fontsize=8.5, ha='center')


# ==================== 2. PLANTA DE ARRANJO GERAL ====================
ax_plan.set_title("2. PLANTA BAIXA DO ARRANJO GERAL (Convés, Cabine & Praça de Pesca)", color='#00adb5', fontsize=13, fontweight='bold', pad=12)
ax_plan.set_xlim(-0.8, 10.5)
ax_plan.set_ylim(-2.2, 2.2)
ax_plan.set_xlabel("Comprimento (m)", color='#8e9aaf', fontsize=9)
ax_plan.set_ylabel("Boca / Largura (m)", color='#8e9aaf', fontsize=9)

# Curva do Casco na Planta
x_half = np.linspace(0, 9.6, 100)
# Perfil parabólico clássico de saveiro (boca máx 3.25 em ~5.2m)
y_half = 1.625 * np.sin(np.pi * x_half / 9.6)**0.75

ax_plan.plot(x_half, y_half, color='#eeeeee', linewidth=2.5)
ax_plan.plot(x_half, -y_half, color='#eeeeee', linewidth=2.5)
ax_plan.plot([0, 0], [-y_half[0], y_half[0]], color='#eeeeee', linewidth=2.5)

# Divisória Proa / Salão (x=7.5)
ax_plan.plot([7.5, 7.5], [-1.3, 1.3], color='#393e46', linewidth=2)

# 1. Cama de Proa em V
ax_plan.fill([7.5, 9.1, 7.5], [-1.1, 0, 1.1], color='#2d4059', edgecolor='#00adb5', linewidth=1.5)
ax_plan.text(8.0, 0, "Cama Casal (V)\n2,0m x 1,6m", color='#ffffff', fontsize=9, fontweight='bold', ha='center', va='center')
ax_plan.text(9.2, 0, "Paiol\nAmarra", color='#00adb5', fontsize=7.5, ha='center', va='center')

# 2. Salão Central (x: 5.6 a 7.5)
# Mesa
ax_plan.add_patch(patches.Rectangle((5.9, -0.4), 1.2, 0.8, color='#8d5524', edgecolor='#fff'))
ax_plan.text(6.5, 0, "Mesa Refeições", color='#fff', fontsize=8.5, ha='center', va='center')
# Sofá Boreste
ax_plan.add_patch(patches.Rectangle((5.7, 0.65), 1.6, 0.65, color='#00adb5', alpha=0.7, edgecolor='#fff'))
ax_plan.text(6.5, 0.98, "Sofá / Cama Solteiro", color='#fff', fontsize=8, ha='center', va='center')
# Sofá Bombordo
ax_plan.add_patch(patches.Rectangle((5.7, -1.3), 1.6, 0.65, color='#00adb5', alpha=0.7, edgecolor='#fff'))
ax_plan.text(6.5, -0.98, "Sofá / Cama Solteiro", color='#fff', fontsize=8, ha='center', va='center')

# Divisória Salão / Serviço (x=5.5)
ax_plan.plot([5.5, 5.5], [-1.55, 1.55], color='#393e46', linestyle='--', linewidth=1.5)

# 3. Banheiro Fechado (Boreste, x: 4.0 a 5.4, y: 0.2 a 1.45)
ax_plan.add_patch(patches.Rectangle((4.0, 0.25), 1.4, 1.2, color='#2b323c', edgecolor='#00bcd4', linewidth=1.5))
ax_plan.add_patch(patches.Circle((4.4, 0.65), 0.2, color='#eeeeee')) # Vaso
ax_plan.add_patch(patches.Circle((5.1, 1.05), 0.15, color='#00bcd4')) # Pia
ax_plan.text(4.7, 1.15, "Banheiro c/\nChuveiro", color='#00bcd4', fontsize=8, ha='center', va='center')

# 4. Cozinha / Galley (Bombordo, x: 4.0 a 5.4, y: -1.45 a -0.25)
ax_plan.add_patch(patches.Rectangle((4.0, -1.45), 1.4, 1.2, color='#2b323c', edgecolor='#f9d342', linewidth=1.5))
ax_plan.add_patch(patches.Rectangle((4.2, -1.35), 0.45, 0.35, color='#e84545')) # Fogão
ax_plan.add_patch(patches.Rectangle((4.8, -1.35), 0.4, 0.35, color='#00bcd4')) # Pia
ax_plan.add_patch(patches.Rectangle((4.4, -0.85), 0.7, 0.45, color='#f9d342', alpha=0.8)) # Geladeira 12V
ax_plan.text(4.7, -0.5, "Cozinha & Geladeira", color='#f9d342', fontsize=8, ha='center', va='center')

# Escada de Descida
ax_plan.add_patch(patches.Rectangle((3.6, -0.3), 0.4, 0.6, color='#8d5524', edgecolor='#fff'))
ax_plan.text(3.8, 0, "Escada", color='#fff', fontsize=7, ha='center', va='center')

# 5. Cockpit & Praça de Pesca (x: 0.5 a 3.5)
# Bancos laterais
ax_plan.add_patch(patches.Rectangle((0.6, 0.7), 2.8, 0.6, color='#393e46', edgecolor='#00adb5', linewidth=1.2))
ax_plan.add_patch(patches.Rectangle((0.6, -1.3), 2.8, 0.6, color='#393e46', edgecolor='#00adb5', linewidth=1.2))
ax_plan.text(2.0, 1.0, "Banco Estofado (Paiol Sob)", color='#eeeeee', fontsize=8, ha='center', va='center')
ax_plan.text(2.0, -1.0, "Banco Estofado (Paiol Sob)", color='#eeeeee', fontsize=8, ha='center', va='center')

# Caixa de Peixe / Geleira Popa
ax_plan.add_patch(patches.Rectangle((0.3, -0.45), 0.5, 0.9, color='#00bcd4', alpha=0.9, edgecolor='#fff'))
ax_plan.text(0.55, 0, "Geleira /\nPeixe", color='#ffffff', fontsize=7.5, fontweight='bold', ha='center', va='center')

# Praça livre central
ax_plan.text(2.0, 0, "PRAÇA DE POPA DESIMPEDIDA\n(Pesca, Lazer & Convívio até 10 pessoas)", color='#00adb5', fontsize=9, fontweight='bold', ha='center', va='center')

# Roda de Leme / Comando
ax_plan.add_patch(patches.Circle((1.1, 0), 0.25, color='none', edgecolor='#f9d342', linewidth=2))
ax_plan.text(1.1, 0.4, "Posto Comando", color='#f9d342', fontsize=7.5, ha='center')

plt.tight_layout()
plt.savefig('/home/magdalena/eee/alunos/matheus-silva/arranjo_geral.png', dpi=200, bbox_inches='tight')
print("Imagem do Arranjo Geral salva com sucesso!")
