A high-performance, real-time implementation of Lenia - a fascinating continuous cellular automaton that creates complex, lifelike patterns. Built with Blazor WebAssembly and MudBlazor for a modern, interactive web experience.
- 60 FPS Target: Optimized for smooth real-time simulation
- Adaptive Quality: Automatically adjusts processing quality to maintain performance
- Multi-threaded Processing: Utilizes all CPU cores for maximum speed
- Scalable Grid: Dynamic grid sizing from 24ร24 to 128ร128
- Memory Optimized: Efficient algorithms with minimal allocations
- Dark Theme: Professional dark interface with custom purple accent
- Real-time Metrics: Live FPS, update time, and render time monitoring
- Responsive Design: Works beautifully on desktop and mobile
- Material Design: Clean, intuitive interface using MudBlazor components
- Interactive Controls: Sliders, buttons, and toggles for all parameters
- Authentic Lenia Mathematics: Implements the original Lenia formulas
- Configurable Physics: Adjust radius (R), time step (ฮt), growth parameters (ฮผ, ฯ)
- Pattern Presets: Pre-configured Orbium and Geminium patterns
- Custom Initialization: Circle patterns and random seeding
Try the live demo: Lenia Simulation
- .NET 9.0 - Modern, cross-platform framework
- Blazor WebAssembly - Client-side web UI with C#
- MudBlazor - Material Design component library
- JavaScript Interop - High-performance canvas rendering
- .NET 9.0 SDK
- A modern web browser (Chrome, Firefox, Safari, Edge)
-
Clone the repository
git clone https://github.com/phmatray/lenia.git cd lenia -
Restore dependencies
dotnet restore
-
Run the application
cd Lenia/Lenia dotnet run -
Open your browser Navigate to
https://localhost:5001orhttp://localhost:5000
- Play/Pause: Click the play button in the top bar or main controls
- Reset: Clear the grid and start fresh
- Patterns: Choose from Circle, Orbium, or Geminium presets
- Radius (R): Neighborhood size for cell interactions (2.0 - 10.0)
- Time Step (ฮt): Simulation speed multiplier (0.01 - 0.5)
- Growth ฮผ: Peak of the growth function (0.0 - 0.5)
- Growth ฯ: Width of the growth function (0.001 - 0.1)
- Grid Size: Adjust from 24ร24 to 128ร128 cells
- Target FPS: Set desired frame rate (10-120 FPS)
- Adaptive Quality: Auto-adjust processing quality for consistent performance
Lenia is a continuous cellular automaton discovered by Bert Wang-Chak Chan. Unlike traditional cellular automata (like Conway's Game of Life), Lenia uses:
- Continuous values instead of binary states
- Smooth kernels for neighborhood calculations
- Differential equations for state updates
- Real-valued time for fluid evolution
This creates remarkably lifelike behaviors including:
- Self-organization and emergence
- Glider-like moving patterns
- Complex interactions and collisions
- Adaptive and evolutionary dynamics
Update Rule: A^(t+ฮt)(x) = clip(A^t(x) + ฮt ร G(U^t(x)), 0, 1)
Where:
- A^t(x): Cell state at time t and position x
- U^t(x): Local neighborhood potential
- G(u): Growth function G(u; ฮผ, ฯ) = 2รexp(-((u-ฮผ)/ฯ)ยฒ/2) - 1
- ฮt: Time step size
For more details, see the original paper.
โโโ Lenia/ # Server-side Blazor Web App
โ โโโ Components/
โ โ โโโ App.razor # Main application shell
โ โโโ Program.cs # Server configuration
โ โโโ Lenia.csproj # Server project file
โ
โโโ Lenia.Client/ # Client-side Blazor WebAssembly
โ โโโ Components/
โ โ โโโ LeniaCanvas.razor # Canvas rendering component
โ โโโ Pages/
โ โ โโโ Home.razor # Main simulation page
โ โโโ Layout/
โ โ โโโ MainLayout.razor # App layout with dark theme
โ โโโ wwwroot/
โ โ โโโ leniaCanvas.js # High-performance canvas rendering
โ โโโ LeniaScalable.cs # Optimized simulation engine
โ โโโ Program.cs # Client configuration
โ โโโ Lenia.Client.csproj # Client project file
โ
โโโ README.md # This file
- Float Precision: Uses
floatinstead ofdoublefor 2ร memory bandwidth - Pre-computed Kernels: Kernel weights calculated once and cached
- Parallel Processing: Multi-threaded updates using
Parallel.For - Chunked Processing: Large grids processed across multiple frames
- Adaptive Quality: Dynamic reduction of processed cells when needed
- JavaScript Interop: Direct canvas manipulation for maximum speed
- ImageData Optimization: Efficient pixel buffer updates
- Hardware Scaling: GPU-accelerated canvas scaling
- Minimal Allocations: Reused buffers and optimized memory access
Contributions are welcome! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes: Follow the existing code style
- Add tests: Ensure your changes don't break existing functionality
- Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request: Describe your changes and why they're awesome
- Follow C# coding conventions
- Use MudBlazor components for UI consistency
- Maintain 60 FPS performance target
- Add XML documentation for public APIs
- Include unit tests for new features
This project is licensed under the MIT License - see the LICENSE file for details.
- Bert Wang-Chak Chan - Original Lenia research and discovery
- MudBlazor Team - Excellent Blazor component library
- Microsoft - .NET and Blazor frameworks
- Blazor Community - Inspiration and best practices
- Lenia - Biology of Artificial Life - Original paper
- Lenia and Expanded Universe - Extended research
- Bert Chan's YouTube Channel - Lenia demonstrations
- MudBlazor Documentation - UI component reference
- Bug Reports: GitHub Issues
- Feature Requests: GitHub Discussions
- Documentation: Wiki
โญ Star this repository if you find it interesting!
Made with โค๏ธ and lots of โ by Philippe Matray
