A powerful, custom-built graphics rendering engine for terminal-based applications, featuring real-time sprite rendering, animation systems, and interactive game development capabilities.
This project demonstrates advanced terminal graphics manipulation using ANSI escape codes and custom rendering algorithms. It includes a complete 2D game engine with chunk-based world management, entity systems, and pixel-perfect sprite rendering—all running entirely in the terminal.
Main Project: A puzzle-strategy game where players navigate levels, collect resources, manipulate blocks, and solve spatial challenges using TNT explosions and environmental interactions.
A comprehensive graphics library that transforms the terminal into a pixel-perfect canvas using ANSI color codes.
1. Advanced Rendering System
- Double-buffered rendering for flicker-free display
- Efficient screen updates using ANSI cursor positioning
- Alpha compositing with color-aware blending
- Layered drawing with transparent color support
2. Geometric Primitives
# Lines using Bresenham's algorithm
drawLine(screen, color, (x1, y1), (x2, y2))
# Shapes and fills
square(height, width, color)
hollowSquare(height, width, outer_color, inner_color)
fillTrapezoid(screen, color, p1, p2, p3, p4)
# Advanced shapes
drawTriangle(screen, color, p1, p2, p3)
drawPG(screen, color, width, length, point) # Parallelogram3. Matrix Transformations
rotate(matrix, degrees)- 90°, 180°, 270° rotationsmirror(matrix)- Horizontal flipflip(matrix)- Vertical fliptranspose(matrix)- Matrix transposition
4. Color Manipulation & RGB System
# Dynamic RGB to ANSI conversion
rgb(r, g, b) # Converts any RGB to closest ANSI color
# Color operations
changeRGB(object, oldRGB, newRGB) # Non-destructive color swap
replaceRGB(object, oldRGB, newRGB) # In-place color replacement
addBorder(object, oldColor, newColor) # Intelligent border detection
addPerimeter(object, borderColor, thickness) # Outline generation5. Smart Compositing Functions
# Standard blitting
addToScreen(screen, obj, x, y, getDrawnOver=False)
# Conditional rendering
addToScreenOnColor(screen, obj, onColor, x, y) # Only draw on specific colors
addToScreenWithColor(screen, obj, withColor, x, y) # Only draw specific colors
addToScreenWithoutColor(screen, obj, color, x, y) # Skip specific colors (transparency)6. Scene Management
screen(height, width, filling)- Initialize rendering canvasprintScreen(screen, clear, hideCursor)- Optimized display outputgetFromScreen(screen, x, y, height, width)- Region extractionscanArea(screen, point, height, width)- Pixel data sampling
- Bresenham's Line Algorithm for pixel-perfect line rendering
- Slope detection for adaptive drawing orientation
- Buffer management using StringIO for smooth animation
- Color palette optimization with 256-color ANSI support
- Zero external graphics dependencies - pure Python implementation
A sophisticated image processing pipeline that converts PNG assets into terminal-renderable sprite data.
1. Image Processing Pipeline
class pixelImage:
def __init__(self, img_paths, oldColor, newColor, findPixel, trim)
# Loads PNGs, converts to RGB, maps to ANSI codesProcess Flow:
- Load PNG using Pillow
- Convert to RGB color space
- Map each pixel to closest ANSI 256-color code
- Cache mappings in
ansi_dict.gplfor performance - Generate 2D arrays of ANSI escape sequences
2. Color Mapping & Optimization
# Intelligent color matching
def rgb(r, g, b):
# Uses Euclidean distance in RGB space
# Caches results for O(1) lookup on subsequent calls
distance = sum((x1-x2)**2 for x1, x2 in zip(c1, c2))
closest_color = min(ansi_colors, key=lambda c: distance(rgb, c))3. Sprite Management
class Pixel:
# Represents a sprite with transformation capabilities
setPixel(row, col, color)
replacePixels(oldColor, newColor)
rotate(degrees)
flip() / rotateLeft() / rotateRight()4. Sprite Sheet System
# Automatic sprite extraction from sheets
def scanSpriteSheet(sheet, sprite_list, y_position):
for i, sprite in enumerate(sprite_list):
sprite.setSprite(
scanArea(sheet, (i*BLOCK_SIZE, y_position),
BLOCK_SIZE, BLOCK_SIZE)
)- Persistent color cache - RGB→ANSI mappings saved to disk
- Lazy loading - Sprites loaded on-demand
- Memory-efficient - Shared references for identical colors
- Trim optimization - Automatic cropping of transparent regions
class ChunkLoader:
# Manages game world as discrete chunks
# Enables procedural generation and dynamic loading
def generateChunks(self)
def loadMap(self, chunkNumber, mapData, blockMap)
def fillScreenWithChunk(self, screen, chunk)class Player:
# Position, inventory, health management
# Direction tracking and movement calculation
def calculateMovement(self, forceDirection=False)class Block:
# Properties: solid, moveable, breakable, background
# Enables dynamic world interactionclass Animation:
# Frame-based sprite animation
# Used for TNT explosions, effects
getSprite(frame)- 60+ FPS rendering capability in terminal
- Sub-10ms screen update times
- Zero screen flicker using double buffering
- 256-color palette support
- Modular architecture - Clear separation of concerns
- Reusable components - DrawingAPI works standalone
- Clean abstractions - Easy to extend and maintain
- Comprehensive type hints - Self-documenting code
- Bresenham's Line Algorithm - Efficient rasterization
- Flood Fill Variations - Border detection algorithms
- Sprite Blitting - Multiple blending modes
- Color Distance Calculation - Perceptual color matching
- Matrix Transformations - Rotation and reflection
pip install -r requirements.txt
# Dependencies: pynput, Pillow, numpypython game.py- WASD - Movement
- E - Break blocks (pickaxe)
- B - Detonate TNT
- T - Place TNT
- Q - Craft health potion (3 diamonds)
- V - Use health potion
- Z/C - Switch between levels
- M - Reset current level
from DrawingAPI import *
# Create a screen
scene = screen(30, 50, cyan)
# Draw shapes
drawLine(scene, red, (0, 0), (49, 29))
addToScreen(scene, square(10, 10, yellow), 20, 10)
# Add sprite with transparency
sprite = hollowSquare(5, 5, white, cyan)
addToScreenWithoutColor(scene, sprite, cyan, 25, 15)
# Render
printScreen(scene)import time
# Rotating sprite
sprite = square(8, 8, red)
for degrees in [0, 90, 180, 270]:
rotated = rotate(sprite, degrees)
addToScreen(scene, rotated, 20, 10, True)
printScreen(scene)
time.sleep(0.1)Skills Demonstrated:
- Low-level graphics programming and rendering optimization
- Algorithm implementation (Bresenham's, color matching)
- Object-oriented design and software architecture
- Performance optimization and memory management
- Cross-platform compatibility (Windows/macOS/Linux)
- Real-time system programming
- Creative problem-solving with constrained resources
Technical Depth:
- Built complete 2D rendering engine from scratch
- Implemented double buffering for smooth 60 FPS performance
- Developed sprite sheet parsing and asset management pipeline
- Created chunk-based world system with dynamic loading
- Designed entity component system for game objects
Project Scale:
- 2000+ lines of original code
- Modular architecture with 6+ custom libraries
- Full game with multiple levels and mechanics
- Comprehensive animation and effects systems
screen(height, width, filling)- Create rendering canvasprintScreen(screen, clear, hideCursor)- Display to terminalclearScreen(screen, newColor)- Reset canvas
drawLine(screen, color, p1, p2)- Bresenham linesquare(height, width, color)- Filled rectanglehollowSquare(height, width, outer, inner)- Bordered rectangledrawTriangle(screen, color, p1, p2, p3)- Triangle outlinefillTrapezoid(screen, color, p1, p2, p3, p4)- Filled quadrilateral
addToScreen(screen, obj, x, y)- Standard blitaddToScreenWithoutColor(screen, obj, transparentColor, x, y)- Alpha blitgetFromScreen(screen, x, y, height, width)- Extract region
rotate(matrix, degrees)- Rotate 90°/180°/270°mirror(matrix)- Horizontal flipflip(matrix)- Vertical flip
rgb(r, g, b)- RGB to ANSI conversionchangeRGB(obj, oldRGB, newRGB)- Color replacementaddBorder(obj, oldColor, newColor)- Smart border
pixelImage(paths, oldColor, newColor, findPixel, trim)- Load spritesgetPixel(index)- Get Pixel object for manipulationgetPixelImage(index)- Get raw 2D array
replacePixels(oldColor, newColor)- Color swaprotate(degrees)- Transform spritegetImage()- Export as 2D array
# Create animated sprite
sprite = square(16, 16, cyan)
drawTriangle(sprite, yellow, (8,4), (4,12), (12,12))
addPerimeter(sprite, white, 1)
# Apply to game
block = Block("Custom", sprite, solid=True)# Explosion effect using color interpolation
for radius in range(1, 10):
color = interpolate_color(red, yellow, radius/10)
drawSetSquare(scene, color, center, radius)
printScreen(scene)
time.sleep(0.05)This project demonstrates advanced terminal graphics techniques and game engine architecture. The DrawingAPI and ImageReader libraries are modular and can be extracted for use in other terminal-based applications.
Author: [Your Name]
Technologies: Python, ANSI Escape Codes, Pillow, NumPy
Year: 2024
This project provided hands-on experience with:
- Graphics rendering pipelines and optimization
- Real-time system programming constraints
- Algorithm implementation and analysis
- Software architecture and design patterns
- Cross-platform development considerations
- Asset management and resource optimization
Perfect for demonstrating to employers: systems programming, graphics programming, game development, and software architecture skills.