- private float[] tmp = new float[4];
-
- private char getAsciiChar(int pixel) {
- float brigthness = getBrightness(pixel, tmp);
- if (brigthness < 0.20) {
- return ' ';
- } else if (brigthness < 0.40) {
- return '.';
- } else if (brigthness < 0.60) {
- return '+';
- } else if (brigthness < 0.80) {
- return '*';
- } else {
- return '#';
- }
- }
-
- private char getDitheringChar(int pixel) {
- float brigthness = getBrightness(pixel, tmp);
- if (brigthness < 0.20) {
- return ' ';
- } else if (brigthness < 0.40) {
- return '░';
- } else if (brigthness < 0.60) {
- return '▒';
- } else if (brigthness < 0.80) {
- return '▓';
- } else {
- return '█';
- }
+ /**
+ * Return the {@link Character} corresponding to the given brightness level
+ * from the evenly-separated given {@link Character}s.
+ *
+ * @param brightness
+ * the brightness level
+ * @param cars
+ * the {@link Character}s to choose from, from less bright to
+ * most bright; <b>MUST</b> contain at least one
+ * {@link Character}
+ *
+ * @return the {@link Character} to use
+ */
+ private char getDitheringChar(float brightness, String cars) {
+ int index = Math.round(brightness * (cars.length() - 1));
+ return cars.charAt(index);