"""Lecture 28: acceleration in g against dimensionless time g t/V_E for a vertical vacuum flight with zeta = 0.8 and
initial thrust-to-weight 1.5: constant thrust against thrust kept proportional to weight (flight.rocket).
Writes img/fig-28-accel.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, INK, GREY
from flight import rocket as R

ZETA, TAU = 0.8, 1.5
CT = R.vertical_constant_thrust(ZETA, TAU)
CA = R.vertical_constant_acceleration(ZETA, TAU)
A_END = float(R.vertical_acceleration_g(CT["theta_c"], TAU)) - 1.0

if __name__ == "__main__":
    fig, ax = plt.subplots(figsize=(10, 5.0))
    th = np.linspace(0, CT["theta_c"], 300)
    ax.plot(th, R.vertical_acceleration_g(th, TAU) - 1, color=MAROON, lw=2.8, label="constant thrust")
    ax.plot([0, CA["theta_c"]], [TAU - 1] * 2, color=BLUE, lw=2.8, label="constant acceleration (throttled)")
    for t, a, c, text, off, ha in ((CT["theta_c"], A_END, MAROON, f"burnout: {A_END:.1f} $g$", (16, -44), "left"),
                                   (CA["theta_c"], TAU - 1, BLUE, f"burnout: {TAU - 1:.1f} $g$", (0, 14), "center")):
        ax.plot(t, a, "o", color=c, ms=9)
        ax.annotate(text + f"\n$gt/V_E$ = {t:.2f}", (t, a), xytext=off, textcoords="offset points", ha=ha, fontsize=12, color=c)
    ax.set_xlim(0, 1.2); ax.set_ylim(0, 8.0); ax.set_xlabel("dimensionless time $gt/V_E$"); ax.set_ylabel("acceleration $a/g$")
    ax.legend(frameon=False, fontsize=12, loc="upper left")
    despine(ax)
    save(fig, "fig-28-accel")
