Skip to main content

DisplayLib

A collection of frameworks used to display ASCII or Pygame graphics in an infite world

Requires Python version >= 3.10


Submodules

  • template
  • ascii (default)
  • pygame

Networking support

DisplayLib provides mixin classes for enabling networking. Networking is available in each submodule through dl.networking (when using import displaylib.[mode] as dl).

To create a Client, use:

class MyApp(dl.Engine, dl.Client): ...

Creating a Server is as simple as:

class MyServer(dl.Engine, dl.Server): ...

Example using displaylib in ascii mode:

import displaylib.ascii as dl
# mode selected   ^^^^^


class Square(dl.Node2D, dl.Texture):
    def __init__(self, parent: dl.Node | None = None, x: int = 0, y: int = 0) -> None:
        super().__init__(parent, x, y) # the most important arguments to pass down
        self.texture = [ # you can use this style to define its visual
            [*"OO+OO"], # the "+" represents transparancy
            [*"O+++O"], # changed through `dl.Node2D.cell_transparancy`
            [*"OO+OO"]
        ]

    def _update(self, delta: float) -> None: # called every frame
        if len(self.texture[1]) == 5: # modifying the middle line
            self.texture[1].append(")")
        else:
            self.texture[1].pop()
    

class App(dl.Engine):
    def _on_start(self) -> None: # use this instead of __init__
        # -- config
        dl.Screen.cell_transparant = "+" # represents transparancy
        dl.Screen.cell_default = "." # changes background default
        # -- create nodes
        self.my_square = Square(x=5, y=3)
        # nodes are kept alive by `Node.nodes` (dict) by default
        # this means `del self.my_square` is needed to fully free it
        self.direction = 1
    
    def _update(self, delta: float) -> None: # called every frame
        if self.direction == 1:
            self.my_square.position.x += 1
            if self.my_square.position.x == 22:
                self.direction = -1
        elif self.direction == -1:
            self.my_square.position.x -= 1
            if self.my_square.position.x == 4:
                self.direction = 1

if __name__ == "__main__":
    # autorun on instance creation
    app = App(tps=4, width=24, height=8)

Example using displaylib in pygame mode:

import displaylib.pygame as dl
# mode selected   ^^^^^^
import pygame # import pygame

import random
import math


class Cirlce(dl.Node2D):
    def __init__(self, parent: dl.Node | None = None, x: int = 0, y: int = 0) -> None:
        super().__init__(parent, x, y)
        self.radius = 20
        self.width = 2
        self.time_elapsed = 0.0
    
    def _update(self, delta: float) -> None:
        self.time_elapsed += delta
        self.width = round(math.cos(self.time_elapsed) * 3 +5)
    
    def _render(self, surface: pygame.Surface) -> None:
        pygame.draw.circle(surface, (200, 50, 255), (self.position.x, self.position.y), self.radius, self.width)


class App(dl.Engine):
    def _on_start(self) -> None:
        print("= Started Pygame program")
        self.circle = Cirlce(x=200, y=100)
        self.elapsed_time = 0.0
    
    def _update(self, delta: float) -> None:
        self.circle.position = dl.Vec2(
            math.cos(self.elapsed_time) * 50,
            math.sin(self.elapsed_time) * 50
        ) + dl.Vec2i(200, 100)
        self.elapsed_time += delta
    
    def _render(self, surface: pygame.Surface) -> None:
        pygame.draw.line(surface, color=(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)), start_pos=(50, 50), end_pos=(200, 100), width=5)


if __name__ == "__main__":
    app = App("Pygame example using DisplayLib")

Metadata

Release files for displaylib 0.0.7

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

Source distribution (sdist)

Source distribution for displaylib 0.0.7
File Size Uploaded Provenance Actions
displaylib-0.0.7.tar.gz 26.2 kB Without provenance Details for displaylib-0.0.7.tar.gz

Release files / displaylib-0.0.7.tar.gz

Download URL displaylib-0.0.7.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3df171a7085bcc570094f7571abb163d7c71db03b5bd424588df2df9a5e6f16e
BLAKE2b-256 checksum
How to use checksums
e278f031797802ce3fb15dc806e9add90b8e268d6b7d5fcef5d2a29e4330c30c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Security for displaylib 0.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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