0

I would like to know if there exists a tool which will basically transform my text, let's say "42" into a "map" file that I can display using a little program I coded. The position of the numbers in this file defines the Z coordinates of my points that I project onto the screen, their X and Y beeing obviously the 2 dimensions of my array.

Here's an example of a map I'd like to get:

0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
0  0 10 10  0  0 10 10  0  0  0 10 10 10 10 10  0  0  0
0  0 10 10  0  0 10 10  0  0  0  0  0  0  0 10 10  0  0
0  0 10 10  0  0 10 10  0  0  0  0  0  0  0 10 10  0  0
0  0 10 10 10 10 10 10  0  0  0  0 10 10 10 10  0  0  0
0  0  0 10 10 10 10 10  0  0  0 10 10  0  0  0  0  0  0
0  0  0  0  0  0 10 10  0  0  0 10 10  0  0  0  0  0  0
0  0  0  0  0  0 10 10  0  0  0 10 10 10 10 10 10  0  0
0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0

Which outputs

fdf42

So does anyone know how I can convert any string into this kind of file ? If no such tool exists, is there a common way of getting a character's shape which could help me generate those maps ?

Thanks for reading me, looking forward to read your answers :)

cfz42
  • 384
  • 1
  • 14
  • Just use `banner` or `figlet`? – abligh Feb 25 '15 at 08:42
  • What language are these tags ? Could you please elaborate a little more ? – cfz42 Feb 25 '15 at 09:49
  • 1
    Both convert text to ASCII graphics. If you want to recode it yourself, then fine, but these should serve as inspiration. From memory, they are both in C.See http://en.wikipedia.org/wiki/Banner_(Unix) , https://packages.debian.org/testing/misc/sysvbanner and http://www.figlet.org/ ; according to http://stackoverflow.com/questions/652517/whats-the-deal-with-the-banner-command (Zoredache's answer) the debian sysvbanner is a single file with 155 lines of C. – abligh Feb 25 '15 at 14:18
  • Also this answer has 2 lots of source code to do pretty much what you want to do (just print a decimal value not a #): http://stackoverflow.com/questions/652517/whats-the-deal-with-the-banner-command – abligh Feb 25 '15 at 14:24
  • Thank you for pointing me those tools man question solved – cfz42 Feb 25 '15 at 21:31

1 Answers1

2

A rough solution:

  1. Create an image object.
  2. Write your text on it using a font library. Using a bitmap font will improve results due to the very low resolution.
  3. Iterate through the image pixels and output your text file.

A more detailed solution would require specifying a programming language.

EDIT: I whipped this up: http://phpfiddle.org/lite/code/zr3k-hwbw

<?php
    $str = isset($_GET['str']) ? $_GET['str'] : "+1";
    $font = isset($_GET['font']) ? $_GET['font'] : 1;
    $w = imagefontwidth($font) * strlen($str);
    $h = imagefontheight($font);
    $img = imagecreate($w, $h);
    $bg = imagecolorallocate($img, 0, 0, 0);
    $tc = imagecolorallocate($img, 255, 0, 0);
    imagestring($img, $font, 0, 0, $str, $tc);

    header("Content-Type: text/plain");
    for ($y = 0; $y < $h; $y++) {
        for ($x = 0; $x < $w; $x++) {
            echo (imagecolorat($img, $x, $y) * 10)."\t";
        }
        echo "\n";
    }
?>

Output:

0   0   0   0   0   0   0   0   0   0   
0   0   10  0   0   0   0   10  0   0   
0   0   10  0   0   0   10  10  0   0   
10  10  10  10  10  0   0   10  0   0   
0   0   10  0   0   0   0   10  0   0   
0   0   10  0   0   0   0   10  0   0   
0   0   0   0   0   0   10  10  10  0   
0   0   0   0   0   0   0   0   0   0   
Adrian Leonhard
  • 7,040
  • 2
  • 24
  • 38
  • Thank you for bothering (or not I don't know !) to do this, it indeed fits what I need but unfortunately I do prefer the figlet solution given above. (Upvoted though :-) ) – cfz42 Feb 25 '15 at 21:32