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, 11), dpi=300)

c_hull = '#0F2B48'
c_wl = '#0284C7'
c_engine = '#EA580C'
c_shaft = '#94A3B8'
c_skeg = '#1E293B'
c_wood = '#D97706'

# 1. PERFIL LONGITUDINAL DA CANOA COM MOTOR DIESEL DE CENTRO
ax1 = fig.add_subplot(2, 1, 1)
ax1.set_title("1. CORTE DO SEMI-CASCO: INSTALAÇÃO DO MOTOR DIESEL DE CENTRO COM SKEG\nPOWERCAT 8,50 m × 3,60 m — 2x Motores Diesel Centro (20 a 30 CV) com Linha de Eixo Protegida", fontsize=11, fontweight='bold', color=c_hull, pad=10)

# Contorno da Canoa
x_c = [0, 0, 4.5, 7.5, 8.5, 8.2, 0]
y_c = [0.85, -0.55, -0.55, -0.30, 0.95, 0.95, 0.85]
ax1.plot(x_c, y_c, color=c_hull, lw=2.5)
ax1.fill(x_c, y_c, color='#F8FAFC')

# Skeg / Falso Quilhão de Proteção sob o fundo
x_skeg = [0, 2.2, 2.2, 0]
y_skeg = [-0.75, -0.55, -0.40, -0.75]
ax1.fill(x_skeg, y_skeg, color='#CBD5E1', edgecolor=c_skeg, lw=1.5, label="Skeg Maciço de Proteção")
ax1.plot([-0.1, 2.2], [-0.75, -0.55], color=c_skeg, lw=4) # Sapata inferior

# Motor Diesel de Centro na Praça de Máquinas (x = 1,0 a 2,0 m)
engine_box = patches.Rectangle((0.8, -0.35), 1.1, 0.65, facecolor='#FED7AA', edgecolor=c_engine, lw=2, zorder=3)
ax1.add_patch(engine_box)
ax1.text(1.35, -0.05, 'Motor Diesel Centro\n(20 a 30 CV)', ha='center', va='center', fontsize=8, fontweight='bold', color=c_engine, zorder=4)

# Reversor / Acoplamento
ax1.add_patch(patches.Rectangle((0.55, -0.38), 0.25, 0.45, facecolor='#FDBA74', edgecolor=c_engine, lw=1.5, zorder=3))
ax1.text(0.67, -0.15, 'Rev.', ha='center', va='center', fontsize=6.5, fontweight='bold', color=c_engine, zorder=4)

# Linha de Eixo Inox inclinada (~8 graus)
ax1.plot([0.15, 0.65], [-0.60, -0.30], color=c_shaft, lw=4, zorder=2)
# Hélice de bronze (4 pás)
ax1.add_patch(patches.Rectangle((0.05, -0.72), 0.10, 0.25, facecolor='#F59E0B', edgecolor='#B45309', lw=1.2, zorder=3))
ax1.text(0.10, -0.82, 'Hélice', ha='center', va='top', fontsize=7, fontweight='bold', color='#B45309')

# Leme protegido pelo Skeg
ax1.add_patch(patches.Rectangle((-0.18, -0.75), 0.10, 0.45, facecolor='#475569', edgecolor='black', lw=1.2, zorder=3))
ax1.text(-0.13, -0.90, 'Leme Protegido', ha='center', va='top', fontsize=7, fontweight='bold', color='#475569')

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

# Popa totalmente desimpedida para faina
ax1.plot([0, 0], [0.85, 1.2], color=c_wood, lw=3)
ax1.text(0.3, 1.05, 'POPA TOTALMENTE LIVRE\nSem motor de popa atrapalhando!', ha='left', va='center', fontsize=8, fontweight='bold', color='#047857')

# Cotas
ax1.annotate('', xy=(0, -1.05), xytext=(8.5, -1.05), arrowprops=dict(arrowstyle='<->', color='black', lw=1.2))
ax1.text(4.25, -1.25, 'Comprimento Total (LOA) = 8,50 m', ha='center', va='top', fontsize=8.5, fontweight='bold')

ax1.set_xlim(-0.8, 9.5)
ax1.set_ylim(-1.4, 1.5)
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 ARRANJO DA PRAÇA DE MÁQUINAS (Top View)
ax2 = fig.add_subplot(2, 2, 3)
ax2.set_title("2. DISPOSIÇÃO DOS MOTORES NOS 2 CASCOS (Top View)", fontsize=9.5, fontweight='bold', color=c_hull, pad=8)

