A beautiful and simple rendering library for Python
Project description
PyRender 🎨
A beautiful and simple 2D rendering library for Python. PyRender provides an elegant API for creating graphics, visualizations, and animations with ease.
✨ Features
- Simple & Intuitive API - Clean, fluent interface for creating graphics
- Rich Primitives - Rectangles, circles, lines, polygons, text, gradients, and images
- Flexible Transformations - Position, rotation, and scale with matrix support
- Camera System - Pan, zoom, and navigate your scenes
- Visual Effects - Shadows, blur, glow, and outlines
- Scene Management - Organize and layer your graphics with z-indexing
- Anti-aliasing - Crisp, high-quality output with supersampling
- Color Tools - RGB, HSV, hex support with beautiful palettes
📦 Installation
pip install pyrender-lib
Or install from source:
git clone https://github.com/yourusername/pyrender.git
cd pyrender
pip install -e .
🚀 Quick Start
from pyrender import Renderer, Scene, Rectangle, Circle, ColorPalette
# Create renderer and scene
renderer = Renderer(800, 600)
scene = Scene(background_color=ColorPalette.WHITE)
# Add some shapes
scene.add(Rectangle(100, 100, 200, 150, color=ColorPalette.BLUE))
scene.add(Circle(400, 300, 80, color=ColorPalette.RED))
# Render and save
renderer.save(scene, "output.png")
📚 Examples
Creating Shapes
from pyrender import *
renderer = Renderer(800, 600)
scene = Scene()
# Rectangle with rounded corners
rect = Rectangle(50, 50, 200, 100, color=ColorPalette.INDIGO)
rect.set_corner_radius(10)
scene.add(rect)
# Circle
circle = Circle(400, 300, 60, color=ColorPalette.PINK, fill=True)
scene.add(circle)
# Line
line = Line(100, 100, 700, 500, color=ColorPalette.GRAY_DARK, width=3)
scene.add(line)
# Polygon (triangle)
triangle = Polygon(
[(300, 100), (250, 200), (350, 200)],
color=ColorPalette.TEAL,
fill=True
)
scene.add(triangle)
# Text
text = Text(400, 50, "Hello, PyRender!", color=ColorPalette.BLACK, font_size=32)
text.set_bold(True)
scene.add(text)
renderer.save(scene, "shapes.png")
Working with Colors
from pyrender import Color, ColorPalette
# Create colors in different ways
red = ColorPalette.RED
blue = Color.from_rgb(0, 100, 255)
green = Color.from_hex("#00FF00")
purple = Color.from_hsv(0.8, 0.6, 0.9)
# Blend colors
pink = red.blend(ColorPalette.WHITE, 0.5)
# Create gradient
gradient = ColorPalette.gradient(ColorPalette.BLUE, ColorPalette.PURPLE, steps=10)
Transformations
from pyrender import *
scene = Scene()
# Create and transform a rectangle
rect = Rectangle(0, 0, 100, 100, color=ColorPalette.ORANGE)
rect.transform.translate(200, 150)
rect.transform.rotate(0.785) # 45 degrees in radians
rect.transform.scale(1.5, 1.5)
scene.add(rect)
Camera Control
renderer = Renderer(800, 600)
scene = Scene()
# Add some objects
for i in range(10):
scene.add(Circle(i * 100, 300, 30, color=ColorPalette.BLUE))
# Move camera
renderer.camera.set_position(200, 0)
renderer.camera.set_zoom(1.5)
renderer.save(scene, "camera.png")
Creating Gradients
from pyrender import Gradient, Color
gradient = Gradient(
0, 0, 800, 600,
color_start=Color.from_hex("#FF6B6B"),
color_end=Color.from_hex("#4ECDC4"),
angle=0.785 # 45 degrees
)
scene = Scene()
scene.add(gradient)
Layering with Z-Index
scene = Scene()
# Background
bg = Rectangle(0, 0, 800, 600, color=ColorPalette.GRAY_LIGHT)
bg.z_index = 0
scene.add(bg)
# Middle layer
circle = Circle(400, 300, 100, color=ColorPalette.BLUE)
circle.z_index = 1
scene.add(circle)
# Foreground
text = Text(400, 300, "Front!", color=ColorPalette.WHITE, font_size=48)
text.z_index = 2
scene.add(text)
Anti-aliasing
renderer = Renderer(800, 600)
# Enable high-quality anti-aliasing
renderer.set_antialiasing(True, scale=4) # 4x supersampling
scene = Scene()
# ... add your shapes ...
renderer.save(scene, "smooth.png")
🎨 Color Palettes
PyRender includes beautiful built-in colors:
# Basic colors
ColorPalette.BLACK, WHITE, RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA
# Grays
ColorPalette.GRAY_LIGHT, GRAY, GRAY_DARK
# Material Design colors
ColorPalette.INDIGO, PURPLE, PINK, ORANGE, TEAL
# Transparent
ColorPalette.TRANSPARENT
🛠️ Advanced Features
Custom Transformations
from pyrender import Transform, Matrix3x3
# Create custom transformation matrix
transform = Transform(x=100, y=100, rotation=0.5, scale_x=2.0, scale_y=1.5)
matrix = transform.to_matrix()
# Apply to points
new_x, new_y = matrix.transform_point(50, 50)
Scene Queries
scene = Scene()
# ... add primitives ...
# Find object at position
obj = scene.find_at_position(400, 300)
# Get scene bounds
x_min, y_min, x_max, y_max = scene.get_bounds()
# Get all visible objects sorted by z-index
objects = scene.get_primitives_sorted()
📖 API Reference
Renderer
Renderer(width, height, mode=RenderMode.NORMAL)- Create rendererrender(scene)- Render scene to PIL Imagesave(scene, filename)- Render and save to fileset_antialiasing(enabled, scale=2)- Configure anti-aliasing
Scene
Scene(background_color=None)- Create sceneadd(primitive)- Add primitive to sceneremove(primitive)- Remove primitiveclear()- Remove all primitivesfind_at_position(x, y)- Find primitive at position
Primitives
Rectangle(x, y, width, height, color, fill, stroke_width)Circle(x, y, radius, color, fill, stroke_width)Line(x1, y1, x2, y2, color, width)Polygon(points, color, fill, stroke_width)Text(x, y, text, color, font_size, font_family)Gradient(x, y, width, height, color_start, color_end, angle)Image(x, y, image_path, width, height)
🤝 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.
🙏 Acknowledgments
- Built with Pillow for image processing
- Inspired by modern graphics libraries and elegant API design
📞 Support
- Documentation: https://pyrender.readthedocs.io
- Issues: https://github.com/yourusername/pyrender/issues
- Discussions: https://github.com/yourusername/pyrender/discussions
Made with ❤️ by the PyRender Team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyrenderer-0.1.0.tar.gz.
File metadata
- Download URL: pyrenderer-0.1.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da85059214e3343d65a893c1da017ebb0f00f2c9a0e2e7967f98aeaa5a3393e9
|
|
| MD5 |
eb75e4a3cfa5df792f32e41a99ab19ca
|
|
| BLAKE2b-256 |
a5090a6b5667c44f25e089050950c7b205ab7b7cad146434fe4764f5f0e0931e
|
File details
Details for the file pyrenderer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyrenderer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cda4a7627f9c38dbc8ab2209c7b26a8494db70b834bd4b0ca242f55fa7b3162
|
|
| MD5 |
7a2f9f9d29071feed67d6b049708917c
|
|
| BLAKE2b-256 |
63dd58b732cde7f6148f0e500f60ec1b6df69b22d5f65f191ef498d5a5eba662
|