#include #include #include #include #include #define M_PI 3.14159 const int WIDTH = 96; // Console width const int HEIGHT = 32; // Console height const int MESSAGE_BOX_WIDTH = 60; // Width of the message box const int PROC_TIME = 25; //ms for processing time // Function to clear the console void clearConsole() { std::cout << "\033[2J\033[1;1H"; // ANSI escape code to clear console } // Function to set console text color void setColor(int color) { std::cout << "\033[38;5;" << color << "m"; // ANSI escape code to set text color } // Function to draw ASCII graph with rainbow glowy fader animation void drawGraph(float time, char symbol, int dimensions, int swirl, int initialSwirl) { clearConsole(); // Loop through each row of the console for (int y = 0; y < HEIGHT; ++y) { // Loop through each column of the console for (int x = 0; x < WIDTH; ++x) { // Calculate distance from center of the screen float distance = std::sqrt(std::pow(x - WIDTH / 2, 2) + std::pow(y - HEIGHT / 2, 2)); // Calculate color based on distance, time, and position int color = static_cast(std::fmod(distance + time * 10, 256)); setColor(color); // Output ASCII character based on distance if (distance < 5) { std::cout << "@"; } else if (distance < 9) { std::cout << symbol; } else { // Add swirls, spirals, etc. char effect = static_cast('Y' + swirl); // Varying effects based on input std::cout << effect; } } std::cout << std::endl; // Move to next line } } // Function to display messages in a message box void displayMessages(const std::deque& messageQueue) { // Clear the message box area for (int i = 0; i < HEIGHT; ++i) { for (int j = WIDTH - MESSAGE_BOX_WIDTH; j < WIDTH; ++j) { std::cout << " "; } std::cout << std::endl; } // Display messages in the message box int row = 1; for (const auto& message : messageQueue) { std::cout << "\033[" << row << ";" << (WIDTH - MESSAGE_BOX_WIDTH + 1) << "H"; // Move cursor to message box area std::cout << message << std::endl; ++row; } } // Function to generate a sine wave void generateSineWave(float time, int frequency, float amplitude, char symbol) { int xOffset = 10; // Offset for the wave on the x-axis int yOffset = HEIGHT / 2; // Offset for the wave on the y-axis for (int x = 0; x < WIDTH; ++x) { float y = amplitude * std::sin(2 * M_PI * frequency * (x - xOffset) / WIDTH + time); int yPos = static_cast(yOffset + y); if (yPos >= 0 && yPos < HEIGHT) { std::cout << "\033[" << yPos + 1 << ";" << x + 1 << "H"; // Move cursor to wave position std::cout << symbol; // Draw wave symbol } } } // Function to generate a triangle wave void generateTriangleWave(float time, int frequency, float amplitude, char symbol) { int xOffset = 10; // Offset for the wave on the x-axis int yOffset = HEIGHT / 2; // Offset for the wave on the y-axis for (int x = 0; x < WIDTH; ++x) { float period = WIDTH / (2 * frequency); float phase = std::fmod((x - xOffset) / period, 2.0f); float y; if (phase < 1.0f) { y = amplitude * (2 * phase - 1); } else { y = amplitude * (3 - 2 * phase); } int yPos = static_cast(yOffset + y); if (yPos >= 0 && yPos < HEIGHT) { std::cout << "\033[" << yPos + 1 << ";" << x + 1 << "H"; // Move cursor to wave position std::cout << symbol; // Draw wave symbol } } } // Function to generate a square wave void generateSquareWave(float time, int frequency, float amplitude, char symbol) { int xOffset = 10; // Offset for the wave on the x-axis int yOffset = HEIGHT / 2; // Offset for the wave on the y-axis for (int x = 0; x < WIDTH; ++x) { float period = WIDTH / frequency; float phase = std::fmod((x - xOffset) / period, 1.0f); float y; if (phase < 0.5f) { y = amplitude; } else { y = -amplitude; } int yPos = static_cast(yOffset + y); if (yPos >= 0 && yPos < HEIGHT) { std::cout << "\033[" << yPos + 1 << ";" << x + 1 << "H"; // Move cursor to wave position std::cout << symbol; // Draw wave symbol } } } void displayMessages(bool displayStats, float time, char symbol, char symbol2, int dimensions, int swirl, int initialSwirl) { std::cout << std::endl; // Display current dimensions and swirl std::cout << "\n\n\n"; std::cout << "Current Dimensions: " << dimensions << "D\n"; std::cout << "Current Swirl: " << symbol << " '&' " << symbol2 << " :" << swirl << "\n"; std::cout << "Initial Swirl: " << initialSwirl << "\n"; std::cout << "\n\n\n"; // Pause for a short duration to control animation speed std::this_thread::sleep_for(std::chrono::milliseconds(25) ); } int main() { char symbol, symbol2; std::cout << "Enter the symbol to use for the : "; std::cin >> symbol; std::cout << "Enter symbol2: "; std::cin >> symbol2; int dimensions = 9; // Default dimensions int swirl = 4; // Default swirl int initialSwirl; // Initial swirl size std::cout << "Enter the initial swirl size: "; std::cin >> initialSwirl; std::cout << "Processing world"; for (int i = 0; i < 5; i++) { std::cout << "."; std::this_thread::sleep_for(std::chrono::milliseconds(384)); } std::cout << "\n"; std::this_thread::sleep_for(std::chrono::milliseconds(2000)); float time = 0.0f; std::deque messageQueue; while (true) { // Generate and draw sine wave generateSineWave(time, 2, 8, '*'); // Generate and draw triangle wave generateTriangleWave(time, 1, 5, '+'); // Generate and draw square wave generateSquareWave(time, 3, 3, '-'); drawGraph(time, symbol, dimensions, swirl, initialSwirl); displayMessages(messageQueue); // Display messages in the message box // Increment time for animation time += 0.1f; // Pause for a short duration to control animation speed std::this_thread::sleep_for(std::chrono::milliseconds(PROC_TIME)); } std::cout << "Goodbye, Professor"; for (int i = 0; i < 3; i++) { std::cout << "."; std::this_thread::sleep_for(std::chrono::milliseconds(384)); } return 0; }