Copy code
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// Function to clear the screen
void clearScreen() {
printf("\033[H\033[J");
}
int main() {
int i, j, k;
int n = 100; // number of frames
int delay = 100000; // delay between frames in microseconds
char stars[20][41]; // array to store the positions of stars
// Initialize stars array
for (i = 0; i < 20; i++) {
for (j = 0; j < 40; j++) {
stars[i][j] = ' ';
}
}
// Generate random positions for stars
for (i = 0; i < 50; i++) {
int x = rand() % 20;
int y = rand() % 40;
stars[x][y] = '*';
}
// Animation loop
for (k = 0; k < n; k++) {
clearScreen(); // Clear screen
// Print stars
for (i = 0; i < 20; i++) {
for (j = 0; j < 40; j++) {
printf("%c ", stars[i][j]);
}
printf("\n");
}
usleep(delay); // Wait before next frame
}
return 0;