Skip to main content

Simple Bresenham implementation

This is a very simple Bresenham implementation for enumerating pixels along a line including a very simple anti aliased version. It's the felt infinite implementation out there and has been implemented during enhancement of a tomography reconstruction library for personal use.

Dependencies

  • numpy >= 1.25

Installation

pip install pybresenham-tspspi

Usage

Simple lines

import matplotlib.pyplot as plt
import numpy as np

from bresenham.bresenham import trace_line

fig, ax = plt.subplots()

img = np.zeros((51, 21))
for pt in trace_line((-25,-10),(10,10)):
    img[int(pt[0]) + 25, int(pt[1]) + 10] = 1
ax.imshow(img)

Simple lines using callbacks

from bresenham.bresenham import trace_line

def mycallback(point):
    print(f"Point at {point[0]} x {point[1]}")

trace_line((-25,-10),(10,10),mycallback)

Antialiased lines

import matplotlib.pyplot as plt
import numpy as np
from bresenham.bresenham import trace_line_antialiased_it

fig, ax = plt.subplots()

imgaa = np.zeros((51, 21))
for pt, weight in trace_line_antialiased_it((-25,-10),(10,10)):
    imgaa[int(pt[0]) + 25, int(pt[1]) + 10] = weight
ax.imshow(imgaa)

Antialiased lines using callbacks

from bresenham.bresenham import trace_line_antialiased

def mycallback(point, weight):
    print(f"Point at {point[0]} x {point[1]} with weight {weight}")

trace_line_antialiased((-25,-10),(10,10),mycallback)

Metadata

Release files for pybresenham-tspspi 0.0.2

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

Source distribution (sdist)

Source distribution for pybresenham-tspspi 0.0.2
File Size Uploaded
pybresenham-tspspi-0.0.2.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pybresenham-tspspi 0.0.2
File Interpreter ABI Platform
pybresenham_tspspi-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / pybresenham-tspspi-0.0.2.tar.gz

Download URL pybresenham-tspspi-0.0.2.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6d3df4a612c21e1883d486800f5e9f1ecccbe53ee22e9c09731fccf64dacc96c
BLAKE2b-256 checksum
How to use checksums
931de72be66857b78b1a79c7ff1695e3e0603dbec6da1735c4a0dbfa88301291
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.13

Release files / pybresenham_tspspi-0.0.2-py3-none-any.whl

Download URL pybresenham_tspspi-0.0.2-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b927951ce5298006160821066c69355ccafdf83fa6f3d68add985b497f8d13ad
BLAKE2b-256 checksum
How to use checksums
828156c8b872d10c377210b1f83617a47ad958e4b01e5b0f4428cc39bf0838f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.13

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

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