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 f
is 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.
+ +++++++++ +++++++++++ + +++++++++ +++++++++++ ++ ++++++++ +++++++++++ +++ +.+++++ +++++++.+.+ ++++ ++++.+ +++++++++++
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+++++++++ + +++++++++++ ++++++++++ +++++++++++ +++++++++++ ++++++++++ +++++++++++ + +++++++++ ++++++++++. +. ++++++++
+ + . + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + + + +
+ + + + + + + + + + +
+++++++++++ +++++++ +++ +++++++++++ ++++++++ ++ +++++++++++ +++++++++ + +++++++++++ ++++++++++ +++++++++++ +++++++++++ ++++++++++ ++++++++++.