Is there a more refined solution to displaying a shirt?

54 Views Asked by At

I am creating an ascii art of a t shirt using this said function, however I'm not sure where to start on making it more concise to begin with.

    void 
    displayShirt(char size, char neckline, char leftsleeve, char leftChest, char rightSleeve, char      rightChest, char bottomLeft, char bottomRight) {

    int isRound;
    int halfColumn;
    int r;
    int c;
    int rows, columns;

    switch (size) {
        case 'S':
            rows = 10;
            columns = 18;
            break;
        case 'M':
            rows = 12;
            columns = 22;
            break;
        case 'L':
            rows = 14;
            columns = 26;
            break;
        case 'X':
            rows = 16;
            columns = 30;
            break;
    }

    halfColumn = columns / 2;

    switch (neckline) {
        case 'R':
            isRound = 1;
            break;
        case 'V':
            isRound = 0;
            break;
    }

    printf("\n\nMock Shirt:\n");


    for (r = 1; r <= rows; r++) {
        for (c = 0; c <= columns; c++) {
            if (r == 1) {
                if (c >= 0 && c <= 3)
                    printf(" ");
                else if ( (c == 4 || (c <= halfColumn - 2 || c >= halfColumn + 3)) 
                        && (c <= columns - 3))
                    printf("x");
                else printf(" ");
            }
            else if (r == 2) {
                if ((isRound == 1) && (c == halfColumn || c == halfColumn + 1 ))
                    printf("x");
                else if (c == 3 || c == halfColumn - 1 || c == halfColumn + 2 || c == columns - 2)
                    printf("x");
                else
                    printf(" ");
            }
            else if (r == 3) {
                if (c == 2)
                    printf("x");
                else if (c == 4 && (rightSleeve == 'L' || rightSleeve == 'P'))
                    printf("%c", rightSleeve);
                else if ((isRound == 0) && (c == halfColumn || c == halfColumn + 1))
                    printf("x");
                else if (c == columns - 3 && (leftsleeve == 'L' || leftsleeve == 'P'))
                    printf("%c", leftsleeve);
                else if (c == columns - 1)
                    printf("x");
                else
                    printf(" ");
            }
            else if (r == 4) {
                if (c >= 1 && c <= 4)
                    printf("x");
                else if (c == 6 && (rightChest == 'L' || rightChest == 'P' || rightChest == 'O'))
                    printf("%c", rightChest);
                else if (c == columns - 5 && (leftChest == 'L' || leftChest == 'P' || leftChest == 'O'))
                    printf("%c", leftChest);
                else if (c >= columns - 3 && c <= columns)
                    printf("x");
                else
                    printf(" ");
            }
            else if ((r >= 5 || r > rows) && ((c == 4 || c == columns - 3) || (r == rows && (c >= 4 && c <= columns - 3))))
                printf("x");
            else if (r == rows - 1 && c == 6 && bottomRight == 'O')
                printf("%c", bottomRight);
            else if (r == rows - 1 && c == columns - 5 && bottomLeft == 'O')
                printf("%c", bottomLeft);
            else
                printf(" ");
        }
        printf("\n");
    }
}

int main() {
    char size = 'M';
    char neckline = 'V';
    char leftSleeve = 'L';
    char leftChest = 'O';
    char rightSleeve = 'O';
    char rightChest = 'O';
    char bottomLeft = 'O';
    char bottomRight = 'O';

    displayShirt(size, neckline, leftSleeve, leftChest, rightSleeve, rightChest, bottomLeft, bottomRight);
    
    size = 'X';
    neckline = 'R';
    leftSleeve = 'P';
    leftChest = 'L';
    rightSleeve = 'L';
    rightChest = 'O';
    bottomLeft = 'O';
    bottomRight = 'O';
    
    displayShirt(size, neckline, leftSleeve, leftChest, rightSleeve, rightChest, bottomLeft, bottomRight);

    return 0;
}

As you can see, I'm trying to show the shirt per row mostly. Is there a way to visualize the first four rows as two separate trapezoids? And how should I approach it that way?

0

There are 0 best solutions below