Here was Part I: 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, here's an experiment 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:
1. First transform text to exploded view
2. Parse as usual
3. Then apply an inverse transform to collapse back to normal.
The transform looks like:
Load template:
Apply Transform:
Apply pre-processing filters (sharpen edges)
Parse and apply post-processing filters
Apply inverse transform:
For example:
1. First transform text to exploded view
2. Parse as usual
3. Then apply an inverse transform to collapse back to normal.
The transform looks like:
Load template:
Apply Transform:
Apply pre-processing filters (sharpen edges)
Parse and apply post-processing filters
Apply inverse transform:
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:
Parser Hints
Now, 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.
summary:
~ means outside of shape
` means don't use whitespace
For example, to protect the closed shape of the eye, add a ~ inside of it:
Updated code at:
Python2: https://github.com/sevkeifert/text-utils/blob/master/maze-ify-ascii.py
Python3: https://github.com/sevkeifert/text-utils/blob/master/maze-ify-ascii-v3.py
No comments:
Post a Comment