class InvertedPyramidArt implements AsciiArt {
private static final String ASTERISK = "*";
private static final String WHITESPACE = " ";
private static final String NEWLINE = "\n";
private static final int ROWS = 5;
private static final int COLS = 9;
private InvertedPyramidArt() {}
public static InvertedPyramidArt of() {
return new InvertedPyramidArt();
}
private void process(String[] pattern) {
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
int stopper = row;
if (col < stopper) {
System.out.print(WHITESPACE);
} else if (col == stopper) {
for (int i = ROWS-row; i > 0; i--) {
System.out.print(pattern[row]);
System.out.print(WHITESPACE);
}
} else if (col > stopper) {
System.out.print(WHITESPACE);
}
}
System.out.print(NEWLINE);
}
System.out.print(NEWLINE);
}
@Override
public void print() {
process(new String[]{ASTERISK, ASTERISK, ASTERISK, ASTERISK, ASTERISK});
}
@Override
public void print(String[] pattern) {
process(pattern);
}
}
class DiagonalArt implements AsciiArt {
private static final String ASTERISK = "*";
private static final String PLUS = "+";
private static final String WHITESPACE = " ";
private static final String NEWLINE = "\n";
private static final int ROWS = 5;
private static final int COLS = 5;
private DiagonalArt() {}
public static DiagonalArt of() {
return new DiagonalArt();
}
private void process(String[] pattern) {
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
int stopper = row;
if (col < stopper) {
System.out.print(pattern[0]);
System.out.print(WHITESPACE);
} else {
System.out.print(pattern[1]);
System.out.print(WHITESPACE);
}
}
System.out.print(NEWLINE);
}
System.out.print(NEWLINE);
}
@Override
public void print() {
process(new String[]{PLUS, ASTERISK});
}
@Override
public void print(String[] pattern) {
process(pattern);
}
}
class InvertedDiagonalArt implements AsciiArt {
private static final String ASTERISK = "*";
private static final String PLUS = "+";
private static final String WHITESPACE = " ";
private static final String NEWLINE = "\n";
private static final int ROWS = 5;
private static final int COLS = 5;
private InvertedDiagonalArt() {}
public static InvertedDiagonalArt of() {
return new InvertedDiagonalArt();
}
private void process(String[] pattern) {
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
int stopper = COLS - (row + 1);
if (col < stopper) {
System.out.print(pattern[0]);
System.out.print(WHITESPACE);
} else {
System.out.print(pattern[1]);
System.out.print(WHITESPACE);
}
}
System.out.print(NEWLINE);
}
System.out.print(NEWLINE);
}
@Override
public void print() {
process(new String[]{PLUS, ASTERISK});
}
@Override
public void print(String[] pattern) {
process(pattern);
}
}
class ComplexArt implements AsciiArt {
private static final String ASTERISK = "*";
private static final String PLUS = "+";
private static final String WHITESPACE = " ";
private static final String NEWLINE = "\n";
private static final int ROWS = 5;
private static final int COLS = 9;
private ComplexArt() {}
public static ComplexArt of() {
return new ComplexArt();
}
private void process(String[] pattern) {
int mid = COLS/2;
for (int row = 0; row < ROWS; row++) {
int k = 0;
int j = ROWS-1;
for (int col = 0; col < COLS; col++) {
int stopper = mid - row;
if (col < stopper) {
// Render initial 50% of outer
System.out.print(pattern[0]);
System.out.print(WHITESPACE);
} else if (col == stopper) {
// Render initial 50% of inner
for (int i = 0; i < row + 1; i++) {
System.out.print(pattern[1]);
System.out.print(WHITESPACE);
}
} else if (col > stopper) {
// Render remaining 50% of inner
for (; k < row; k++) {
System.out.print(pattern[1]);
System.out.print(WHITESPACE);
}
// Render remaining 50% of outer
for (; j > row; j--) {
System.out.print(pattern[0]);
System.out.print(WHITESPACE);
}
}
}
System.out.print(NEWLINE);
}
System.out.print(NEWLINE);
}
@Override
public void print() {
process(new String[]{PLUS, ASTERISK});
}
@Override
public void print(String[] pattern) {
process(pattern);
}
}
class InvertedComplexArt implements AsciiArt {
private static final String ASTERISK = "*";
private static final String PLUS = "+";
private static final String WHITESPACE = " ";
private static final String NEWLINE = "\n";
private static final int ROWS = 5;
private static final int COLS = 9;
private InvertedComplexArt() {}
public static InvertedComplexArt of() {
return new InvertedComplexArt();
}
private void process(String[] pattern) {
for (int row = 0; row < ROWS; row++) {
int k = 0;
int j = 0;
for (int col = 0; col < COLS; col++) {
int stopper = row;
if (col < stopper) {
// Render initial 50% of outer
System.out.print(pattern[0]);
System.out.print(WHITESPACE);
} else if (col == stopper) {
// Render initial 50% of inner
for (int i = ROWS-row; i > 0; i--) {
System.out.print(pattern[1]);
System.out.print(WHITESPACE);
}
} else if (col > stopper) {
// Render remaining 50% of inner
for (; k < ROWS-row-1; k++) {
System.out.print(pattern[1]);
System.out.print(WHITESPACE);
}
// Render remaining 50% of outer
for (; j < row; j++) {
System.out.print(pattern[0]);
System.out.print(WHITESPACE);
}
}
}
System.out.print(NEWLINE);
}
System.out.print(NEWLINE);
}
@Override
public void print() {
process(new String[]{PLUS, ASTERISK});
}
@Override
public void print(String[] pattern) {
process(pattern);
}
}