---
type: Guide
title: "Streamlit Applications"
description: >-
  Catalogue of the twelve Streamlit apps in apps/ (bacterial DLA and swarming,
  Physarum, yeast colony, tree growth rings, cambium and 3D tree-root models),
  how to run them, and the matplotlib and PIL scripts that render static fractal
  images and GIFs.
resource: https://tyson-swetnam.github.io/fractal-notebooks/applications/streamlit-apps/
tags: [app, streamlit, dla, branching, biological]
sources:
  - id: fujikawa-matsushita-1989
    resource: https://doi.org/10.1143/JPSJ.58.3875
    title: "Fujikawa and Matsushita (1989) Fractal growth of Bacillus subtilis on agar plates, Journal of the Physical Society of Japan 58"
  - id: kawasaki-1997
    resource: https://doi.org/10.1006/jtbi.1997.0462
    title: "Kawasaki et al. (1997) Modeling spatio-temporal patterns generated by Bacillus subtilis, Journal of Theoretical Biology 188"
  - id: streamlit-docs
    resource: https://docs.streamlit.io/
    title: "Streamlit documentation"
generated:
  by: human:tswetnam
  at: "2025-12-14T00:00:00Z"
status: stable
---

# Streamlit Applications

<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.

The `apps/` directory holds twelve [Streamlit](https://docs.streamlit.io/) applications—browser-based Python tools for simulating growth processes and branching architectures—plus a set of plain matplotlib and PIL scripts that render static fractal images and animated GIFs. The Streamlit apps run locally; they are not deployed on this site.

---

## Running Streamlit Apps

### Quick Start

```bash
cd apps
pip install streamlit numpy scipy matplotlib plotly pillow imageio
streamlit run tree_roots_3d.py
```

The four tree-ring apps (`app.py`, `app2.py`, `app3.py`, `app4.py`) also need `pandas`, and `app3.py` additionally needs `shapely`. Alternatively create the pinned `streamlit-plotly` conda environment described in the [Installation Guide](installation.md#option-2-using-conda-with-mamba).

### Available Applications

| Application | File | What it does |
|-------------|------|--------------|
| Bacterial DLA | `bacterial_dla_app.py` | Animated diffusion-limited aggregation of a bacterial colony after Fujikawa and Matsushita (1989), with live colony statistics and a fractal dimension near 1.71 |
| Bacterial Swarming | `bacterial_swarming_app.py` | Reaction-diffusion model of *Bacillus subtilis* colony patterns after Kawasaki et al. (1997), showing the bacterial density and nutrient fields side by side |
| Physarum Simulation | `physarum_app.py` | Agent-based *Physarum polycephalum* slime-mould model with animated trail maps |
| Yeast Colony Simulation | `yeast_d3js.py` | D3.js force-directed graph of yeast colony growth with an energy budget, cell growth, shrinkage and death, embedded with `components.html()` and documented in a second tab |
| Tree Growth Simulator | `cones.py` | 3D tree built from stacked cones, growing year by year with adjustable branching angle, branches per split and radius taper (Plotly) |
| Interactive 3D Tree Visualization | `tree_roots_3d.py` | Tapered-cylinder crown and root system with separate level, length, radius, taper, angle and branching sliders for each half (Plotly) |
| 3D Tree Visualization (compact) | `branch_roots_3d.py` | The same crown-and-root model as `tree_roots_3d.py`, with a second tab that documents the code |
| Tree Growth Rings (hexagons) | `treerings.py` | Linear core view of annual rings as hexagonal cells with a logarithmic growth rate |
| Tree Growth Rings (Voronoi) | `app.py` | Linear core view with Voronoi-tessellated earlywood and latewood cells from a CSV of ring widths (matplotlib) |
| Tree Growth Rings (Voronoi, zoom) | `app2.py` | The Voronoi view rebuilt in Plotly with zoom and hover |
| Tree Growth Rings (aligned cells) | `app3.py` | Radially aligned cell rows clipped to ring boundaries with Shapely |
| Tree Cambium Growth | `app4.py` | Cambium growth with rays and cell rows, radial growth per year and an early/late wood ratio, with a preview of the first rows of the cell table (`st.write(df_cells.head())`) |

Every app runs with `streamlit run apps/<file>.py` and opens in the browser on port 8501.

---

## Matplotlib/PIL Scripts

These scripts in `apps/` are **not** Streamlit apps. Run them with `python`; each writes an image or GIF next to the script, and some also open a matplotlib window.

| Script | Output | What it draws |
|--------|--------|---------------|
| `mandelbrot.py` | `mandelbrot_set1.png` | Grayscale Mandelbrot set rendered pixel by pixel with PIL |
| `julia.py` | `julia_set.png` | A Julia set for a fixed complex parameter (PIL) |
| `julia_gif.py` | `julia_animation.gif` | Julia sets animated through parameter space (PIL and imageio) |
| `branching_tree.py` | `branching_tree.png` | Recursive self-affine branching tree with separate length and width scaling (matplotlib) |
| `pythagoras_tree.py` | `pythagoras_tree.png` | Pythagoras tree of squares (matplotlib) |
| `browniannoise.py` | `brownian_motion_animation.gif` | Brownian (red) noise trace with its Welch power spectrum |
| `pinknoise.py` | `pink_noise_animation.gif` | 1/f pink noise trace with its Welch power spectrum |
| `conway.py` | `game_of_life_high_res.gif` | High-resolution Conway's Game of Life animation |
| `waves.py` | `wave_tide_animation.gif` | Simulated wave and tide record with its power spectrum |

```bash
cd apps
python mandelbrot.py        # writes mandelbrot_set1.png
python pythagoras_tree.py   # writes pythagoras_tree.png and opens a window
```

### Mandelbrot and Julia Scripts

`mandelbrot.py` and `julia.py` colour each pixel by the escape time of the iteration

\[
z_0 = 0, \quad z_{n+1} = z_n^2 + c
\]

for the Mandelbrot set (where \( c \) ranges over the image plane), and of \( z_{n+1} = z_n^2 + c \) for a fixed \( c \) and varying \( z_0 \) for the Julia set. Edit the constants at the bottom of each script (image size, zoom, centre and maximum iterations) to change the view; `julia_gif.py` sweeps \( c \) to build an animation. The interactive counterparts are the React [Mandelbrot Set](react-apps.md#mandelbrot-set) and [Julia Sets](react-apps.md#julia-sets) apps.

### Branching Tree Script

`branching_tree.py` draws a recursive tree in which each branch spawns children shortened by a length factor and thinned by a separate width factor. When the two factors differ the tree is self-affine:

\[
\gamma = \frac{l_{k+1}}{l_k} \neq \xi = \frac{r_{k+1}}{r_k}
\]

which is the branching geometry that Metabolic Scaling Theory predicts for vascular networks (see [Chapter 1 §1.5](../foundations/history.md#15-fractals-enter-biology-sernetz-west-brown-enquist)). The branching angle, scaling factors, branching factor and depth are arguments of `draw_tree()` at the bottom of the script.

### Pythagoras Tree Script

`pythagoras_tree.py` builds the classic Pythagoras tree: on each square it constructs two smaller squares forming a right triangle and recurses to a maximum depth. With angle \( \theta \) the scaling factor is \( r = \cos\theta \). The React [Pythagoras Tree](react-apps.md#pythagoras-tree) app provides the interactive version.

---

## Development Guide

### Creating New Streamlit Apps

1. Create a new `.py` file in `apps/`:

```python
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt

st.title("My Fractal App")

# Parameters
iterations = st.slider("Iterations", 1, 100, 50)

# Computation
# ... your fractal algorithm ...

# Display
fig, ax = plt.subplots()
ax.imshow(result)
st.pyplot(fig)
```

2. Run with `streamlit run apps/your_app.py`

### Dependencies

Key packages used:

- `streamlit`: Web interface
- `numpy`: Numerical computation
- `matplotlib`: Static visualization
- `plotly`: Interactive visualization
- `scipy`: Scientific algorithms
- `pillow`: Image processing

### Performance Tips

- Use `@st.cache_data` for expensive computations
- Consider WebGL alternatives for real-time interaction

---

## Docker Deployment

For production deployment:

```bash
# from the repository root (the Dockerfile copies apps/)
docker build -f docker/Dockerfile -t fractal-app .
docker run -p 8501:8501 fractal-app
```

The image installs the Quick Start packages, copies `apps/`, exposes port 8501 and starts `streamlit run apps/tree_roots_3d.py`. To serve another of the Streamlit apps listed above, override the command: `docker run -p 8501:8501 fractal-app streamlit run apps/cones.py --server.address=0.0.0.0`.
