A Python project that simulates and visualizes how HbA1c (glycated hemoglobin) levels change over time based on blood glucose patterns and red blood cell (RBC) lifecycles.
- Real-time RBC visualization: Watch red blood cells spawn, age, and change color based on glycation
- Circadian glucose patterns: Toggle between realistic daily glucose cycles and manual glucose levels
- Multiple lifespan models: Choose from gamma distribution (realistic), normal distribution, or fixed lifespans
- Live statistics: Track RBC count, average age, glycation levels, and estimated A1c
- Long-term modeling: Simulate A1c changes over 6 months
- Glucose history tracking: Model how past glucose levels affect current A1c
- Statistical analysis: Generate plots showing A1c trends over time
This simulation models the biological process behind A1c testing:
- Red blood cells live approximately 120 days (gamma distributed)
- Glucose attachment occurs continuously during RBC lifespan
- A1c measurement reflects average glucose over 2-3 months
- Circadian patterns show realistic daily glucose fluctuations
- Clone this repository
- Install dependencies:
pip install -r requirements.txt
python a1c_animation.pyControls:
- Toggle "Use Circadian Glucose" to switch between realistic daily patterns and fixed glucose
- Change "Lifespan Mode" to experiment with different RBC longevity models
- Watch RBCs change from red to yellow as they accumulate glucose
python a1c_simulation.pyThis will generate a plot showing how A1c estimates change over time based on glucose history.
- Red circles: Fresh RBCs with low glycation
- Yellow circles: Older RBCs with high glycation
- RBC color gradient: Shows individual glycation levels
- Estimated A1c: Calculated from average population glycation
- Python 3.11 (required for pygame compatibility)
- NumPy (numerical computations)
- Matplotlib (plotting for analytical simulation)
- Pygame (graphics and real-time animation engine)
- Pygame GUI (user interface elements for interactive controls)
This project requires Python 3.11 due to pygame compatibility constraints. Pygame currently does not support Python versions newer than 3.11, so please ensure you're using Python 3.11 specifically to avoid compatibility issues.
This simulation is designed for educational purposes to help understand:
- How A1c testing works at a cellular level
- Why A1c reflects 2-3 month glucose averages
- The relationship between daily glucose patterns and long-term measurements
- The biological variability in RBC lifespans
Open source - feel free to use and modify for educational purposes.