A Python script and interactive web visualization that moves a pointer through the digits of π (pi) and counts the occurrence of each digit (0-9) as it progresses.
The interactive web version is available at: GitHub Pages
Features:
- 🎬 Animated pointer moving through π digits
- 📊 Real-time digit counting (0-9)
- 📈 Visual progress bars and statistics
- ⚡ Adjustable animation speed
- 🎨 Beautiful, modern UI
Simply open index.html in your web browser, or use a local server:
# Python 3
python -m http.server 8000
# Node.js
npx http-server
# Then open http://localhost:8000 in your browserA command-line Python script for calculating and analyzing π digits.
- Calculates π digits up to a specified precision
- Moves a pointer through π digits step by step
- Counts occurrences of each digit (0-9) in real-time
- Displays statistics including counts and percentages
- Visual bar charts for digit distribution
- Interactive mode for step-by-step exploration
- Python 3.6+
- Standard library only (decimal, collections)
Optional (for better performance with large precisions):
mpmath- For faster π calculation
pip install mpmathRun the script and follow the prompts:
python pi_digit_counter.pyYou'll be prompted to:
- Enter the number of decimal places to calculate
- Move the pointer forward by entering steps
- Type 'auto' to process all remaining digits
- Type 'quit' to exit
from pi_digit_counter import PiDigitCounter
# Create a counter with 1000 decimal places
counter = PiDigitCounter(precision=1000)
# Move pointer forward by N steps
counter.move_pointer(100)
# Display current status
counter.display_status()
# Get current digit counts
counts = counter.get_counts()
# Get percentages
percentages = counter.get_percentages()See example_usage.py for more examples.
pi_visualizer/
├── index.html # Web app HTML
├── styles.css # Web app styles
├── script.js # Web app JavaScript
├── pi_digit_counter.py # Python script
├── example_usage.py # Python examples
├── requirements.txt # Python dependencies
└── README.md # This file
This project is set up to automatically deploy to GitHub Pages using GitHub Actions.
- Go to your repository Settings → Pages
- Set source to "GitHub Actions"
- The workflow will automatically deploy on pushes to
mainormasterbranch
For local development, just open index.html in your browser or use a local server.
- Initialization: Calculates or loads π digits
- Pointer: Starts at position 0 (the digit '3')
- Movement: As the pointer moves forward, it reads each digit
- Counting: Each digit encountered increments its counter
- Statistics: Real-time display shows counts, percentages, and visual bars
- The pointer starts at the digit '3' (position 0)
- Decimal places start from position 1 onwards
- For very large precisions (>10000), consider using
mpmathfor faster calculation - The Python script uses Machin's formula for π calculation (fallback) or mpmath if available
Free to use and modify.