# ASCII Art Code Generator

I have a program that generates formatted Brainfuck code. I run my program

./example "S"


and the output is

 +[>+
<
+++
]
>--.


which prints S in Brainfuck.

Your objective is to write a program which accepts a string as input and outputs source code in another language which prints that string.

• The source code your program outputs must be formatted in such a way that it represents the string in ASCII art (printed horizontally, not vertically).
• The source code cannot contain the string (it may, however, contain letters that occur in the string, just not sequentially)

Otherwise,

Please title your submission with the language it is written in, the language it outputs, and the total size in bytes. Please include the output of your program when you enter the string UNCOPYRIGHTABLE.

Thanks!

• Does the program have to handle all printable ASCII characters or just uppercase letters? What about white space? – r3mainer Sep 8 '14 at 9:09
• @squeamishossifrage Just uppercase letters. Whitespace is preferable, but I realize the string " " might be impossible to represent, so its optional. – Orby Sep 8 '14 at 18:33

# C --> Brainfuck 556 Bytes

Excluding unnecessary whitespace. I could easily save another hundred by changing the font data in d[]from hex to a string in quotemarks.

i,j,s,t,u,v,w,h;
char a[99],b[9999],k,d[]={0x6F,0x3B,0x5A,0xD5,0x7A,0x6A,0x5B,0x2F,0xD0,0x57,0xA1,0x1B,0xCF,0x4F,0x5F,0x6E,0x6D,0x4E,0x79,0x3A,0x1F,0x95,0x9F,0xA6,0x3D,0x76};
f(int z){
return d[a[j-1-t%(2*w*j)/w/2]-65]>>z&1?z=b[i*v/u],b[i++*v/u]=' ',z:' ';
}

main(){
for(scanf("%s",a);a[j];i++)a[j]-k?k++,b[i]='+':(b[i]='.',t+=(0xE7572B70967DB>>(a[j]*2-130)&3)+5,j++);

s=i/t+2;
u=t*(s-1);
v=i;
i=0;

w=2*s;h=2*s+1;
for(t=2*w*h*j;t--;)putchar(
t%(2*w*j)?
t/2/w/j%s?

t%s||!(t/4%s)?' ':f(t/s%4/2+t/2/w/j/s*2|7*(t/s%4==2))
:(
(t%s)&&(t/s+1&2)?f(4+t/2/w/j/s):' '
)
:10  //newline
);

}


This uses a calculator font (for low entropy, only one byte per letter) and a very naive Brainfuck compiler inspired by https://codegolf.stackexchange.com/a/35801/15599 (except I use plus instead of minus.) The first for loop compiles the text in a to the string b, and also calculates the number of strokes required to draw the formatted code, using the 13-digit hex magic number (all characters are 5-8 strokes.)

Given the total program length and the stroke count, the number of characters per stroke is calculated (this can be very small if the characters are the same or in ascending order, and very large if the characters are in descending order.)

Most of the rest of the program is dedicated to deciding whether whitespace or one of the strokes needs to be printed. If the cursor is over a stroke square, the function fis called with the number of that stroke as an argument. It returns a space if that stroke is not required for the current letter, or a character from the program if it is. Because the number of characters required to complete the ASCII art may be more than the characters in the program, occasionally a space is inserted, hence the calculation b[i * v/u].

There are four single strokes and four double strokes in the font, numbered as follows, which are either present or absent, depending on the letter.

 6666 6666
3    7    2
3    7    2
3    7    2
3    7    2
5555 5555
1    7    0
1    7    0
1    7    0
1    7    0
4444 4444


Output

Test at http://copy.sh/brainfuck/

ABC

 + ++ +++                                ++++ + ++
+         +         +
+         +         +                   +
+                   +                   +
+         +         +
++++ + ++           +++  ++++
+                   +         +         +
+         +                   +         +
+         +         +                   +
+         +         +         +
++++ + ++           ++.  +.+.


DEF

 + ++ ++ +           ++++  +++           ++ + ++++
+         +                   +
+    +                             +
+    +         +                   +
+         +                   +
++ + +++            ++++ + ++
+    +         +
+    +         +                   +
+              +                   +
+    +         +
++++ + ++           ++.  +.+.


GHIJK

 + + +++                         ++  +++         +++  ++
+               +       +           +                               +
+               +       +           +                   +
+               +       +           +                   +           +
++ +++                                         + + +++
+       +       +                   +           +       +           +   +
+               +       +           +           +       +           +
+       +       +       +           +           +                   +   +
+++ + +                         ++. +.          +.+ .+.


LMNOP

                 + + +++         + + +++         + + +++         + + +++
