Skip to main content

3D TUI-based rasterization engine

Project description

Liquid-Red

A Python 3D rasterizer engine running entirely in the terminal. No GPU, no display server — just ASCII characters and math. Built on perspective projection, barycentric rasterization, a z-buffer, and Lambert shading. Designed to be used as a library for TUI 3D applications and games.


Features

  • Perspective projection with configurable focal length and zoom
  • Z-buffer for correct depth ordering
  • Barycentric triangle rasterization
  • Lambert shading with ASCII intensity ramp
  • Camera with yaw/pitch rotation and jump physics
  • Plane drawing helpers (draw_plane_xy, draw_plane_xz, draw_plane_yz)
  • Solid cube with faces and wireframe edges
  • Keyboard input via pynput

Installation

pip install pynput numpy LiquidRed

Quick Start

import time
from LiquidRed.camera import Camera
from LiquidRed.grid import Renderer
from LiquidRed.events import pressed
from LiquidRed.geometry import Point3d
import numpy as np
 
CANVAS_WIDTH = 64
CANVAS_HEIGHT = 32
LIGHT = np.array([0, 0, -1])
 
camera = Camera(x=0, y=0, z=-5)
renderer = Renderer(camera, light_direction_vector=LIGHT)
 
last_update = 0
 
while True:
    now = time.time()
    if now - last_update < 1 / 60:
        continue
    last_update = now
 
    camera.update(pressed, now)
    renderer.clear_grid()
 
    # draw a floor plane
    renderer.draw_plane_xz(-4, 4, 0, 20, 2)
 
    renderer.show_grid()

Cube(size, cx, cy, cz)

A solid cube centered at (cx, cy, cz).

from LiquidRed.objects import Cube
 
cube = Cube(size=2, cx=0, cy=0, cz=5)
 
# Draw as solid faces
for v0, v1, v2, v3 in cube.faces:
    renderer.draw_plane(v0, v1, v2, v3)
 
# Draw as wireframe
for i, j in cube.edges:
    renderer.draw_line(cube.vertices[i], cube.vertices[j])

Coordinate System

      -Y (up)
       |
       |
-X ----+---- +X
       |
       |
      +Y (down)
 
+Z = into the screen (away from camera)
-Z = toward the camera

Camera starts at negative Z looking toward positive Z. Place objects at positive Z values to put them in front of the camera.


Example: Corridor Scene

from LiquidRed.camera import Camera
from LiquidRed.grid import Renderer
from LiquidRed.events import pressed
import numpy as np, time
 
camera = Camera(z=-1)
renderer = Renderer(camera, np.array([0, 0, -1]))
 
W, H = 4, 3  # corridor half-width, half-height
 
while True:
    now = time.time()
    camera.update(pressed, now)
    renderer.clear_grid()
 
    # floor, ceiling, left wall, right wall
    renderer.draw_plane_xz(-W, W, 0, 30,  H)   # floor
    renderer.draw_plane_xz(-W, W, 0, 30, -H)   # ceiling
    renderer.draw_plane_yz(-H, H, 0, 30, -W)   # left
    renderer.draw_plane_yz(-H, H, 0, 30,  W)   # right
 
    renderer.show_grid()
    time.sleep(1/60)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liquidred-0.1.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liquidred-0.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file liquidred-0.1.1.tar.gz.

File metadata

  • Download URL: liquidred-0.1.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for liquidred-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8d7535e56f5458731fabec7c5afdda3313d392a523642a6fce72f6687e4fb726
MD5 037272bbaa929750fe9cfa145e5ce049
BLAKE2b-256 d839eb8de1755cdd7bceea36ad7d2dab5c1589158be19b25ac5f146586c4e3ac

See more details on using hashes here.

File details

Details for the file liquidred-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: liquidred-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for liquidred-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4e12e616fb03c6fa7044a10ca3525a0e6922f3046d2556b37f0d70f3eb30688
MD5 3043c91898afb52f35fa5f05476b92f0
BLAKE2b-256 4ff814006bfee293f3d6851d2e3d3a37a5117d96cf6121a095cc580c98848b7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page