3 added 20 characters in body
source | link

This is the source image:

42

This is the source image:

42

2 added 20 characters in body
source | link
1
source | link

Plotting with Chars. You can do it with 42 and with your girl friend, too.

public class CharPlotUtil {

    private static int xStep = 2;
    private static int yStep = 2;

    public static void main(String[] args) throws IOException {

        initChars(" .:0123456789oO*+-,;dc3öÖ%qQG´");

        BufferedImage bufferedImage = ImageIO.read(new File("D:\\Temp\\Chars\\img.png"));
        // http://www.stupidedia.org/images/8/80/The_Answer_to_Life,_the_Universe,_and_Everything.png

        int normalizationFactor = 3 * xStep * yStep * 255;

        for (int y = 0; y < bufferedImage.getHeight() - yStep; y += yStep) {
            for (int x = 0; x < bufferedImage.getWidth() - xStep; x += xStep) {

                int sum = 0;
                for (int xx = x; xx < x + xStep; xx++) {
                    for (int yy = y; yy < y + yStep; yy++) {
                        int value = bufferedImage.getRGB(xx, yy);
                        int byte1 = value & 0xFF;
                        int byte2 = (value >> 8) & 0xFF;
                        int byte3 = (value >> 16) & 0xFF;
                        sum += byte1 + byte2 + byte3;
                    }
                }
                float f = ((float) sum) / normalizationFactor;
                System.out.print(CharWithGrayValue.getCharByGrayValue(f).getChar());
            }
            System.out.println();
        }
    }

    private static void initChars(String charsAsString) {

        for (int i = 0; i < charsAsString.length(); i++) {
            char c = charsAsString.charAt(i);
            CharWithGrayValue.add(new CharWithGrayValue(c));
        }
    }
}

public class CharWithGrayValue {

    private static int width = 16;
    private static int height = 24;
    private static int fontSize = 23;
    private static Font font = new Font("Courier New", Font.PLAIN, fontSize);

    private static Map<Integer, CharWithGrayValue> charsWithGrayValue = new TreeMap<>();
    private static int minGrayValue = -1;
    private static int maxGrayValue = 0;

    private char c;
    private int grayValue;

    public CharWithGrayValue(char c) {
        this.c = c;
        grayValue = getGrayValue(c);
    }

    public char getChar() {
        return c;
    }

    public int getGrayValue() {
        return grayValue;
    }

