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

plt.style.use('seaborn-v0_8-whitegrid' if 'seaborn-v0_8-whitegrid' in plt.style.available else 'default')
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(16, 15), dpi=300)

c_hull1 = '#1E3A8A'      # Azul Marinho (Saveiro)
c_hull2 = '#047857'      # Verde Garrafa (Catboat)
c_hull3 = '#9A3412'      # Ocre / Marrom Telha (Llaüt Mediterrâneo)
c_wood = '#B45309'       # Madeira
c_sail = '#FEF3C7'       # Lona clara
c_wl = '#0284C7'         # Linha d'Água
c_bottom = '#B91C1C'     # Vermelho vivo

# -------------------------------------------------------------------------
# 1. SAVEIRO DE UMA VELA DE PENA (6,30 m — Bahia, Brasil)
# -------------------------------------------------------------------------
ax1.set_title("1. SAVEIRO DE UMA VELA DE PENA (6,30 m — Bahia, Brasil)\nArmação Latina Baiana | Fundo Chato Rasa Maré | 1 Vela de Pena (21,5 m²) | Motor 10-14 CV", fontsize=10, fontweight='bold', color='#0F172A', pad=6)

xs1 = np.linspace(0, 6.30, 80)
sheer1 = 0.65 + 0.35 * (xs1 / 6.30)**2.2
ax1.fill(np.concatenate([xs1, [6.30, 5.5, 3.0, 0, 0]]),
         np.concatenate([sheer1, [1.00, -0.20, -0.45, -0.40, 0.65]]),
         color=c_hull1, edgecolor='black', lw=1.5)
ax1.fill([0, 0, 3.0, 5.5, 5.9, 0], [0, -0.40, -0.45, -0.20, 0, 0], color=c_bottom, alpha=0.85)
ax1.axhline(0, color=c_wl, lw=1.2, linestyle='--')

# Mastro e Pena 6,30m (P = 7,80 m | E = 5,90 m)
ax1.plot([4.10, 3.90], [-0.40, 3.80], color=c_wood, lw=5)
ax1.plot([6.10, 0.40], [0.85, 6.20], color='#78350F', lw=4)
ax1.fill([6.10, 0.40, 0.20, 6.10], [0.85, 6.20, 0.90, 0.85], color=c_sail, edgecolor='#D97706', lw=1.2)
ax1.text(2.6, 3.2, "Vela de Pena Latina\n(21,5 m²)", ha='center', fontsize=7.5, fontweight='bold', color='#78350F')

ax1.set_xlim(-0.8, 8.5)
ax1.set_ylim(-1.0, 7.2)
ax1.set_aspect('equal')
ax1.axis('off')
ax1.text(0, -0.85, "LOA: 6,30 m | Boca: 2,40 m | Calado: 0,45 m | Peso: ~2,0 t | Lastro interno de pedras | Encalha reto na praia rasa", fontsize=7.5, fontweight='bold', color='#0F172A')

# -------------------------------------------------------------------------
# 2. CAPE COD CATBOAT (Marshall 22 / 6,50 m — EUA)
# -------------------------------------------------------------------------
ax2.set_title("2. CAPE COD CATBOAT (6,50 m — Nova Inglaterra, EUA)\nArmação Áurica (Gaff Rig) | Boca Gigante (3,10 m) | Bolina Retrátil | 1 Só Vela Grande (36 m²)", fontsize=10, fontweight='bold', color='#0F172A', pad=6)

xs2 = np.linspace(0, 6.50, 80)
sheer2 = 0.70 + 0.45 * (xs2 / 6.50)**2.2
ax2.fill(np.concatenate([xs2, [6.50, 5.8, 3.2, 0, 0]]),
         np.concatenate([sheer2, [1.15, -0.20, -0.58, -0.50, 0.70]]),
         color=c_hull2, edgecolor='black', lw=1.5)
ax2.fill([0, 0, 3.2, 5.8, 6.1, 0], [0, -0.50, -0.58, -0.20, 0, 0], color=c_bottom, alpha=0.85)
ax2.axhline(0, color=c_wl, lw=1.2, linestyle='--')

# Bolina
ax2.add_patch(patches.Polygon([[3.0, -0.55], [3.6, -0.55], [3.3, -1.45]], closed=True, facecolor='#1E293B', edgecolor='black', lw=1.2))

