Skip to main content

ASCIM - Manipulate ASCII art as you would do with raster images

Upload Python Package PyPI

Pre-document Humor

Do you know why the crazy guy started a side project to feed another one?

No, you should ASCIM.

If you came here from memethesis-cli, go straight to section 'ASCIM Tables'.

Installation

pip install ascim will do.

Usage

Basic ASCIM Class

from ascim.ascim import ASCIM
im = ASCIM('''In ASCIM,
every character
is like
a pixel''')

im is now an ASCIM object, with the following text (enclosed in rectangle*):

 +-----------------+
0| In ASCIM,       |
1| every character |
2| is like         |
3| a pixel         |
 +-----------------+

Lines 0, 2, and 3, which are zero-indexed, are padded with spaces to their right so that they are all uniform in length with Line 1. An ASCIM object is treated as an image, so string methods no longer apply.

* but what is in this rectangle? We will cover this later on in section 'ASCIM Tables'.

ASCIM Tables

An ASCIM Table is a container object of ASCIM Images. An ASCIM Image (or NoneType) can take up one cell in a table, just like in spreadsheets.

Code example:

from ascim.ascim import ASCIM
from ascim.table import ASCIMTable

table = ASCIMTable.from_text('<copy paste that table from below>')
print(table.cell_at(0, 0).to_text())  # => 'symbol'
print(table.size)  # => (4, 7)

Textual representation

The textual representation for ASCIM Tables are designed to be both machine- and human-readable. Here is an example: (relevant xkcd)

+--------+---------------+---------------+------------------------+
| symbol | name          | size          | notes                  |
+--------+---------------+---------------+------------------------+
| kB     | Kilobyte      | 1024 bytes    | 1000 bytes during leap |
|        |               | or 1000 bytes | years, 1024 otherwise  |
+--------+---------------+---------------+------------------------+
| KB     | Kelly-Bootle  | 1012 bytes    | Compromise between     |
|        | Standard Unit |               | 1000 and 1024 bytes    |
+--------+---------------+---------------+------------------------+
| KiB    | Imaginary     | 1024sqrt(-1)  | Used in quantum        |
|        | Kilobyte      | bytes         | computing              |
+--------+---------------+---------------+------------------------+
| kb     | Intel         | 1023.937528   | Calculated on          |
|        | Kilobyte      | bytes         | Pentium F.P.U          |
+--------+---------------+---------------+------------------------+
| Kb     | Drivemaker's  | Currently     | Shrinksby 4 bytes each |
|        | Kilobyte      | 908 bytes     | year for marketing     |
|        |               |               | reasons                |
+--------+---------------+---------------+------------------------+
| KBa    | Baker's       | 1152 Bytes    | 9 bits to the byte     |
|        | Kilobyte      |               | since you're such a    |
|        |               |               | good customer          |
+--------+---------------+---------------+------------------------+
Specification
  1. A cell is an ASCIM object or NoneType stored in the ASCIMTable. When printed, it is enclosed with + and - horizontally and + and | vertically. NoneType denotes there is no content in the cell, and is interpreted as an 1x1 ASCIM object when displayed.

  2. On each side of the pipe (vertical bar; |) that is a cell MUST be a space. As illustrated:

    +---+
    |012|
    |345|
    |678|
    +---+
    

    In this rect-enclosed area, the "cell" only covers 1, 4, and 7. Locations 0, 3, 6, 2, 5, 8 MUST be a space. Locations 1 and 7 SHOULD NOT be a space. That said, only horizontal margins are necessary.

  3. When a row is too wide or a column is too tall in the text to convert to an ASCIMTable, the excess columns/rows of spaces are cut off.

ASCIM Draw

With ASCIMDraw you can make in-place modifications with an ASCIM Image. An ASCIMDraw object takes a (reference to) an ASCIM object as its argument.

Code example:

from ascim.ascim import ASCIM
from ascim.draw import ASCIMDraw

im = ASCIM.new((5, 5))
draw = ASCIMDraw(im)
draw.text((1, 2, 4, 2), 'oh nice')  # text is wrapped in a 4x2 box
# `im` is modified in-place
print(im.to_text())
#
#
#  oh
#  nice
#

Release files for ascim 0.1.1

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

Source distribution (sdist)

Source distribution for ascim 0.1.1
File Size Uploaded
ascim-0.1.1.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ascim 0.1.1
File Interpreter ABI Platform
ascim-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.1 kB

Release files / ascim-0.1.1.tar.gz

Download URL ascim-0.1.1.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3447cf7be4fe1a4807fbb72f3b950c93a9f03ba448555480c5b8f0d70f13726a
BLAKE2b-256 checksum
How to use checksums
19bf047f3682a7046ccb5d227edcda3c7164e5df650d3793f9d0a4372435fc14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release files / ascim-0.1.1-py3-none-any.whl

Download URL ascim-0.1.1-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f8aef1e84c96cf01a64dd4875d5fb796e0d0282d90e6272c1a38179b7b20b86
BLAKE2b-256 checksum
How to use checksums
7e263c7f468e1ea55d80d515ff8971aeeca670812cfd97d94b4f78ad046304ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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