    private static int getGrayValue(char c) {

        BufferedImage charImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
        Graphics graphics = charImage.createGraphics();
        graphics.setFont(font);
        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, width, height);
        graphics.setColor(Color.BLACK);
        graphics.drawString("" + c, 0, height - 4);
        return getGrayValue(charImage);
    }

    private static int getGrayValue(BufferedImage charImage) {
        int result = 0;
        for (int i = 0; i < charImage.getHeight(); i++) {
            for (int j = 0; j < charImage.getWidth(); j++) {
                if (charImage.getRGB(j, i) != -1) {
                    result++;
                }
            }
        }
        return result;
    }

    public static void add(CharWithGrayValue cg) {
        charsWithGrayValue.put(cg.getGrayValue(), cg);
        if (cg.getGrayValue() > maxGrayValue) {
            maxGrayValue = cg.getGrayValue();
        }
        if (cg.getGrayValue() < minGrayValue || minGrayValue == -1) {
            minGrayValue = cg.getGrayValue();
        }
    }

    public static CharWithGrayValue getCharByGrayValue(float normalizedGrayValue) {

        // normalizedGrayValue: 0, ..., 1
        // intGrayValue: minGrayValue, ..., maxGrayValue

        int intGrayValue = (int) (minGrayValue + (maxGrayValue - minGrayValue) * normalizedGrayValue);
        for (int gv : charsWithGrayValue.keySet()) {
            if (gv >= intGrayValue) {
                return charsWithGrayValue.get(gv);
            }
        }
        return new CharWithGrayValue(' '); // Should not happen
    }
}



                                                                                                                     ´´´´´                                      
                                              ,c7co333oc777cooooooo,                                       ´.,:*7c7;;:::::::::::,-..                            
                                             .3occo3223occccooo3ooo,                                   ´,*o3o3333o7;:::::::::*;;;;;;;:,.´                       
                                            .223occo3223oooooo33333,                                 .;555233322o7;*:::::::*;;;;;;77;;;;:,.                     
                                           ´o55233oo32523ooooo33333,                               .o55455232223c7;*::::::*;;;77777;;;;*::::.                   
                                           72555523o325523oooo33222:                             ´;255445222252o7;**::::*;;77777777;;;*:::::::´                 
                                          :325554523o32552333332222:                            ,o2554ö45225523c;;**::*;;777777777;***:::::::::-                
                                         .7o32554452332555233332222:                          ´:o2554öö5555553o7;;***;;7777cccc77;;;**:******:;;:´              
                                        .*;7o3554öö4523254522222222:                         ´73325ö664555552o7;;;**;;7cccccoc77;;;****;;;;;;;77;*´             
                                       ´;;;;7o254öö6452254452222255:                        ´73325ö68ö4554453c7;;;;;7cooooooo77;;;;;;;;**;;;;77777;´            
                                      ´;77;;;7o254ö6645225ö45222255:                        72325ö688ö554ö53o77;;;77ooooooooc7;;;;;;;;;;;;777777c77;´           
                                      *oc777;;7o24ö688ö525464522255:                       :522546886444ö42oc77;77co333333oc77;;;;;;;;777777ccoccccc:           
                                     :33ooc7777c3246888ö555ö6455555:                      .5522468G8ö4ö6ö53c7777co3333333oc77;;;;;;;7777cccooooocc777-          
                                    ,22233oooc77c35ö688865548845555:                      2552568GG8öö6653oc777o33222223oo7777777777cccooooooooccccc7;´         
                                   .322552233ooc7o35ö88GG6456884555:                     :4555ö8GG86688423occoo32222223oo77777777ccoooo333ooooooccc7;7:         
                                  ´7o3225552233oooo3568GGG84ö8G8454:                    ´5ö5548GGG8888ö23oooo322555523oocccccccoooo33333333ooooocc77;;;´        
                                 ´;cco325544552233oo256GG%G8ö6GG844:                    :6ö558G%%G88G6533oo32255555233ooooooooo333222223333ooooc777;*;;,        
                                 :77coo3255öö45522333258G%%G8ö8GG6ö:                    28ö56G%%G8GG8523333255544553:.´´´´.:o32225522223333oooc77;;*;;**        
                                ,777ccoo3255ö664552223258G%q%86GGG6:                   .88öö8Gq%GGGGö2333255444452:´        ´:555555222333ooc77;;;;;;*;;.       
                               .;;77ccoo332254686ö45223248%%q%G8G%G:                   *88ö8GqqGGGG65233254öööö52.            -5455522233occ777;;;;*::::,       
                              ´*;;777cooo3322546886ö452224G%qq%GG%%*                   5886Gqq%G%%8522254ö666ö52.              .5555223ooc77;;;;;***:::;:       
                             ´:*;;;777coo332225468G88ö45224GqqqqGG%;                  ´G888%qq%%%G45225ö6888ö55:                :55233oo777;;;;;**::::*::´      
                            ´::**;;;777coo332255468GGG8ö455öGqqQqG%;                  :G88%qQq%qG65254888G8ö453                 ´323ooc77;;;;;;*****:;*::.      
                            ,:::**;;;77cco33222554ö8G%GG8ö45öGqQQqG;                  7G8GqQqqq%845568GGG86455,                  :ooc777;;;;;****::::*:::.      
                           .:::::*;;;;77coo33225554ö8G%%GG864öGqQQq*                  4G8qQQqqq8ö548GGGG8644ö4´                  .oc777;;;;;****:::::::::.      
                          .::::::**;;;777coo33225554ö8G%qqGG866GQQQ;                  GG%QQQqqG6ö68GG%G86ö668o                   ´c777;;;;;****::::::::::.      
                         ´:::::::**;;;;777coo3322554ö68GGqqqGG88GQQ7                 .%GQQQQQG868G%%%G88888GG:                    777;;;;;;****::::::::::.      
                        ´:::::::***;;;;777ccoo.322554ö68GG%qqqG88GQ7                 :GqQQQQ%868Gqq%G88GGG%qq.                   ´777;;;;;;***::*::::::::.      
                        :;;********;;;;7777co, 3322554ö88GG%qQq%G8G;                 ;%QQQQq88G%qq%GGGGGqqQQq                    .77;;;;;****:**::::;**::.      
                       :777;;;;;;;;;;;;7777c:  33322554ö88GG%qQQq%G*                 ´´´´´´´´´´´´´´´´´´´´´´´´                    ,77;;;;;;*****::::::::::´      
                      ,7777ccccccc77777777c*   333222554ö88GGGqQQQq;                                                             ;77;;;;;;***::::::::::::       
                     .7777ccoooooooooooooo7´   3333222554ö88GG%qQQQ7                                                            .77;;;;**::::::::::::::::       
                    ´;7777ccoooo3333222223.    33332222554ö88GG%qqQ7                                                            ;7;;;;**::::::::::::::::.       
                   ´*77777ccoooo333322255.     555222225554ö888G%qq7                                                           ,;;;;**::::::::::::::::::.       
                   :;;;;7777cooo33332255:      6666öö445544ö6888GGq;                                                          .;;;;**:::::::::::::::::::        
                  ,***;;;;7777cooo33322*       6888GGGGG8888888888G*                                                         ´;;;;;;***::::::::::::::::-        
                 .:::****;;;;777ccooo3;        6688GGGGG%%%%%GG8888*                                                        ´*77;;;;;;***::::::::::::::´        
                .::::::::***;;;;777co7´        44ö688GGG%%qqqqQQQqq;                                                       ´;77777;;;;;;;;*****;*:*:::,         
               ´:::::::::::::**;;;;77´         25554ö688GGG%qqqQQQQ7                                                      ´73ooooocccc7777777;7;;77;;;´         
              ´,:::::::::::::::::**;.          332225554ö6888GGG%qQ7                                                     .2555522223333ooooooccc7c777:          
              ,::::::::::::::::::::.           ooo33332225554ö66688:                                                    ,688866ööö4455522223333ooooo7´          
             -:::::::::::::::::***,            2222554ö6888GG%qqqQQ7                                                   :44445555522223333ooooocccc77.           
            .:::::::::::**;;;;777:             688GGGG%%qqqqqqqqqQQ7                                                  :333ooooooccc77777777;;;;;;;;,            
           .::::*;;;;;;7777cooo37´             888888GGGGGG%qqQQQQQ7                                                ´;cc777;;;;;*****::::::::::::::             
          ´:;;;77777cccoooooo33o´              444ö688G%qQQQQQQQq%G*                                               .3233ooc777;;;**:::::::::::::::´             
         ´:;7777777777777ccccoo.               68GG%qQQQQQQqGG88GGG*                                              :445552233ooc777;;;**::::::::::´              
         :;77;;;;;;;;;;;777777-                %qqqQqq%G8666888GG8G*                                            ´c4455555222233oocc77;;;;***::::´               
        ,:********;;;;;;;;;77,                 %GG86ö5555ö68888888G;                                           .3555555522223333ooooc7777;;;;*:.                
       .:**:::::*****;;;777c*                  552222554ö6666688GqQ7                                          ,o333332222223333oooocc777777;;;.                 
      ´:::::::***;;;;77coo37´                  333225554444ö688qQQq;                                         *233oocccoooooooooooocc777777;;*´                  
     ´:::::*;;;;;777coo3323´                   322255555554ö8%QQq%q7                                       ´3455233oc77777777777777777777;;:´                   
    ´:****;77777cooo332255.                    222222225556GqQqGGqq;                                      .ö86ö455233oc7;;;*;;;;;;;;;;;;;;:´                    
    ,;;;;7777cooo3333333o-                     333332225öGqQqGG%q%G;                                     ,qq%86ö4552233oc7;;*::::::::****,                      
    ,;;777ccoooooooocc77*--.......---,,,,,,,,,,333322248%qqG8G%qGGQö7**77;;77;                          :8qQQqG8ö4552223oo77;;*:::::::::.                       
    :77ccccc777777;;;;**:::::::**;;;7777ccccoooo333256GqqG88G%%8GQQQq8QQQqQQQq                         *5548%qqqG8ö552233ooc77;;*:::::,´                        
    :77777;;;;;;**::::::::::::**;;;;77777777cooo33248%%G8ö8G%G8GQQQq6qQQ%qQQ%q                        cö552256Gqq%G8452233oooc77;;*::-                          
    ,;;;;***:::::::::::::::::**;;;;;;;;77777coo3258G%G8öö8GG86GQQQq6GQQqGQQQGq                      ´3G8ö552225ö8%qG8645233oocc77;;:.                           
    ,:::::::::::::::::::::::****;;;;;;;;7777co25ö8GG645ö8GG6öGQQQqö8QQQG%QQqGq                     ´2GG884522333248G%G8ö4523oocc77:´                            
    ,::::::::::::::::::::::::::*****;;;;777c3248G86455ö8G844GQQQ%ööqQQ%GqQQGGq                    ´6qG8886452233o3256GGG8ö523ooc7-                              
    -:::::::::::::::::::::::::::::**;;;;77o25ö88ö5525ö88ö54GqQQ%ö5GQQqGGQQqGGq                   ´2%qqG8666452233ooo25ö8G864523;´                               
    -:::::::::::::::::::::::::::::**;;;7o32466ö55225ö8ö554GqQq%628qQqG8GQQ%8G%                  ´4G8GqqG6ööö45223ooc7o324688ö4*´                                
    -:::::::::::::::::::::::::::::**;;7o25ö64522225öö4524Gqqq%ö2ö%qQG8GqQqG8GG                 ´2q%86GqqG644445233oc777c325öö,                                  
    -:::::::::::::::::::::::::::::*;7o324ö45233325445224GqqqGö25Gqqq88GqQ%88GG                 3GGqG6öGq%Gö4555523ooc77;;7oc.                                   
    -::::::::::::::::::::::::::::;;co3545523oo3254522248qqqGö228qqqG68GQqG68G8                7qG8G%Gö48%%8ö5555523oc777;;:´                                    
    -::::::::::::::::::::::::::*;7o3255233oco3255523258qq%Gö23ö%qqG668qQ%8ö8G8               :G%G88G%8448G%8ö5555223oc77;,                                      
    -::::::::::::::::::::::::*;77o32223oo7co325523o358%%%Gö235G%q%846GqqG648G8              .ö8G%G68GG8556GG845222223oc7,                                       
    -:::::::::::::::::::::::*;7c32233oc77co32523oo358%%GG42o28%%%8448%q%8ö4886             ´24ö8GG8ö8GGö55öGG84522223oo,                                        
    -:::::::::::::::::::::*;77o333ooc777co3223ooc358GGG842o3öG%%Gö5ö8qqG65488ö             ;454ö8GG6ö8G8425ö8G64233333,                                         
    -:::::::::::::::::::*;;7co3ooc77;;7co333oocc358GG8842o358G%G655öGq%8ö5486ö            -45555ö8G8448G65224886523337,,,,,--.........--,,,,,,,,,,---.....      
    -:::::::::::::::::**;77ooooc77;;;7co33ooc7c356888842co26GGG85556GqG652ö8ö4           ´5455555688ö5468ö522568ö523oooooc77;;*::::::::*;77coooo7777;;***:      
    .::::::::::::::::*;;7coocc7;;*;;77ooooc777356888653c7348GG842548%%8ö52ö644           *645555556864546842325ö8ö52ooooooc7;;**:::::::::*;;77cooc77;;;;::      
    .:::::::::::::::;;77ccc77;;**;;77oooc77;735ö886653c7o588G8ö2254GqG6525öö55          ´86ö552255468ö5546652o35ö6ö53oocccc77;;**::::::::::*;;777oc777;;;;      
                                               66öö537;c2ö888ö5225ö*                    7G8ö552222548645546ö53o3246453occc7777;;**::::::::::::*;;777777;;;      
                                               öö4537;7356886522258*                   ´8G8ö52222225ö6ö5254ö423o325ö423o7777777;;*::::::::::::::**;;7cc77;      
                                               44537;;o5ö6864232248;                   ;888ö522222225öö52255ö52oco354523o777777;;;**::::::::::::::*;;;7777      
                                               52o7;;c24ö66423325öG*                  ´4888ö5522333225ö452325453o7o32452oc7777;;;;;*:::::::::::::::::*;;;7      
                                               2o7**7354ö6ö53o3256G:                  ,ö688ö55233333355ö523325523c7o32553oc7;;;;;;;***:::::::::::::::::**;      
                                               o7*:;o244öö53oo3258G:                  34ö66ö552333o33254453o32553o77co3523o77;;;;;;;**::::::::::::::::::::      
                                               7*:;73544ö52ooo32488:                 .544ö6ö55233oooo3254523o32523o7;7o3223o77;;;;;*;;::::::::::::::::::::      
                                               *::7o254452ocoo35ö8ö:                 :554ö6ö5523oooooo325523oo3222oc;;7o3223o7;;;**;;;**::::::::::::::::::      
                                               ::;c3555423ccoo25684:                 o5554öö5523oooccoo32553oco3323o7;;7co33oc7;;**;;;;;***:::::::::::::::      
                                               :*73255553o7coo248ö5:                ´255554ö5223ooccccco32523oco3323c7;;7co33oc7;*;*;**:::::::::::::::::::      
                                               :;o222553o77co35ö642:                -25555445223occ777cco3223oc7oo33o7;;;;7oo3o77;;**::;;***::::::::::::::      
                                               ;7322253o777co35öö53,                :22225545233occ77777co323oc77co33o7;**;7coocc7;*:******:::::::::::::::      
                                               7o32222oc;77co25ö523,                ;32222555233oc7777777co323o777coooc7;**;77ooo77;;*::::::::::::::::::::      
                                               c33322oc7;77co24453o,                o32222555233oc77777777co33oc777co3oc7;**;7ccoc7;;**:::::::::::::::::::      
                                               o33323c7;;77c324523c,               ´oo333225523ooc777;;;;77co3oo7;;7cooc7;;:*;77coc7;;*:::::::::::::::::::      
                                               o3333o7;;;77o35423o7,               .co333322523ooc77;;;;;;77co3oc7;;77coc7;*:*;;7cc77;;**:::::::::::::::::