Wednesday, December 2, 2015

Edge/Collision Detection in ASCII character templates

I started playing with edge detection in ASCII characters, to use for manipulating text data (for example, creating mazes).  Here was the first pass:

http://sevkeifert.blogspot.com/2015/11/i-wrote-that-turns-ascii-tessellation.html

Then I noticed that a lot of character patterns have implied white space, such as a pattern with pipes and underscores:

# this pattern contains visual whitespace, but no actual whitespace character data:
 _
|_|

So, I thought about how to generalize the parser to handle cases like this.  The simplest approach I found was to add an option to  translate all characters into an exploded map of the data.  One character can translate to a block of 9 characters that represent the solid and non-solid properties of the font shape.  For example:




Then, the edge detection code works as usual, just in an exploded view of the ASCII data.  For example:




Then I added some code to detect the "outside" of a shape.  Also, I added pre and post image filtering rules, so loose edges like /_ can be automatically detected and closed.

Here's another example parsing implied whitespace in a template:



Update: The parser can automatically detect inside/outside of closed shapes.  Also, I added a special character ~ that flags a region as closed within another shape (such as holes in the template).  The special character ` acts as non-useable whitespace.

For example:



Updated code at:

https://github.com/sevkeifert/text-utils/blob/master/maze-ify-ascii.py