C语言生成舒尔特方格 -- 注意力训练

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
static int LEN = 7;
#define DIV_UP(a, b) ((a + b - 1) / b)
#define WALL "* "
static int NUM = 0;
static int walls = 3;
int rand_num[100] = {0};

void draw_col(int len) {
    int flag = 0;
    for (int i = 0; i < len;  i++) {
        for (int j = 0; j < LEN - flag; j++) {
            printf(WALL);
        }
        flag = 1;
    }
    printf("\n");
}

void row_with_blank(int len) {
    //len = (len - 1) * LEN + 1;
    for (int i = 0; i < len; i++) {
        printf(WALL);
        for (int j = 0; j < LEN - 2; j++) {
            printf("  ");
        }
    }
    printf(WALL);
    printf("\n");
}


void row_with_digit(int len) {
    for (int i = 0; i < len; i++) {
        printf(WALL);
        int col_blank = (LEN - 3) / 2;
        for (int j = 0; j < col_blank; j++) {
            printf("  ");
        }
        if (rand_num[NUM] <= 9) printf("%d ", rand_num[NUM++]);
        else printf("%d", rand_num[NUM++]);
        for (int j = 0; j < col_blank; j++) {
            printf("  ");
        }
    }
    printf(WALL);
    printf("\n");
}

void draw(int len) {
    //draw_col(len);
    for (int i = 0; i < len; i++) {
        draw_col(len);
        int row_blank = (LEN - 3) / 2;
        for (int j = 0; j < row_blank; j++) {
            row_with_blank(len);
        }
        row_with_digit(len);
        for (int j = 0; j < row_blank; j++) {
            row_with_blank(len);
        }
    }
    draw_col(len);
    printf("\n");
}

void parse_opt(int argc, char** argv) {
    char ch;
    while ((ch = getopt(argc, argv, "n:g:")) != -1) {
        switch (ch) {
            case 'n':
                walls = atoi(optarg);
                break;
            case 'g':
                LEN = atoi(optarg);
                LEN |= 1;
                break;
        }
    }
}

void make_random() {
    int nums = walls * walls;
    int ind = rand() % nums;
    for (int i = 1; i <= nums; i++) {
        while (rand_num[ind] != 0) {
            ind = rand() % nums;
        }
        rand_num[ind] = i;
    }
}

int main(int argc, char** argv) {
    parse_opt(argc, argv);
    srand(time(0) ^ getpid());
    make_random();
    int times = 0;
    while (1) {
        NUM = 0;
        char buf[10] = {0};
        FILE* fp = popen("clear", "r");
        fread(buf, 1024, 1, fp);
        pclose(fp);
        printf("%s", buf);
        int n;
        printf("%d total: %d\n", times, walls * walls);
        draw(walls);
        sleep(1);
        times++;
    }
    return 0;
}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python尔特方格是一种用于可视化数据的图形工具,它由Python编程语言和matplotlib库提供支持。尔特方格可以帮助我们更好地理解数据之间的关系和趋势。 尔特方格通常用于绘制二维数据,其中一个维度表示数据的横坐标,另一个维度表示数据的纵坐标。每个数据点在方格中的位置由其横纵坐标决定,而数据点的颜色或大小可以表示其对应的数值。 在Python中,我们可以使用matplotlib库来创建尔特方格。首先,我们需要导入matplotlib库,并创建一个图形对象。然后,我们可以使用scatter函数来绘制数据点,并通过设置参数来调整数据点的颜色、大小等属性。最后,我们可以使用xlabel、ylabel和title函数来添加坐标轴标签和标题。 下面是一个简单的示例代码,演示了如何使用Python绘制尔特方格: ```python import matplotlib.pyplot as plt # 创建图形对象 fig, ax = plt.subplots() # 数据 x = [1, 2, 3, 4, 5] y = [1, 4, 9, 16, 25] # 绘制尔特方格 ax.scatter(x, y, c='blue', s=50) # 添加坐标轴标签和标题 ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_title('Schulte Grid') # 显示图形 plt.show() ``` 这段代码将创建一个尔特方格,其中x轴表示数据的横坐标,y轴表示数据的纵坐标。数据点的颜色为蓝色,大小为50。坐标轴标签分别为'X'和'Y',标题为'Schulte Grid'。 希望以上内容对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值