-2

I'm trying to achieve an effect of ASCII Art, but it is not working. The code is supposed to create "Visual Grammar" out of the letters "VG". There seem to be no errors and the output is displayed, but it only consists of a few rows of letters. It's not creating any image. Any idea what might have gone wrong?

package visualgrammar;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public class Vg {

public static void main(String[] args) {
    int width = 150;
    int height = 30;

    BufferedImage image = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
    Graphics a = image.getGraphics();
    a.setFont(new Font("SansSerif", Font.BOLD, 24));

    Graphics2D a2 = (Graphics2D) a;
    a2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    a2.drawString("VISUAL GRAMMAR", 10, 20);

    for (int y = 0; y < height; y++) {
        StringBuilder builder = new StringBuilder();

        for (int x = 0; x < width; x++) {
        builder.append(image.getRGB(x, y) == -16777216 ? "" : "V"); 
}

        System.out.println(builder);

    }
}
}
Natiaia
  • 15
  • 1
  • see [Image to ASCII art conversion](https://stackoverflow.com/a/32987834/2521214) for some ideas for improvemnet – Spektre Nov 27 '17 at 17:33

1 Answers1

0

Right now, you only output V characters, but not G characters.

So change this line

builder.append(image.getRGB(x, y) == -16777216 ? "" : "V");

to this

builder.append(image.getRGB(x, y) == -16777216 ? "G" : "V");

This looks far more like usefull, it looks like "VISUAL GR" and half of an "A". So you need more width. 250 looks kinda good to me. int width = 250;

Korashen
  • 2,144
  • 2
  • 18
  • 28