{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "id": "cell-0",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": "# --- house style (the Press palette: accent/navy/gold/parchment) ---\nimport matplotlib as mpl\nACCENT, NAVY, GOLD, PARCH = '#7a1f1f', '#1f3a5f', '#b8860b', '#f7f2e7'\nmpl.rcParams.update({'figure.facecolor': PARCH, 'axes.facecolor': '#fffdf6',\n                     'axes.edgecolor': '#c9bfa3', 'font.family': 'serif'})\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib import animation\n\nw0 = np.array([3.0, 1.0, 4.0, 1.5, 2.5, 1.0])\nA0 = np.array([0, 2, 4])\n\nfig, ax = plt.subplots(figsize=(8, 3))\ndef draw(k):\n    ax.clear()\n    wk = np.repeat(w0, k) / k                    # split each tessera into k\n    sel = np.isin(np.arange(len(wk)) // k, A0)   # lift of the selection\n    v = wk[sel].sum() / wk.sum()\n    ax.bar(np.arange(len(wk)), wk, width=1.0,\n           color=np.where(sel, ACCENT, 'lightsteelblue'))\n    ax.set(ylim=(0, w0.max() * 1.1),\n           title=f\"split factor k = {k}:  $|T| = {v:.6f}$  (Thm 2.1: invariant)\")\n\nani = animation.FuncAnimation(fig, draw, frames=[1, 2, 3, 4, 6, 8, 12], interval=900)\n# Colab:  from IPython.display import HTML; HTML(ani.to_jshtml())\n# Web:    ani.save('py02_vermiculator.gif', writer='pillow', fps=2)\nplt.show()\n"
  }
 ]
}