HACKER Q&A
📣 shivajikobardan

Devnagari ASCII Art Generator, How to Make?


This is an example of Nepali sentence. Nepali is based on Devanagari Script.

यो फोरम मलाई एकदम मन पर्छ|

https://nepalilanguage.org/alphabet/#:~:text=Each%20of%20the%20following%2033,%2F%2C%20%E0%A4%AB%20%2Fp%CA%B0a%2F%2C These are the vowels and consonants in Nepali.

A Nepali consonant can take these many forms. "Ka" is first letter of Nepali consonant.

Expected Input

यो फोरम मलाई एकदम मन पर्छ|

And any character like a,b,c,.,/,,+,- based on which the ASCII art will be generated.

Expected Output

Every letter should be scaled and drawn with the given character, say for example "". Like below.

Plan 1:

1) Accept Nepali characters as input. And parse each character.

example यो फोरम मलाई एकदम मन पर्छ|

2) Get the shape of each character.

3) Scale the shape.

4) Redraw the shape using "*" or anything given by user as input.

Plan 2:

1) Take Nepali character as input

2) Convert to Unicode.

3) Process the Unicode.

4) Display Nepali as output.

I'm wondering how could I do this? Language doesn't matter but I'd prefer, C, C++ or Javascript.

Here are the images used in the post.

https://imgur.com/a/GIUljrK


  👤 Someone Accepted Answer ✓
1) render string at large font size to monochrome bitmap

2) loop over all pixels in the bitmap, writing spaces or asterisks depending on bit value

You can also render anti-aliased to grayscale and use blacker/whiter ASCII characters.

Many languages have libraries/support for #1, and for accessing individual pixels in a bitmap. If you have that, #2 is trivial.

The most difficult part may be to make sure to pick a font that allows you to do whatever you want to do with the ASCII art.


👤 yawpitch
Never tried anything like this, but I’d assume you’d probably use Freetype to render an existing Devanagari font to a matrix, then map each pixel position and brightness to a corresponding ASCII character… effectively your result is just a larger image that uses very large, letter-snapped “pixels” to represent shades of grey.

One possible (and randomly found) starting off point, in Go: https://fiwippi.net/blog/post/rendering_images_with_ascii_ch...