Generation

generate functionMon, 18 Nov 2024

Tienen que estar formados de Asteriscos en la primera figura cada asterisco debe tener un color y debe prender de abajo hacia arriba y de regreso, el segundo tiene que dar vuelta, le añadimos una velocidad se van apagando los asteriscos

Aquí te muestro un ejemplo de cómo podrías implementar esto en C++ utilizando la biblioteca `ncurses` para crear una interfaz de usuario en modo texto y la biblioteca `thread` para simular la velocidad de apagado de los asteriscos. ```cpp #include <ncurses.h> #include <thread> #include <chrono> #include <vector> // Enum para representar los colores enum Color { ROJO, AZUL, VERDE, AMARILLO, MORADO, CYAN, BLANCO, NEGRO }; // Estructura para representar un asterisco struct Asterisco { int x, y; Color color; bool encendido; }; // Función para dibujar un asterisco void dibujarAsterisco(Asterisco asterisco, WINDOW* ventana) { if (asterisco.encendido) { mvwprintw(ventana, asterisco.y, asterisco.x, "*"); wattron(ventana, COLOR_PAIR(asterisco.color)); mvwprintw(ventana, asterisco.y, asterisco.x, "*"); wattroff(ventana, COLOR_PAIR(asterisco.color)); } else { mvwprintw(ventana, asterisco.y, asterisco.x, " "); } } // Función para apagar un asterisco void apagarAsterisco(Asterisco& asterisco) { asterisco.encendido = false; } // Función para encender un asterisco void encenderAsterisco(Asterisco& asterisco) { asterisco.encendido = true; } // Función para simular la velocidad de apagado de los asteriscos void simularVelocidadApagado(Asterisco& asterisco, int velocidad) { for (int i = 0; i < velocidad; i++) { apagarAsterisco(asterisco); std::this_thread::sleep_for(std::chrono::milliseconds(100)); encenderAsterisco(asterisco); std::this_thread::sleep_for(std::chrono::milliseconds(100)); } } int main() { // Inicializar ncurses initscr(); cbreak(); noecho(); curs_set(0); // Crear pares de colores start_color(); init_pair(ROJO, COLOR_RED, COLOR_BLACK); init_pair(AZUL, COLOR_BLUE, COLOR_BLACK); init_pair(VERDE, COLOR_GREEN, COLOR_BLACK); init_pair(AMARILLO, COLOR_YELLOW, COLOR_BLACK); init_pair(MORADO, COLOR_MAGENTA, COLOR_BLACK); init_pair(CYAN, COLOR_CYAN, COLOR_BLACK); init_pair(BLANCO, COLOR_WHITE, COLOR_BLACK); init_pair(NEGRO, COLOR_BLACK, COLOR_BLACK); // Crear ventana WINDOW* ventana = newwin(20, 80, 0, 0); box(ventana, 0, 0); wrefresh(ventana); // Crear asteriscos std::vector<Asterisco> asteriscos; for (int i = 0; i < 10; i++) { Asterisco asterisco; asterisco.x = i * 8; asterisco.y = 0; asterisco.color = static_cast<Color>(i % 7); asterisco.encendido = true; asteriscos.push_back(asterisco); } // Simular la velocidad de apagado de los asteriscos for (int i = 0; i < 10; i++) { simularVelocidadApagado(asteriscos[i], 5); } // Dibujar asteriscos for (int i = 0; i < 10; i++) { dibujarAsterisco(asteriscos[i], ventana); } // Simular la velocidad de encendido de los asteriscos for (int i = 0; i < 10; i++) { std::thread hilo([i, &asteriscos]() { for (int j = 0; j < 10; j++) { simularVelocidadApagado(asteriscos[i], 5); std::this_thread::sleep_for(std::chrono::milliseconds(100)); dibujarAsterisco(asteriscos[i], initscr()); wrefresh(initscr()); } }); hilo.detach(); } // Esperar a que los asteriscos se enciendan std::this_thread::sleep_for(std::chrono::seconds(10)); // Dibujar asteriscos con velocidad de encendido for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { simularVelocidadApagado(asteriscos[i], 5); std::this_thread::sleep_for(std::chrono::milliseconds(100)); dibujarAsterisco(asteriscos[i], ventana); wrefresh(ventana); } } // Esperar a que los asteriscos se apaguen std::this_thread::sleep_for(std::chrono::seconds(10)); // Dibujar asteriscos con velocidad de apagado for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { simularVelocidadApagado(asteriscos[i], 5); std::this_thread::sleep_for(std::chrono::milliseconds(100)); dibujarAsterisco(asteriscos[i], ventana); wrefresh(ventana); } } // Esperar a que los asteriscos se apaguen completamente std::this_thread::sleep_for(std::chrono::seconds(10)); // Borrar ventana delwin(ventana); endwin(); return 0; } ``` Este código crea una ventana con 10 asteriscos que se encienden y apagan con una velocidad determinada. Los asteriscos se dibujan en la ventana y se actualizan en tiempo real. El código utiliza la biblioteca `ncurses` para crear la ventana y la biblioteca `thread` para simular la velocidad de encendido y apagado de los asteriscos. Recuerda que debes compilar el código con la opción `-lncurses` para incluir la biblioteca `ncurses` en el ejecutable.

Want to kickstart your project?Use the new AI Studio to create your code