Skip to main content

A Python tool for rendering GIFs and custom animations as ASCII art directly in the terminal.

Project description

ci PyPI version

ascii-animator

A Python tool for rendering GIFs and custom animations as ASCII art directly in the terminal.

It supports two main use cases:

  • play an animated GIF as ASCII in the terminal
  • build your own terminal animations with Python

Installation

pip install ascii_animator

CLI

The package installs the ascii-art-animator command.

Usage

usage: ascii-art-animator [-h] [-s SPEED] [-f FILE] [-d] [-a] [-m MAX_LOOPS] [-c COLUMNS]

Ascii Art Animator from GIF

optional arguments:
  -h, --help            show this help message and exit
  -s SPEED, --speed SPEED
                        speed of the animation: very_slow, slow, normal, fast (default normal)
  -f FILE, --file FILE  the path to a gif file
  -d, --debug           display debug messages to stdout
  -a, --show_axis       display the grid axis
  -m MAX_LOOPS, --max_loops MAX_LOOPS
                        maximum number of loops, set to 0 to loop through image until keyboard interrupt (default 1)
  -c COLUMNS, --columns COLUMNS
                        the number of characters per row (default 150)

Example

ascii-art-animator -f docs/images/marcovich.gif -a -m 3 -c 100

input

example

output

example

Python API

Play a GIF

from ascii_animator import Animator, AsciiAnimation, Speed

Animator(
    animation=AsciiAnimation("docs/images/marcovich.gif", columns=100),
    speed=Speed.NORMAL,
    max_loops=1,
)

Creating custom animations

Subclass Animation and implement:

  • grid - returns the current frame (list of rows)
  • cycle() - updates state and returns True when a full cycle completes

Example: Bouncer

from ascii_animator import Animator, Animation, Speed

class Bouncer(Animation):
    def __init__(self, width=20):
        self.y_size = 1
        self.x_size = width
        self.position = 0
        self.direction = 1
        self._grid = [[" " for _ in range(self.x_size)]]
        self._draw()

    @property
    def grid(self):
        return self._grid

    def _draw(self):
        self._grid[0] = [" " for _ in range(self.x_size)]
        self._grid[0][self.position] = "●"

    def cycle(self):
        if self.position == self.x_size - 1:
            self.direction = -1
        elif self.position == 0:
            self.direction = 1
        self.position += self.direction
        self._draw()
        return self.position == 0

Animator(
    animation=Bouncer(),
    speed=Speed.NORMAL,
    max_loops=3)

example

Generator-based animations

cycle() can also be impleted as a generator that yields once per frame update. This is useful for step-by-step visualizations (e.g. sorting, searching). If the animation needs to replay, implement reset() to restore initial state.

Speed presets:

from ascii_animator import Speed

Speed.VERY_SLOW
Speed.SLOW
Speed.NORMAL
Speed.FAST

Included Examples

Selection Sort Animation

A selection sort search is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the unsorted portion of the list and moving it to the sorted portion of the list.

example

Here is another example of a selection sort animation this time using vertical bars.

example

Plasma Wave Animation

A plasma wave animation.

example

Vortex Reactor

A chromatic vortex reactor animation.

example

Matrix Animation

A Matrix animation.

example

Game-Of-Life

A Conway Game-Of-Life implementation that uses ascii_animator to display the game to the terminal.

Development

Clone the repository and ensure the latest version of Docker is installed on your development server.

Build the Docker image:

docker image build \
--target build-image \
-t ascii-animator:latest .

Run the Docker container:

docker container run \
--rm \
-it \
-v $PWD:/code \
ascii-animator:latest \
bash

Execute the build:

make dev

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

ascii_animator-0.3.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

ascii_animator-0.3.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file ascii_animator-0.3.0.tar.gz.

File metadata

  • Download URL: ascii_animator-0.3.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for ascii_animator-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c7e472250207b5b8fca9e00cd8a2305667358f51327f6e5d138802dc1d658e60
MD5 c028c74b8af4b6b581c9bc48296cce25
BLAKE2b-256 d598d425e0d351b57c6335866357f50d241b643f0cd82dc5f5c1f891be757ce5

See more details on using hashes here.

File details

Details for the file ascii_animator-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ascii_animator-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for ascii_animator-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec64b5395bd44080cd1f95045d2315f7f95201cfad07cbd69dc8e845a29ac90e
MD5 c180e93f60e562a9a38e2ac23a25610e
BLAKE2b-256 170beb5b364eeaa83347dbf5e05341183613bf483f802c2807e5e0c0adc0bfec

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