Skip to main content

e2D - High-Performance 2D Graphics and Math Library

Python License Status

e2D combines ultra-optimized vector mathematics with modern OpenGL rendering for high-performance 2D applications. Perfect for games, simulations, and real-time graphics.

✨ Features

🚀 Optimized Vector Operations

  • Cython-compiled Vector2D class (10-500x faster than pure Python)
  • Batch operations for processing thousands of vectors efficiently
  • Direct memory access with zero-copy operations
  • NumPy integration for seamless GPU data upload

🎮 Modern Graphics

  • ModernGL rendering pipeline
  • Shape rendering with instancing support
  • Text rendering with custom styles and TTF fonts
  • Screen recording with async video encoding
  • Color system with 80+ pre-defined colors
  • GLFW window management

🎯 Game Development Tools

  • Keyboard and mouse input handling
  • Collision detection
  • Color manipulation
  • Vector mathematics

📦 Installation

Basic Installation

pip install e2D

The package will automatically compile the Cython extensions during installation for optimal performance (like numpy). If compilation fails, it falls back to pure Python mode.

Optional Features

Install with screen recording support:

pip install e2D[rec]

Install for development (includes testing tools):

pip install e2D[dev]

Install with performance monitoring (includes Cython source):

pip install e2D[performance]

Install everything:

pip install e2D[all]

Legacy Version (1.x with Pygame)

If you need the old pygame-based version:

pip install "e2D<2.0"

Requirements

  • Python 3.10+
  • NumPy (required)
  • ModernGL (required)
  • GLFW (required)
  • Pillow (required - for text rendering)
  • attrs (required - for data structures)
  • OpenCV-Python (optional, for recording - install with [rec] extra)

Linux-Specific Setup (Fedora/RHEL/CentOS)

If you encounter OpenGL library errors on Fedora-based systems:

# Install Mesa OpenGL libraries
sudo dnf install mesa-libGL mesa-libEGL

# Create symlinks (ModernGL needs unversioned .so files)
sudo ln -s /usr/lib64/libGL.so.1 /usr/lib64/libGL.so
sudo ln -s /usr/lib64/libEGL.so.1 /usr/lib64/libEGL.so

Note: On Debian/Ubuntu systems, these symlinks are usually created automatically. If you encounter similar issues:

sudo apt-get install libgl1-mesa-glx libegl1-mesa

🚀 Quick Start

Optimized Vector Operations

from e2D import Vector2D, batch_add_inplace, vectors_to_array

# Create vectors
v1 = Vector2D(3.0, 4.0)
v2 = Vector2D(1.0, 2.0)

# Basic operations
v3 = v1 + v2
length = v1.length
dot = v1.dot_product(v2)

# In-place operations (faster!)
v1.iadd(v2)
v1.normalize()
v1.irotate(0.1)

# Process thousands of vectors instantly
positions = [Vector2D.random(-10, 10) for _ in range(10000)]
displacement = Vector2D(1.0, 0.5)
batch_add_inplace(positions, displacement)  # 🚀 Lightning fast!

# Convert to numpy for GPU upload
pos_array = vectors_to_array(positions)

Graphics Rendering

from e2D import RootEnv, DefEnv
from e2D.vectors import V2

class MyApp(DefEnv):
    def __init__(self) -> None:
        pass
    
    def update(self) -> None:
        # Your game logic here
        pass
    
    def draw(self) -> None:
        # Your rendering code here
        pass

# Initialize and run
rootEnv = RootEnv(window_size=V2(1920, 1080), target_fps=60)
rootEnv.init(MyApp())

# Optional: Enable screen recording
rootEnv.init_rec(fps=30, draw_on_screen=True, path='output.mp4')

rootEnv.loop()

Color System

from e2D import Color, WHITE, RED, CYAN, normalize_color
from e2D.color_defs import MD_BLUE, PASTEL_PINK, NEON_GREEN

# Create colors
color1 = Color.from_hex("#FF5733")
color2 = Color.from_rgb255(100, 150, 200)
color3 = Color.from_hsv(0.5, 0.8, 1.0)

# Color operations
lighter = color1.lighten(0.2)
darker = color1.darken(0.2)
inverted = color1.invert()
rotated = color1.rotate_hue(120)

