AsciiImage for Delphi

I just finished a first version of an AsciiImage-Implementation for Delphi. It’s available on Github. For those not familiar with it:

2 Month ago, Charles Parnot posted an article about using simple Ascii-Art for rendering images. For a more detailed look on how things work, take a look at his Post: Replacing Photoshop with NSString

The basics are quite simple. You define an array of strings and fill it with a sequence of Chars representing shapes. The AsciiImage uses this string array to paint an actual image made of Shapes(Ellipsis, Lines, Dots and Polygons). The valid characters for sequences are(in THIS order):

1-9 A-Z a-z

All other characters are IGNORED. And this is how they are used to form shapes:

  • if it’s a Character-Sequence (like 1, 2, 3 or 9, A, B), it’s a Polygon. As soon as this sequence breaks (like 1, 2, 3, 4, 6) or is broken up by another type of shape, the Polygonsequence ends. A Polygon with only one Character is rendered as dot.
  • if a character occurs twice, it creates a line
  • if a character occurs 3 or more times, it forms an ellipsis with a boundingbox which fits around all characters.

 

This can look like this:

Chefron

The Memo contains the Ascii-Sequence and on the right is the resulting image. The image is an upscaled version(like Vectorgraphics, it scales!). By looking at the grid, you see how the upscaled version snaps to the native-resolution:

Chefron-Grid

You can go quite crazy with it and do more complex shapes, too:

Lock

For more complex shapes like this lock, it is required to alter each shape(modifying Fill and StrokeColor). The source behind this example looks like this:

Lock-Source

AsiiImage derives from TGraphic, which allows us to use it in any normal Draw-Operation for a Canvas. A normal Draw paints it with it’s native resolution, StretchDraw generates a scaled version. The OnDraw-Callback is used to alter each shapes apperiance. You get the Shape-Index and a set of properties you can modify.

And as a final image, here is an example from an older implementation of my AsciiImage, which is even more fancy:

pokeball

And the callback to specify Shape-Properties:

pokeball-source

Posted in Delphi and tagged , , , .

7 Comments

  1. Hi Memnarch,

    that looks very interesting. Is the demo application available for download? 🙂

    Best regards,
    Uli

    • Currently not. Working on a few other things but plan to add a Demo at a later time(maybe i’ll prioritize it)

      • Thanks for your answer!
        It’s not really urgent. 🙂 I guess the demo would make it easier to understand what this article really is about.

        • have you read the linked article at the top? That one explains it a lot better and in more detail what an AsciiImage is.

    • Oh okay o.O
      As i am working on the FireMonkey-Implementation, i might add something to toy around with for the next update.

Leave a Reply

Your email address will not be published. Required fields are marked *