+                   +   +       +       +       +               +       +
+               +   +           +       +       +       +       +
+               +   +   +       +               +       +       +       +
+ + +++
+               +   +   +       +       +               +       +
+       +       +       +       +       +       +       +
+       +       +   +   +               +       +       +       +
+ . +.+                                         . + .+.


QRSTU

 + + +++         +++ +++         +++ ++
+       +       +       +       +               +               +       +
+       +       +       +       +               +               +
+       +       +       +       +               +               +       +
+++ +++                         + + +++         +++ +++
+       +                       +       +               +
+       +                       +       +               +       +
+       +                       +       +               +       +
+++  ++         +++ .+.         +.+ .+.


VWXYZ

                                                                + + +++
+   +       +   +   +               +       +       +               +
+   +       +   +   +           +           +       +               +
+   +       +   +   +           +           +       +               +
+++ +++         + + +++         +++ ++
+   +       +   +   +       +   +                   +       +
+           +   +   +       +   +                   +       +
+   +           +   +       +   +                   +       +
+++ + +         +++ +++                         ++  .+.         +.+ .+.


COPYABLE

with most strings with letters in random order (not ascending) the letter size is much larger, and the letters look much better. Unfortunately the file sizes get quite large. I cannot upload the full word UCOPYRIGHTABLE here, COPYABLE is about the longest word I am allowed.

        + +++++++++ +++++++++++                         + +++++++++ +++++++++++                         ++ ++++++++ +++++++++++                                                                         +++ +.+++++ +++++++.+.+                                                                                                                         ++++ ++++.+ +++++++++++
+                                               +                       +                       +                       +                                               +                       +                       +                       +                                               +                                               +
+                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
+                                               +                       +                                               +                       +                       +                       +                       +                       +                                               +                                               +
+                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
+                                               +                                               +                       +                       +                       +                       +                       +                       +                                               +                                               +
+                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
+                                                                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
+                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
+                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
+                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +
+                                               +                       +                       +                       +                       +                       +                       +                       +                       +                                               +                                               +
+++++++++ + +++++++++++                         ++++++++++  +++++++++++                         +++++++++++  ++++++++++                         +++++++++++ + +++++++++                                                                         ++++++++++. +. ++++++++
+                                               +                       .                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
+                                               +                                               +                                                                       +                       +                       +                       +                       +                       +                       +                       +
+                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
+                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
+                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +
+                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
+                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                                               +
+                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
+                                               +                       +                       +                                                                       +                       +                       +                       +                       +                                               +                       +
+                                               +                       +                       +                                                                       +                       +                       +                       +                       +                       +                       +                       +
+                                               +                       +                       +                                                                       +                       +                       +                       +                                               +                       +                       +
+++++++++++ +++++++ +++                         +++++++++++ ++++++++ ++                                                                         +++++++++++ +++++++++ +                                                                         +++++++++++ ++++++++++                          +++++++++++ +++++++++++                          ++++++++++ ++++++++++.


# Perl → Befunge, 868 bytes

OK, I'll get the ball rolling. This could be golfed down a bit more, but my head is starting to hurt...