# Use pre-defined colors
from e2D import draw_circle
draw_circle((100, 100), 50, color=RED, fill_mode='fill')

📊 Performance

Vector2D benchmark (100,000 operations):

Operation Time vs Pure Python
Creation 42 ms 10x faster
Addition 64 ms 15x faster
In-place ops 3.8 ms 100x faster
Normalization 1.9 ms 200x faster
Batch operations 0.17 ms 500x+ faster 🔥

Perfect for:

  • Particle systems (10,000+ particles)
  • Physics simulations
  • Collision detection
  • Path finding
  • Real-time graphics

📚 Documentation

Feature Guides

  • Vector Operations - Complete guide to Vector2D operations, batch processing, and optimization
  • Color System - Color creation, manipulation, pre-defined palettes, and conversions
  • Shape Rendering - Drawing circles, rectangles, lines, and using shape caching
  • Text Rendering - Text rendering, styles, fonts, pivots, and cached labels
  • Input Handling - Keyboard and mouse input with Keys and MouseButtons constants

Examples & API

🎯 Use Cases

Particle System

from e2D import Vector2D, batch_add_inplace, vectors_to_array

positions = [Vector2D.random(-10, 10) for _ in range(10000)]
velocities = [Vector2D.random(-1, 1) for _ in range(10000)]

def update(dt):
    # Update all particles in milliseconds
    for i in range(len(positions)):
        temp = velocities[i].mul(dt)
        positions[i].iadd(temp)

def render():
    # Upload to GPU
    pos_array = vectors_to_array(positions).astype(np.float32)
    vbo.write(pos_array)

Physics Simulation

from e2D import Vector2D

class RigidBody:
    def __init__(self, pos, vel):
        self.position = Vector2D(*pos)
        self.velocity = Vector2D(*vel)
        self.acceleration = Vector2D(0, -9.8)
    
    def update(self, dt):
        # Optimized in-place physics
        temp = self.acceleration.mul(dt)
        self.velocity.iadd(temp)
        
        temp = self.velocity.mul(dt)
        self.position.iadd(temp)

🔧 Development

Building from Source

git clone https://github.com/marick-py/e2D.git
cd e2D
pip install -e .[dev]

Running Tests

pytest

Building Distribution

python -m build

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👤 Author

Riccardo Mariani

🙏 Acknowledgments

  • Built with ModernGL
  • Optimized with Cython
  • Inspired by the need for high-performance 2D mathematics in Python

📈 Version History

Version 2.x (ModernGL-based - Current)

  • 2.1.8 (Current) - Bug fixes and documentation improvements
  • 2.0.0 - Complete rewrite with ModernGL rendering, Cython-optimized vectors, modern color system, screen recording, removed pygame dependency

Version 1.x (Pygame-based - Legacy)

  • 1.4.24 - Previous stable release with pure Python vectors and pygame
  • Legacy versions available via: pip install "e2D<2.0"

Made with ❤️ for high-performance 2D development

Metadata

Release files for e2D 2.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for e2D 2.1.8
File Size Uploaded
e2d-2.1.8.tar.gz 458.4 kB Details

Release files / e2d-2.1.8.tar.gz

Download URL e2d-2.1.8.tar.gz
Size 458.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6d2332b69dde6c36244c69bb2e2882126ef52c05356e413ad28929275cb9bfde
BLAKE2b-256 checksum
How to use checksums
3abd9ebe7a9d63ac8df70c7c244d8f5f4ce9bf279277806db4191c5f5d52dc83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.1.8 This release

1 release file

2.1.7

1 release file

2.1.6

1 release file

2.1.5

1 release file

2.1.4

1 release file

2.1.2

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.3

1 release file

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.4.24

2 release files

1.4.23

2 release files

1.4.22

2 release files

1.4.21

2 release files

1.4.18

2 release files

1.4.17

2 release files

1.4.16

2 release files

1.4.15

2 release files

1.4.14

2 release files

1.4.13

2 release files

1.4.12

2 release files

1.4.11

2 release files

1.4.10

2 release files

1.4.9

2 release files

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.13

2 release files

1.3.12

2 release files

1.3.11

2 release files

1.3.10

2 release files

1.3.9

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.12

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page