Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
2.8 kB
3
Indexable
Never
#include <stdio.h>

#define N 15
#define M 13

void transform(int *buf, int **matr, int n, int m);
void make_picture(int **picture, int n, int m);
void reset_picture(int **picture, int n, int m);
void print_picture(int **picture, int n, int m);

int main() {
    int picture_data[N][M];
    int *picture[N];
    for(int i = 0; i < N; i++) {
        picture[i] = picture_data[i];
    }

    transform((int *)picture_data, picture, N, M);
    make_picture(picture, N, M);
    print_picture(picture, N, M);

    return 0;
}

void make_picture(int **picture, int n, int m) {
    // Сброс картинки
    reset_picture(picture, n, m);

    // Рамка
    for (int i = 0; i < n; i++) {
        picture[i][0] = 1;
        picture[i][m-1] = 1;
    }
    for (int j = 0; j < m; j++) {
        picture[0][j] = 1;
        picture[n-1][j] = 1;
    }

    // Ствол дерева
    for (int i = n/2; i < n/2 + 4; i++) {
        picture[i][m/2] = 7;
    }

    // Листва дерева
    for (int i = n/2 - 3; i <= n/2; i++) {
        for (int j = m/2 - 2; j <= m/2 + 2; j++) {
            picture[i][j] = 3;
        }
    }

    // Солнце
    int sun_data[6][5] = { { 0, 6, 6, 6, 0 }, 
                           { 6, 6, 6, 6, 6 }, 
                           { 6, 6, 6, 6, 6 },
                           { 0, 6, 6, 6, 0 },
                           { 0, 0, 6, 0, 0 },
                           { 0, 0, 6, 0, 0 } };
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 5; j++) {
            if (sun_data[i][j] != 0) {
                picture[1+i][m-6+j] = sun_data[i][j];
            }
        }
    }
}

void reset_picture(int **picture, int n, int m) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            picture[i][j] = 0;
        }
    }
}

void transform(int *buf, int **matr, int n, int m) {
    for (int i = 0; i < n; i++) {
        matr[i] = buf + i * m;
    }
}

void print_picture(int **picture, int n, int m) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            switch (picture[i][j]) {
                case 0:
                    printf("  "); // Пустое пространство
                    break;
                case 1:
                    printf("* "); // Рамка
                    break;
                case 3:
                    printf("# "); // Листва дерева
                    break;
                case 6:
                    printf("@ "); // Солнце
                    break;
                case 7:
                    printf("| "); // Ствол дерева
                    break;
                default:
                    printf("  ");
            }
        }
        printf("\n");
    }
}
Leave a Comment