y_be = 1.39
y_bb = -1.39
bw = 0.41

# Cascos
xp = np.linspace(0, 8.5, 100)
w_ext = np.where(xp < 5.5, bw, bw * (1 - ((xp - 5.5)/3.0)**1.2))
ax2.plot(xp, y_be + w_ext, color=c_hull, lw=1.8)
ax2.plot(xp, y_be - w_ext*0.8, color=c_hull, lw=1.8)
ax2.plot(xp, y_bb - w_ext, color=c_hull, lw=1.8)
ax2.plot(xp, y_bb + w_ext*0.8, color=c_hull, lw=1.8)

# Convés central
ax2.fill([0.5, 7.5, 7.5, 0.5], [y_bb + bw*0.8, y_bb, y_be, y_be - bw*0.8], color='#F1F5F9', edgecolor=c_hull, lw=1.2)

# Motor Boreste
ax2.add_patch(patches.Rectangle((0.8, y_be - 0.25), 1.1, 0.5, facecolor='#FED7AA', edgecolor=c_engine, lw=1.2))
ax2.text(1.35, y_be, 'Motor Diesel BE\n(25 CV)', ha='center', va='center', fontsize=6.5, fontweight='bold', color=c_engine)

# Motor Bombordo
ax2.add_patch(patches.Rectangle((0.8, y_bb - 0.25), 1.1, 0.5, facecolor='#FED7AA', edgecolor=c_engine, lw=1.2))
ax2.text(1.35, y_bb, 'Motor Diesel BB\n(25 CV)', ha='center', va='center', fontsize=6.5, fontweight='bold', color=c_engine)

# Linhas de eixo saindo na popa
ax2.plot([0.1, 0.8], [y_be, y_be], color=c_shaft, lw=3)
ax2.plot([0.1, 0.8], [y_bb, y_bb], color=c_shaft, lw=3)
ax2.add_patch(patches.Circle((0.1, y_be), 0.15, facecolor='#F59E0B', edgecolor='#B45309'))
ax2.add_patch(patches.Circle((0.1, y_bb), 0.15, facecolor='#F59E0B', edgecolor='#B45309'))

# Praça de Popa Livre
ax2.text(2.8, 0, 'PRAÇA DE TRABALHO 100% PLANA\nE DESIMPEDIDA NA POPA', ha='center', va='center', fontsize=7.5, fontweight='bold', color='#047857')

ax2.set_xlim(-0.8, 9.0)
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. VANTAGENS DO MOTOR DE CENTRO NO CATAMARÃ
ax3 = fig.add_subplot(2, 2, 4)
ax3.axis('off')
ax3.set_title("3. PRINCIPAIS VANTAGENS TÉCNICAS E OPERACIONAIS", fontsize=9.5, fontweight='bold', color=c_hull, pad=8)

text_v = """
• Por que usar Motor Diesel de Centro no Catamarã 8,50 m?

1. Praça de Popa Desimpedida:
   - Não há motores de popa pendurados no espelho.
   - O pescador pode lançar e recolher o espinhel pela popa 
     ou pelos bordos com total liberdade e sem enroscar linha.

2. Proteção Absoluta de Fundo (Skegs / Falsos QuilhSingle-casco):
   - Cada canoa tem uma quilha maciça que protege o hélice e o leme.
   - O catamarã pode encalhar na areia ou apoiar na praia na maré baixa 
     sem encostar o hélice nem o leme no fundo!

3. Economia e Confiabilidade Máxima:
   - 2x Motores Diesel (ex: Yanmar / Agrale / MWM 20 a 30 CV).
   - Consumo combinado de apenas 4,0 a 5,0 L/h a 7,0 nós de cruzeiro.
   - Durabilidade de trabalho pesado para viagens de 5 dias no mar.

4. Manobrabilidade por Empuxo Diferencial:
   - Como os motores ficam separados por 2,78 m, basta botar um motor 
     para frente e o outro para trás para o catamarã girar 360° no próprio eixo!
"""
ax3.text(0.02, 0.98, text_v, ha='left', va='top', fontsize=7.5, family='monospace', color='#1E293B', linespacing=1.35)

plt.tight_layout()
output_img = "/home/magdalena/eee/alunos/alberico-de-carvalho-santiago/catamara_8_5m_motor_centro.png"
plt.savefig(output_img, dpi=300, bbox_inches='tight')
plt.close()
print("Desenho do catamara com motor de centro gerado!")
