2024年4月15日发(作者:)
c语言烟花程序代码 -回复
下面是一个简单的 C 语言烟花程序代码:
c
include
include
include
include
void delay(int milliseconds) {
long pause;
clock_t now, then;
pause = milliseconds * (CLOCKS_PER_SEC / 1000);
now = then = clock();
while ((now - then) < pause) {
now = clock();
}
}
void setCursorPos(int x, int y) {
COORD pos = {x, y};
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(output, pos);
}
void setColor(int color) {
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(output, color);
}
int main() {
srand(time(NULL));
int width = 50;
int height = 20;
int x = width / 2;
int y = height - 2;
while (1) {
int r = rand() 256;
int g = rand() 256;
int b = rand() 256;
int color = r + g * 256 + b * 256 * 256;
int speed = 1 + rand() 5;
int angle = 30 + rand() 121;
int rads = angle * 3.14159 / 180;
float vx = speed * cos(rads);
float vy = -speed * sin(rads);
setCursorPos(x, y);
setColor(color);
发布者:admin,转转请注明出处:http://www.yc00.com/web/1713132509a2189306.html
评论列表(0条)