Skip to content

Streamlit Applications

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

The apps/ directory holds twelve Streamlit 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

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.

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
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 and 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). 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 app provides the interactive version.


Development Guide

Creating New Streamlit Apps

  1. Create a new .py file in apps/:
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)
  1. 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:

# 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.