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 = plt.figure(figsize=(16, 12), dpi=300)

c_hull = '#1E293B'      # Grafite / Prata metálico escuro
c_silver = '#E2E8F0'    # Prata da casca
c_red = '#DC2626'       # Vermelho esportivo
c_orange = '#F97316'    # Faixa laranja
c_yellow = '#FBBF24'    # Faixa amarela
c_glass = '#38BDF8'     # Vidro azul espelhado
c_targa = '#EF4444'     # Arco targa vermelho
c_wl = '#0284C7'        # Linha d'água

# 1. VISTA LATERAL (PERFIL ESPORTIVO TIPO DOUBLE TROUBLE)
ax1 = fig.add_subplot(2, 1, 1)
ax1.set_title("1. PERFIL LONGITUDINAL (Side View) — POWERCAT 8,50 m ESTILO 'DOUBLE TROUBLE'\nProa Wave-Piercing Agressiva, Cabine Fechada com Hardtop e Arco Targa Esportivo", fontsize=11, fontweight='bold', color=c_hull, pad=10)

# Linha do Casco (Wave-Piercing com proa reta/invertida)
# Popa x=0, Borda x=0 a 8.5
x_hull_prof = [0, 0, 4.5, 7.8, 8.5, 8.3, 0]
y_hull_prof = [0.85, -0.55, -0.55, -0.3, 0.4, 0.95, 0.85]

# Preenchimento do Casco Prata
ax1.fill([0, 0, 4.5, 7.8, 8.5, 8.3, 0], [0.85, -0.55, -0.55, -0.3, 0.4, 0.95, 0.85], color=c_silver, edgecolor=c_hull, lw=2.5)

# Faixas Gráficas Laterais (Vermelho, Laranja, Amarelo - estilo Double Trouble)
ax1.plot([0.5, 7.5], [0.65, 0.75], color=c_red, lw=4)
ax1.plot([0.8, 7.2], [0.55, 0.65], color=c_orange, lw=3)
ax1.plot([1.2, 6.8], [0.47, 0.57], color=c_yellow, lw=2.5)
ax1.plot([8.2, 8.5], [0.75, 0.4], color=c_red, lw=4) # Bico de proa vermelho

# Cabine Central e Para-brisa (Cuddy Cabin Facetada)
cabin_x = [3.2, 5.8, 5.2, 3.2]
cabin_y = [0.85, 0.95, 1.85, 1.85]
ax1.fill(cabin_x, cabin_y, color='#F8FAFC', edgecolor=c_hull, lw=2)

# Vidros / Para-brisa Facetado
windshield_x = [3.6, 5.1, 4.6, 3.6]
windshield_y = [1.1, 1.15, 1.75, 1.75]
ax1.fill(windshield_x, windshield_y, color=c_glass, alpha=0.7, edgecolor='#0284C7', lw=1.5)

# Teto Hardtop
ax1.fill([2.8, 5.4, 5.3, 2.8], [1.85, 1.85, 1.95, 1.95], color='#F1F5F9', edgecolor=c_hull, lw=2)

# Arco Targa Vermelho na Popa
targa_x = [2.2, 2.5, 2.8, 2.5]
targa_y = [0.85, 2.3, 2.3, 0.85]
ax1.fill(targa_x, targa_y, color=c_targa, edgecolor='#991B1B', lw=2)
ax1.plot([2.5, 3.0], [2.3, 2.3], color=c_targa, lw=6) # Suporte de radar/antenas

# Guarda-Mancebo Inox de Proa
ax1.plot([6.2, 8.1, 8.1], [0.95, 0.95, 1.35], color='#94A3B8', lw=2.5)
ax1.plot([6.2, 8.1], [1.35, 1.35], color='#94A3B8', lw=2.5)
ax1.plot([6.8, 6.8], [0.95, 1.35], color='#94A3B8', lw=2)
ax1.plot([7.5, 7.5], [0.95, 1.35], color='#94A3B8', lw=2)

# Respiros / Louvers Vermelhos na Cabine
ax1.add_patch(patches.Rectangle((5.3, 1.2), 0.3, 0.15, facecolor=c_red, edgecolor='black', lw=1))

