丙丁先生 发表于 2025-6-7 23:23

繁星C程序

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

#define WIDTH 80
#define HEIGHT 25

void clearScreen() {
    printf("\033[2J\033[H");
}

void setBGColor() {
    printf("\033[40m"); // 设置背景为黑色
    printf("\033[37m"); // 设置文字为白色
}

void printStar(int x, int y) {
    printf("\033[%d;%dH*", y, x);
}

int main() {
    srand(time(NULL)); // 初始化随机数种子
    clearScreen();    // 清屏
    setBGColor();   // 设置背景和文字颜色

    while (1) {
      clearScreen(); // 每次循环清屏,重新绘制星星
      for (int i = 0; i < 100; i++) { // 随机生成100颗星星
            int x = rand() % WIDTH + 1; // 随机生成x坐标
            int y = rand() % HEIGHT + 1; // 随机生成y坐标
            printStar(x, y); // 在指定位置打印星星
      }
      usleep(100000); // 暂停0.1秒
    }

    return 0;
}

丙丁先生 发表于 2025-6-7 23:24

繁星C程序https://bbs.21ic.com/forum.html?mod=viewthread&tid=3459768&fromguid=hot&extra=&mobile=2

AuroraWaltz 发表于 2025-6-18 15:47

繁星C程序???什么鬼没听过啊 是满天星吗?
页: [1]
查看完整版本: 繁星C程序