#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun May 4 08:58:38 2025 @author: amriksen """ import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation, PillowWriter import os # ───────────────────────────────────────────── # CONFIGURATION # ───────────────────────────────────────────── n_frames = 100 # simulate k = 0 … n_frames # initial state (k = 0) V0, S0 = 1.0, 1.0 # V₀ (Vita Corpora, blue) & S₀ (Spiritus Fundamentum, red) # coefficient matrix ⎡base_11 base_12⎤ # ⎣base_21 base_22⎦ base_11 = 1.1 base_12 = 1.0 base_21 = 0.0 base_22 = 1.1 fps = 4 # frames per second for the GIFs # ───────────────────────────────────────────── # ── PRECOMPUTE THE TRAJECTORY ───────────────────────────── V_vals = [V0] S_vals = [S0] for k in range(n_frames): V_next = base_11 * V_vals[k] + base_12 * S_vals[k] S_next = base_21 * V_vals[k] + base_22 * S_vals[k] V_vals.append(V_next) S_vals.append(S_next) # maxima for scaling max_V = max(V_vals) max_S = max(S_vals) # style for big, bold tick numbers def style_y_ticks(ax, size=14, weight="bold"): for lbl in ax.get_yticklabels(): lbl.set_fontsize(size) lbl.set_fontweight(weight) ax.tick_params(axis="y", width=1.5, length=6) # ───────────────────────────────────────────── # Helper: create & save a single‑bar animated GIF # ───────────────────────────────────────────── def make_bar_gif(color, values, ymax, ylabel, filename): fig, ax = plt.subplots(figsize=(5, 6)) bar = ax.bar([0], [values[0]], color=[color], width=0.6) # big, bold y‑label ax.set_ylabel(ylabel, labelpad=14, fontsize=16, fontweight="bold") ax.set_ylim(0, ymax * 1.05) fig.subplots_adjust(left=0.35) # room for y‑label # big, bold title (updates each frame) ax.set_title("Refinement stage k = 0", pad=18, fontsize=18, fontweight="bold") ax.set_xticks([]) # no x‑tick labels style_y_ticks(ax) def update(k): bar[0].set_height(values[k]) ax.set_title(f"Stage k = {k}", pad=18, fontsize=18, fontweight="bold") style_y_ticks(ax) return bar anim = FuncAnimation(fig, update, frames=range(n_frames + 1)) anim.save(filename, writer=PillowWriter(fps=fps)) plt.close(fig) # ── GENERATE THE TWO GIFS IN CURRENT DIRECTORY ─────────── make_bar_gif( color="blue", values=V_vals, ymax=max_V, ylabel="Potency", filename="blue_growth.gif", ) make_bar_gif( color="red", values=S_vals, ymax=max_S, ylabel="Potency", filename="red_growth.gif", ) print("GIFs saved to current directory:", os.getcwd())