An open API service indexing awesome lists of open source software.

https://github.com/phmatray/lenia

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.
https://github.com/phmatray/lenia

Last synced: 6 months ago
JSON representation

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.

Awesome Lists containing this project

README

          

# ๐Ÿงฌ Lenia - Artificial Life Simulation

[![.NET](https://img.shields.io/badge/.NET-9.0-blue.svg)](https://dotnet.microsoft.com/download/dotnet/9.0)
[![Blazor](https://img.shields.io/badge/Blazor-WebAssembly-purple.svg)](https://blazor.net/)
[![MudBlazor](https://img.shields.io/badge/MudBlazor-8.6.0-orange.svg)](https://mudblazor.com/)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

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.

![Lenia Demo](screenshots/lenia.png)

## โœจ Features

### ๐Ÿš€ High-Performance Engine
- **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

### ๐ŸŽจ Modern UI
- **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

### ๐Ÿงช Scientific Accuracy
- **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

## ๐ŸŽฎ Demo

Try the live demo: **[Lenia Simulation](https://phmatray.github.io/Lenia/)**

## ๐Ÿ› ๏ธ Technologies

- **[.NET 9.0](https://dotnet.microsoft.com/)** - Modern, cross-platform framework
- **[Blazor WebAssembly](https://blazor.net/)** - Client-side web UI with C#
- **[MudBlazor](https://mudblazor.com/)** - Material Design component library
- **[JavaScript Interop](https://docs.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability)** - High-performance canvas rendering

## ๐Ÿš€ Getting Started

### Prerequisites
- [.NET 9.0 SDK](https://dotnet.microsoft.com/download/dotnet/9.0)
- A modern web browser (Chrome, Firefox, Safari, Edge)

### Installation

1. **Clone the repository**
```bash
git clone https://github.com/phmatray/lenia.git
cd lenia
```

2. **Restore dependencies**
```bash
dotnet restore
```

3. **Run the application**
```bash
cd Lenia/Lenia
dotnet run
```

4. **Open your browser**
Navigate to `https://localhost:5001` or `http://localhost:5000`

## ๐ŸŽฏ Usage

### Basic Controls
- **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

### Physics Parameters
- **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)

### Performance Settings
- **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

## ๐Ÿ”ฌ About Lenia

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

### Mathematical Foundation

```
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](https://arxiv.org/abs/1812.05433).

## ๐Ÿ—๏ธ Architecture

```
โ”œโ”€โ”€ 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
```

## โšก Performance Optimizations

### Simulation Engine
- **Float Precision**: Uses `float` instead of `double` for 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

### Rendering
- **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

## ๐Ÿค Contributing

Contributions are welcome! Here's how to get started:

1. **Fork the repository**
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
3. **Make your changes**: Follow the existing code style
4. **Add tests**: Ensure your changes don't break existing functionality
5. **Commit your changes**: `git commit -m 'Add amazing feature'`
6. **Push to the branch**: `git push origin feature/amazing-feature`
7. **Open a Pull Request**: Describe your changes and why they're awesome

### Development Guidelines
- 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

## ๐Ÿ“ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- **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

## ๐Ÿ“š References

- [Lenia - Biology of Artificial Life](https://arxiv.org/abs/1812.05433) - Original paper
- [Lenia and Expanded Universe](https://arxiv.org/abs/2005.03742) - Extended research
- [Bert Chan's YouTube Channel](https://www.youtube.com/c/BertChakovsky) - Lenia demonstrations
- [MudBlazor Documentation](https://mudblazor.com/) - UI component reference

## ๐Ÿ› Issues & Support

- **Bug Reports**: [GitHub Issues](https://github.com/phmatray/lenia/issues)
- **Feature Requests**: [GitHub Discussions](https://github.com/phmatray/lenia/discussions)
- **Documentation**: [Wiki](https://github.com/phmatray/lenia/wiki)

---

**[โญ Star this repository](https://github.com/phmatray/lenia/stargazers)** if you find it interesting!

Made with โค๏ธ and lots of โ˜• by [Philippe Matray](https://github.com/phmatray)