# Motores na Popa
ax1.add_patch(patches.Rectangle((-0.4, 0.2), 0.4, 0.8, facecolor='#334155', edgecolor='black', lw=1.5))
ax1.plot([-0.2, -0.2], [0.2, -0.4], color='#334155', lw=4) # Rabeta
ax1.add_patch(patches.Polygon([[-0.4, -0.4], [-0.1, -0.4], [-0.25, -0.55]], closed=True, facecolor='#F59E0B')) # Hélice

# Linha d'Água
ax1.axhline(0, color=c_wl, lw=2.0, linestyle='-', label="Linha d'Água de Projeto (WL)")
ax1.fill_between([0, 8.3], [-0.55, 0], [0, 0], color='#BAE6FD', alpha=0.45)

# Textos e Cotas
ax1.text(1.8, 0.3, 'DOUBLE TROUBLE STYLE', fontsize=12, fontweight='heavy', color='#64748B', style='italic', alpha=0.7)
ax1.annotate('', xy=(0, -0.75), xytext=(8.5, -0.75), arrowprops=dict(arrowstyle='<->', color='black', lw=1.2))
ax1.text(4.25, -0.95, 'Comprimento Total (LOA) = 8,50 m', ha='center', va='top', fontsize=9, fontweight='bold')

ax1.set_xlim(-0.8, 9.5)
ax1.set_ylim(-1.2, 2.7)
ax1.set_aspect('equal')
ax1.set_xlabel("Comprimento (metros)", fontsize=8)
ax1.set_ylabel("Altura (metros)", fontsize=8)
ax1.legend(loc='upper right', fontsize=8)


# 2. PLANTA DE CONVÉS (Top View - Arranjo Completo)
ax2 = fig.add_subplot(2, 2, 3)
ax2.set_title("2. PLANTA BAIXA / CONVÉS INTEGRADO (Top View)\nPlataforma Rígida Fechada e Cabine Central", fontsize=10, fontweight='bold', color=c_hull, pad=8)

y_be = 1.39
y_bb = -1.39
b_w = 0.41

# Cascos em planta (Wave-piercing finos)
x_p = np.linspace(0, 8.5, 100)
# Perfil fino com bico afiado
w_ext = np.where(x_p < 5.5, b_w, b_w * (1 - ((x_p - 5.5)/3.0)**1.2))

# Desenho dos cascos
ax2.plot(x_p, y_be + w_ext, color=c_hull, lw=2)
ax2.plot(x_p, y_be - w_ext*0.8, color=c_hull, lw=2)
ax2.plot(x_p, y_bb - w_ext, color=c_hull, lw=2)
ax2.plot(x_p, y_bb + w_ext*0.8, color=c_hull, lw=2)

# Ponte central sólida (Solid Bridgedeck)
ax2.fill([0.5, 7.5, 7.5, 0.5], [y_bb + b_w*0.8, y_bb, y_be, y_be - b_w*0.8], color='#F1F5F9', edgecolor=c_hull, lw=1.5)

# Cabine Central com Para-brisa
ax2.fill([3.2, 5.8, 5.8, 3.2], [-1.0, -1.0, 1.0, 1.0], color='#E2E8F0', edgecolor=c_hull, lw=2)
ax2.fill([3.6, 5.1, 5.1, 3.6], [-0.8, -0.8, 0.8, 0.8], color=c_glass, alpha=0.7, edgecolor='#0284C7', lw=1.2)
ax2.text(4.4, 0, 'CABINE CENTRAL\nPosto de Comando &\nAssentos Abrigados', ha='center', va='center', fontsize=7.5, fontweight='bold', color=c_hull)

# Arco Targa Vermelho (Top View)
ax2.plot([2.5, 2.5], [-1.4, 1.4], color=c_targa, lw=5)
ax2.text(2.5, 0, 'Arco Targa Radar', ha='center', va='bottom', fontsize=7, fontweight='bold', color='white', bbox=dict(boxstyle='square,pad=0.2', facecolor=c_targa, edgecolor='none'))

# Praça de Popa (Trabalho / Pesca / Lazer)
ax2.text(1.3, 0, 'PRAÇA DE POPA\nLIVRE (~12 m²)\nEspinhel / Porões', ha='center', va='center', fontsize=7.5, fontweight='bold', color='#475569')

