A wrapper for manim for blockchain and blockDAG related animations
BLanim (short for BLockDAG animations) is an extension of the Manim (community) Python package, a community-maintained version of the library used by 3Blue1Brown to animate mathematical concepts. BLanim extends Manim with utilities specifically designed for creating visual illustrations of blockchain and blockDAG related concepts. I develop Manim to produce animations for my YouTube channel, the Deepdive.
BLanim is currently in a pre-pre-pre-alpha stage and is only publicly available for collaboration purposes. It is not well packaged yet, lacks documentation, and needs a lot of refactoring and missing features. If you'd like to contribute, please don't hesitate to contact me.
Note: from here to end is AI generated and can likely be improved
BLanim is a comprehensive Python library extending Manim (community) with specialized tools for creating blockchain and blockDAG animations. Built for educational content creation, it provides complete visualization systems for both linear chains (Bitcoin) and directed acyclic graphs (Kaspa).
- Bitcoin Support: Linear blockchain visualization with single-parent chains
- Kaspa Support: Full DAG visualization with GHOSTDAG consensus algorithm
- Multiple Parent Lines: Visual support for blocks referencing multiple parents
- Manager Delegation Pattern: Specialized managers for distinct concerns
- Three-Layer Separation: Logical blocks (structure), visual blocks (rendering), DAG layer (orchestration)
- Unified Configuration: Type-safe config system with blockchain-specific parameters
- Workflow Control: Step-by-step, immediate, or batch animation patterns
- Network Simulation: Realistic block generation with propagation delays
- GHOSTDAG Visualization: Complete consensus algorithm animation with blue/red classification
- Dual Text Channels: Upper narration and lower caption with primer pattern optimization
- Fixed-in-Frame HUD: Elements stay visible during camera movements
- Camera Controls: MovingCameraScene-compatible API with Frame2DWrapper
- UniversalNarrationManager: Handles text creation with LaTeX validation
- Transcript Support: Automatic .txt file generation for accessibility
- Raw String Handling: Built-in validation for LaTeX commands
- Frame2DWrapper: 2D camera movements with 3D scene benefits
- Animation Chaining: Method chaining for smooth transitions
pip install blanim from blanim import *
class MyBlockchainScene(HUD2DScene):
def construct(self):
# Create Kaspa DAG
dag = KaspaDAG(scene=self)
# Add blocks with automatic animation
genesis = dag.add_block()
block1 = dag.add_block(parents=[genesis])
block2 = dag.add_block(parents=[genesis])
# Create merge block
merge = dag.add_block(parents=[block1, block2])
# Animate GHOSTDAG process
dag.animate_ghostdag_process(merge) Simulate realistic network conditions:
blocks = dag.simulate_blocks(
duration_seconds=20, # 20 seconds of simulation
blocks_per_second=1, # 1 BPS network rate
network_delay_ms=350 # 350ms propagation delay
)
dag.create_blocks_from_simulator_list(blocks) blanim/
βββ core/ # Base infrastructure
β βββ base_config.py # Configuration interface
β βββ base_visual_block.py # Visual rendering base
β βββ parent_line.py # Connection lines
β βββ hud_2d_scene.py # Scene with narration support
βββ blockDAGs/ # Blockchain implementations
βββ bitcoin/ # Linear chains
β βββ config.py
β βββ logical_block.py
β βββ visual_block.py
β βββ chain.py
βββ kaspa/ # DAG structures
βββ config.py
βββ logical_block.py
βββ visual_block.py
βββ dag.py
βββ ghostdag.py
KaspaDAG uses specialized managers for clean separation of concerns:
- BlockManager: Block creation and workflow control
- Movement: Block positioning and camera tracking
- Retrieval: Block lookup with fuzzy matching
- RelationshipHighlighter: Past/future/anticone visualization
- GhostDAGHighlighter: Consensus algorithm animation
- BlockSimulator: Network parameter simulation
Each blockchain type has its own configuration class:
# Kaspa configuration [header-1](#header-1)
kaspa_config = KaspaConfig(
k=18, # GHOSTDAG parameter
block_color=WHITE,
ghostdag_blue_color=BLUE,
ghostdag_red_color=RED,
create_run_time=2.0
)
# Bitcoin configuration [header-2](#header-2)
bitcoin_config = BitcoinConfig(
block_color=ORANGE,
create_run_time=1.5
) Comprehensive test suite with visual validation:
# Run Kaspa tests [header-3](#header-3)
python -m tests.kaspa_tests
# Run Bitcoin tests [header-4](#header-4)
python -m tests.bitcoin_tests - Basic DAG Creation: Simple parent-child relationships
- Network Simulation: Realistic block generation under varying conditions
- GHOSTDAG Process: Step-by-step consensus algorithm visualization
- Relationship Highlighting: Past cone, future cone, and anticone visualization
BLanim follows a modular architecture pattern. When contributing:
- Maintain Separation: Keep logical, visual, and orchestration layers separate
- Use Manager Pattern: New functionality should follow the delegation pattern
- Add Tests: Include visual test scenes for new features
- Document: Update docstrings and architecture documentation