Trying to Output an ASCII Pattern

  ascii, ascii-art, c++, output

My desired output looks about like this:

    **         **         **         **         **
   ****       ****       ****       ****       ****
  ******     ******     ******     ******     ******
 ********   ********   ********   ********   ********
********** ********** ********** ********** **********
********** ********** ********** ********** **********
 ********   ********   ********   ********   ********
  ******     ******     ******     ******     ******
   ****       ****       ****       ****       ****
    **         **         **         **         **
    **         **         **         **         **
   ****       ****       ****       ****       ****
  ******     ******     ******     ******     ******
 ********   ********   ********   ********   ********
********** ********** ********** ********** **********
********** ********** ********** ********** **********
 ********   ********   ********   ********   ********
  ******     ******     ******     ******     ******
   ****       ****       ****       ****       ****
    **         **         **         **         **
    **         **         **         **         **
   ****       ****       ****       ****       ****
  ******     ******     ******     ******     ******
 ********   ********   ********   ********   ********
********** ********** ********** ********** **********
********** ********** ********** ********** **********
 ********   ********   ********   ********   ********
  ******     ******     ******     ******     ******
   ****       ****       ****       ****       ****
    **         **         **         **         **

I’ve been able to figure out how to get the first diamond shape with the following:

//inside of a void function called printDots()
char dot = '*';
char blank = ' ';

for (int i = 1; i < 6; i++) {
    for (int k = 6; k > i; k--) { // right-shifts the first triangle
        std::cout << blank;
    }
    for (int j = 0; j < i; j++) { // first triangle
        std::cout << dot;
    }
    for (int j = 0; j < i; j++) { // second triangle (left-aligned)
        std::cout << dot;
    }
    std::cout << "n";
}
for (int i = 1; i < 6; i++) {
    for (int k = 0; k < i; k++) { // right-shifts the third triangle
        std::cout << blank;
    }
    for (int j = 6; j > i; j--) { // third triangle
        std::cout << dot;
    }
    for (int j = 6; j > i; j--) { // fourth triangle (left-aligned)
        std::cout << dot;
    }
    std::cout << "n";
}

I’m struggling to figure out how to repeat this shape in the desired pattern, though. I’ve tried adding more for loops to do the same thing that I’m already doing to make all four parts of the diamond, but it seems to just be shifting the asterisks down vertically and disrupting the pattern, all without achieving any of the horizontal output. I could just manually output the pattern with a large std::cout statement, but I’m trying to figure out how to generate the shape rather than just copying and pasting it. Any advice?

Source: Windows Questions C++

LEAVE A COMMENT