# Mastro no bico e vela áurica
mast2_x = 5.80
ax2.plot([mast2_x, mast2_x - 0.20], [-0.30, 7.20], color=c_wood, lw=6)
ax2.plot([mast2_x - 0.10, -0.40], [1.25, 0.95], color=c_wood, lw=4) # Retranca
ax2.plot([mast2_x - 0.20, 1.80], [6.50, 6.80], color='#78350F', lw=3.5) # Carangueja
ax2.fill([mast2_x - 0.10, mast2_x - 0.20, 1.80, -0.35, mast2_x - 0.10],
         [1.25, 6.50, 6.80, 1.00, 1.25], color=c_sail, edgecolor='#047857', lw=1.2)
ax2.text(2.8, 3.8, "Vela Áurica (Gaff)\n(36,0 m²)", ha='center', fontsize=7.5, fontweight='bold', color='#047857')

ax2.set_xlim(-0.8, 8.5)
ax2.set_ylim(-1.6, 7.5)
ax2.set_aspect('equal')
ax2.axis('off')
ax2.text(0, -0.95, "LOA: 6,50 m | Boca: 3,10 m | Calado: 0,60 m a 1,55 m | Peso: ~2,5 t | Estabilidade de forma (super largo) | Bolina móvel", fontsize=7.5, fontweight='bold', color='#0F172A')

# -------------------------------------------------------------------------
# 3. LLAÜT MEDITERRÂNEO (6,30 m — Ilhas Baleares / Catalunha, Espanha)
# -------------------------------------------------------------------------
ax3.set_title("3. LLAÜT TRADICIONAL (6,30 m — Maiorca / Baleares, Espanha)\nPopa Fina (Double-Ender) | Roda de Proa Alta com 'Tombete' | Vela Latina Clássica (24 m²)", fontsize=10, fontweight='bold', color='#0F172A', pad=6)

xs3 = np.linspace(0, 6.30, 80)
# Proa e Popa simétricas / curvas (double-ender)
sheer3 = 0.80 + 0.35 * (np.abs(xs3 - 3.15)/3.15)**2.2
ax3.fill(np.concatenate([xs3, [6.30, 5.5, 3.15, 0.8, 0, 0]]),
         np.concatenate([sheer3, [1.15, -0.30, -0.70, -0.30, 0.85, 0.80]]),
         color=c_hull3, edgecolor='black', lw=1.5)
ax3.fill([0, 0.8, 3.15, 5.5, 6.1, 0], [0, -0.30, -0.70, -0.30, 0, 0], color=c_bottom, alpha=0.85)
ax3.axhline(0, color=c_wl, lw=1.2, linestyle='--')

# Roda de proa tradicional com cap-de-fibló (tombete saliente)
ax3.plot([6.1, 6.45], [0.8, 1.45], color='#78350F', lw=5) # Roda de proa saliente
ax3.plot([0.0, -0.25], [0.6, 1.20], color='#78350F', lw=4.5) # Cadaste de popa saliente

# Mastro central inclinado para a vante (característica latina do Mediterrâneo)
mast3_x = 3.30
ax3.plot([mast3_x, mast3_x + 0.35], [-0.60, 4.20], color=c_wood, lw=5.5)

# Antena / Pena latina mediterrânea (P = 8,20 m)
ax3.plot([6.20, 0.20], [0.70, 6.60], color='#78350F', lw=4)
ax3.fill([6.20, 0.20, 0.30, 6.20], [0.70, 6.60, 0.85, 0.70], color=c_sail, edgecolor='#9A3412', lw=1.2)
ax3.text(2.8, 3.4, "Vela Latina Mediterrânea\n(24,0 m²)", ha='center', fontsize=7.5, fontweight='bold', color='#9A3412')

ax3.set_xlim(-0.8, 8.5)
ax3.set_ylim(-1.0, 7.5)
ax3.set_aspect('equal')
ax3.axis('off')
ax3.text(0, -0.85, "LOA: 6,30 m | Boca: 2,42 m | Calado: 0,65 m | Peso: ~2,2 t | Popa fina corta-marola | Quilha de quilhão fixo | Motor Diesel 15 CV", fontsize=7.5, fontweight='bold', color='#0F172A')

plt.tight_layout()
output_3boats = "/home/magdalena/eee/alunos/alberico-de-carvalho-santiago/comparativo_3_veleiros_tradicionais.png"
plt.savefig(output_3boats, dpi=300, bbox_inches='tight')
plt.close()
print("Comparativo de 3 veleiros gerado com sucesso!")