# Motores
ax2.add_patch(patches.Rectangle((-0.4, y_be - 0.2), 0.4, 0.4, facecolor='#334155', edgecolor='black'))
ax2.add_patch(patches.Rectangle((-0.4, y_bb - 0.2), 0.4, 0.4, facecolor='#334155', edgecolor='black'))
ax2.text(-0.6, y_be, 'Motor 1', ha='right', va='center', fontsize=7, fontweight='bold')
ax2.text(-0.6, y_bb, 'Motor 2', ha='right', va='center', fontsize=7, fontweight='bold')

ax2.set_xlim(-1.0, 9.5)
ax2.set_ylim(-2.2, 2.2)
ax2.set_aspect('equal')
ax2.set_xlabel("Comprimento (m)", fontsize=8)
ax2.set_ylabel("Largura (m)", fontsize=8)


# 3. VISTA FRONTAL / SEÇÃO MESTRA (Front View & Chine Hull)
ax3 = fig.add_subplot(2, 2, 4)
ax3.set_title("3. VISTA FRONTAL / BALIZAS DE PROA (Front View)\nCasco Hard Chine com Túnel Alto e Cabine Central", fontsize=10, fontweight='bold', color=c_hull, pad=8)

# Desenho dos dois cascos em Hard Chine (arestas vivas)
def draw_hard_chine(ax, cx):
    # Formato facetado com chine
    xs = [cx - b_w, cx - b_w*0.95, cx, cx + b_w*0.95, cx + b_w]
    ys = [0.85, -0.15, -0.55, -0.15, 0.85]
    ax.fill(xs, ys, color=c_silver, edgecolor=c_hull, lw=2)
    # Faixa vermelha de detalhe
    ax.plot([cx - b_w, cx - b_w*0.95], [0.65, 0.65], color=c_red, lw=3)

draw_hard_chine(ax3, -1.39)
draw_hard_chine(ax3, 1.39)

# Ponte central e túnel
ax3.plot([-1.39 + b_w, 1.39 - b_w], [0.85, 0.85], color=c_hull, lw=2.5) # Piso
ax3.plot([-1.39 + b_w, 1.39 - b_w], [0.35, 0.35], color=c_hull, lw=2)   # Teto túnel
ax3.fill_between([-1.39 + b_w, 1.39 - b_w], [0.35, 0.35], [0.85, 0.85], color='#F1F5F9')

# Cabine Central Frontal
ax3.fill([-1.0, -1.0, 1.0, 1.0], [0.85, 1.85, 1.85, 0.85], color='#F8FAFC', edgecolor=c_hull, lw=2)
ax3.fill([-0.8, -0.8, 0.8, 0.8], [1.1, 1.75, 1.75, 1.1], color=c_glass, alpha=0.7, edgecolor='#0284C7', lw=1.5)
ax3.text(0, 1.4, 'Para-brisa', ha='center', va='center', fontsize=7.5, fontweight='bold', color=c_hull)

# Arco Targa na frente
ax3.plot([-1.3, -1.3, 1.3, 1.3], [0.85, 2.2, 2.2, 0.85], color=c_targa, lw=4)

# Linha d'Água
ax3.axhline(0, color=c_wl, lw=1.8, linestyle='-', label="Linha d'Água (WL)")

# Cotas
ax3.annotate('', xy=(-1.39 - b_w, 2.4), xytext=(1.39 + b_w, 2.4), arrowprops=dict(arrowstyle='<->', color='black', lw=1.2))
ax3.text(0, 2.5, 'Boca Total = 3,60 m', ha='center', va='bottom', fontsize=8, fontweight='bold')

ax3.set_xlim(-2.4, 2.4)
ax3.set_ylim(-1.0, 2.8)
ax3.set_aspect('equal')
ax3.set_xlabel("Largura (m)", fontsize=8)
ax3.set_ylabel("Altura (m)", fontsize=8)
ax3.legend(loc='lower right', fontsize=7.5)

plt.tight_layout()
output_dt = "/home/magdalena/eee/alunos/alberico-de-carvalho-santiago/projeto_catamara_estilo_double_trouble.png"
plt.savefig(output_dt, dpi=300, bbox_inches='tight')
plt.close()
print("Desenho Double Trouble gerado com sucesso!")