$_=" f,j f,jjj f,lgdlH,b >llb ,l,b lb ,lb , f,j f j f >>l>,lb ,9vb >lb,Hlb,H>vb >999*+, mg8Hg8Ha8c8g8Hgb8Hab8,8k/ 8Ha8Hi /H8HgH8g8k >H9ghgH9b 'bhbhgH9ghg9+gH9ga// ma8Hg8Ha8c8ahgbhabhh /bhah VdhibHH9ghb >H9ghgH9abhbhgH*g9+g ii /b>l,^b // >H^>>Hned*angne ned* eneknabnn<b nangn idH*gned*gneb*>>,b *kngH5g*6 Adb><aha//b H*g2HgH3a4Hg5Ha6c7gHHgb1Hab2+3H ib4Ha5Hg6kiHH7g8c, id1H iabHk3k4+g >+ ,^>^dd 7/ ib *k //b +1g+HgH+g+Hg+Ha+c+g,Hgb+kk >^+ki +Ha+Hg+HgH+g+cki'+ki ,gk+k>^gbHc^H 9*gb8+b//a ^<b ^>^ebe^'>^e >^e>>^a >^>> >^gd>^ke> >^b '>^e>>^g>^g e^ >^a >^~'i>^b i >2+^b >^b e>gHaV V >^gb>^bHHHHHH"; s/n/*H/g;s/m/H8g8HgH8/g;s/l/v>/g;s/k/Hb/g;s/j/f>,/g;s/i/\\/g;s/h/9H/g;s/g/bd/g;s/f/ve/g;s/e/>>>/g;s/d/ H/g;s/c/HaH/g;s/b/ /g;s/a/ /g;@f=split$/;
@s=split('',$ARGV[0]);foreach$r(0..6){for($i=0;$i<@s;$i++){print substr($f[$r],(ord($s[$i])-65)*6,6).$"}print$r?'':' @',$/}


## Examples:

The shorter examples can be copy-pasted into online interpreters like this one, but UNCOPYRIGHTABLE appears to result in a program that is too long for all the online interpreters to handle.

$perl bf.pl ABCDEFGHI v>>>, v>>>>, v>>>, v>>>>, v>>>>, v>>>>, v>>>, v> H Hv>H, @ H8 H 8H H H8 H 8H H 8H 8H H8 H 8H H 8H H8 H 8H H H8 8H H 8H 8H H8 9H H 9H >H^>>H *H>>> H* *H H *H>>> *H>>> H* >>> *H>>>H *H H* H 2H H H3 4H H 5H 6H H7 H HH H 1H +1 H +H H H+ H +H H +H +H H+ H ,H H +H ^< ^ >^>>> >>>^' >^>>> >^>>>> >^ >^>> >^ H H>^H$ perl bf.pl JKLMNOPQR
>v> v>   , v>,    v>   , v>   ,  v>>>, v>>>>,  v>>>  v>>>>,  @
8, 8H  /  8H     8H\ /H 8H   H H8   H 8H   > H9   H 9H   H
9H 9H /   9H     9H V H 9H\  H H9   H 9H   > H9   H 9H   H
*H *H<    *H     *H   H *H \ H H*   H *H>>>  H*   H *H>>>
2+ 3H \   4H     5H   H 6H  \H H7   H 8H     H, \ H 1H \
H   >^ +H  \  +H     +H   H +H   H H+   H +H     HH  \' +H  \
>>>>  >^   ' >^>>>> >^   H >^   H  >>>^  >^      >^~'\ >^   \

$perl bf.pl STUVWXYZ v>>> >>v>>, v> , 9v > v> ,H v> ,H >v > 999*+, @ H9 ' 9H 9H H H9 H 9H H 9+ H H9 H // H9 9H 9H H H* H 9+ H \\ / >v>,^ // *>>, *H *H H H5 H *6 A H >< 9H // HH 3H 4+ H >+ ,^ >^ H H 7/ \ *H // , HH +H >^ H HH H^H 9* H 8+ // >2+^ >^ >>>> HH V V >^ H >^ HHHHHH$ perl bf.pl UNCOPYRIGHTABLE
v>   , v>   ,  v>>>,  v>>>, v>>>>, >v   > v>>>>,  Hv>H,  v>>>, v>   H >>v>>,  v>>>, v>>>>, v>,    v>>>>,  @
9H   H 8H   H H8   H H8   H 8H   > H9   H 9H   H   8H   H8   H 8H   H   9H   H8   H 8H   H 8H     8H
9H   H 9H\  H H8     H9   H 9H   >  >v>,^ 9H   H   9H   H8     9H   H   9H   H8   H 8H   H 9H     8H
*H   H *H \ H H*     H*   H *H>>>    9H   *H>>>    *H   H* >>> *H>>>H   *H   >H^>>H *H>>>  *H     *H>>>
4+   H 6H  \H H3     H7   H 8H       *H   1H \     1H   H7   H HH   H   3H   H*   H 2H   H 4H     5H
>^   H +H   H H+   H H+   H +H       8+   +H  \    +H   H+   H ,H   H   +H   +1   H +H   H +H     +H
>>>>  >^   H  >>>^'  >>>^  >^       >^   >^   \  H>^H   >^>>  >^   H   >^   ^<   ^ >^>>>  >^>>>> >^>>>>


### Note:

The @ character at the end of the first line of output tells Befunge to stop running. Without it, the program would keep repeating the same word forever.

• I like the ASCII font :) – Orby Sep 8 '14 at 19:44

## C → Brainfuck, 855 bytes

Some newlines added to improve readability. Notice it segfaults on lowercase letters and symbols. Test the output here.

#define p putchar
#define V(x) c=v[1][x]-65;
l[]={96,48,24,12,66,98,60,90,6,70,102,54,118,14,62,126},e[]={2863659686,
3937331886,1787332774,3937053358,4170115215,2291067023,1789692070,2863659690,
1646404134,1778384896,2864569258,4169697416,1145534458,1165457300,1789569702,
2291051182,1823124134,2863573678,1778804902,572662319,1789569706,648719018,
2943841348,2863033002,572680874,4164034831},a[]={36,36,24,34,30,26,29,36,20,20,
30,20,28,26,32,28,33,34,28,20,32,30,28,32,24,24},r,o,j,k,c,z;char*b[]={
"-[+>+<[+<]>]>+","-[+[>---<<]>+]>-","+[>+<+++++++]>",">+++[[-<]>>--]<",
"+[>+<+++]>----","+[>+<+++]>","-[+[+<]>>+]<+"};main(i,v)char**v;{for(;r<8;r++){
for(i=0;v[1][i];i++)for(o=0;o<8;o++){V(i)if((l[(e[c]>>(4*r))&15]>>o)&1){V(j)
if(k==a[c]){j++;k=0;}V(j)z=k-strlen(b[c/4]);if(z<0)p(b[c/4][k]);else{c=(c%4)-z;
!c?p(46):(c>0?p(43):p(62));}k++;}else p(32);}p(10);}}


## Examples

It looks a lot nicer on a terminal :(

$./art ABCDEFGHI -[+> +<[+< ]>]> +.>>> >>>>>> >>>>>> >>>> >> -[ +>+< [+ <] >] >+ +. >> >> >> >> >> >> >> >> >> >> -[ +> +< [+ <] >] >+ ++ .> >> >> >> -[ +>+<[+ <]>]> ++ ++ .> >>>>> >>>>> >> >>>-[+ [> ---<<] >+]>- .> >> >> >>>>> >>>-[ +[ >-- -<<]>+ ]> -+ .> >> >> >> >- [+ [> -- -< <] >+ ]> -+ +. >> >> >> >> >> -[ +[ >- -- << ]> +] >- ++ +. >> >>>>> >>>> >>>>> +[>+<+ ++ ++++ ]> .> >>>>$ ./art JKLMNOPQR

+[  >+  <+  ++      ++  ++  ]    >   +.>>   >>+[>    +<++   +++++
]>  ++  .>  >>      >>>>>>  >>   >  >+  [>  +<  ++  ++  ++  +]  >+
++  .> >>   ++      + [[ -  < ]> >  --  ]<  .>  >>  >>  >>  >>  >>
>>  +++     [[      - <] >  > -- ]  <+  .>  >>  >>  >>  >>  >+  ++
[[  -<]     >>      - -] <  + +. >  >>  >>  >>>>>   >>  >>  >+++[
[-  <] >>   --      ]    <  + ++ .  >>  >>  >>      >>  >+  [>  +<
++  +]  >-  --  -.      >    >  >   >>  >>  >>  >>      >> >>>  >>  +[
>+<+   ++  ]>  ----+.  >    >  >    >   >>>>   >>       >>>>   >>  >>

$./art STUVWXYZ +[>+ <+++]> -- -- ++ .> > > >> >> >> >> +[>+<+ ++ ]> -- -- ++ +. >> + [ >+ <+ ++ ]> .> >> >> >> >> >> >> > > >> >> >> +[ >+ <+++ ]> +. >> >> >> > >> > >>>> >>>> +[ >+<+ ++ ]> ++ .> >> > >> > >>>> >> >> +[ >+ <+ ++ ]> ++ + .> > >> >> >> >> >> >> >> >> -[ +[+< ]>>+]< +. >> >> >> >>>> -[ +[+< ]> >+ ]< ++ .> >> >>>>>>  And finally, $ ./art UNCOPYRIGHTABLE

+[  >+  <    +   ++]>    .>>>   >>>>>   >>  >>  >>>>>    >>>>    >+++   [[  -<  ]>>--]   <+.>   >>>>>   >>      >-[+>+
<[  +<  ]>   ]  >+  ++  .>  >>  >>  >>  >+  ++  [[  -<    ]>    >-  -]  <+  +.    >>    >>  >>  >>  >>  >>      >>
>+  ++  [ [- <  ]>      >-  -]  <+  ++  .>  >>  >>  >>    >>    -[      +[  +<    ]>    >+  ]<  +.  >>  >>      >>
>>  >>  + [> +  <+      ++  ]>  --  --   +.>>   >>  >>    >>    >>      >>>>>>    >>    +[>+<+  +++++   +]      >.>>>
>>  -[  + [> -  --      <<  ]>  +]>-+     +.    >>>>>     >>    >> >-[  +[>---    <<    ]>+]>-  +++.>   >>      >>>>>
>>  >>  > >> >  +[      >+  <+  ++        ]>    --  --    ++    +.  >>  -[  +>    +<    [+  <]  >]  >+  .>      >>
>>  >>  >   >>  >>  >>  >>  >>  >>        >-    [+  >+    <[    +<  ]>  ]>  ++    .>    >>  >>  >>  >>  >>      >>
>>>>   >    >   >+[>    +<++   ++        ++    +]  >+   ++.>    >-[+   [>  --    -<    <]  >+  ]>-.>   >>>>>>  >>>>>>