0% found this document useful (0 votes)
16 views

Rainbow Recursion

Uploaded by

dennikonov2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Rainbow Recursion

Uploaded by

dennikonov2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <iostream>

#include <string>
#include <stdlib.h>
#include <windows.h>
HANDLE hOUTPUT = GetStdHandle(STD_OUTPUT_HANDLE);
using namespace std;

double different_speed = 0, switcher_operation = 0;


int for_switcher_operation = 0;

inline void red(string text, int number)


{
SetConsoleTextAttribute(hOUTPUT, FOREGROUND_RED);
cout << number << "\t" << text << endl;
}
inline void orange(string text, int number)
{
SetConsoleTextAttribute(hOUTPUT, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout << number << "\t" << text << endl;
}
inline void yellow(string text, int number)
{
SetConsoleTextAttribute(hOUTPUT, FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_INTENSITY);
cout << number << "\t" << text << endl;
}
inline void green(string text, int number)
{
SetConsoleTextAttribute(hOUTPUT, FOREGROUND_GREEN);
cout << number << "\t" << text << endl;
}
inline void blue(string text, int number)
{
SetConsoleTextAttribute(hOUTPUT, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout << number << "\t" << text << endl;
}
inline void dark_blue(string text, int number)
{
SetConsoleTextAttribute(hOUTPUT, FOREGROUND_BLUE);
cout << number << "\t" << text << endl;
}
inline void violet(string text, int number)
{
SetConsoleTextAttribute(hOUTPUT, FOREGROUND_RED | FOREGROUND_BLUE |
FOREGROUND_INTENSITY);
cout << number << "\t" << text << endl;
}

// recursion
int recursion(bool shifter, int n = 0, int number_for_rainbow = 0)
{
if (n < 1)
return 0;

int color = 701 - n;

if (number_for_rainbow >= 7)
number_for_rainbow *= 0;
number_for_rainbow++;
/*
if (color % 7 == 0)
{
violet("iteration", color);
}
else if (color % 6 == 0)
{
dark_blue("iteration", color);
}
else if (color % 5 == 0)
{
blue("iteration", color);
}
else if (color % 4 == 0)
{
green("iteration", color);
}
else if (color % 3 == 0)
{
yellow("iteration", color);
}
else if (color % 2 == 0)
{
orange("iteration", color);
}
else if (color % 1 == 0)
{
red("iteration", color);
cout << endl;
}
*/

if (number_for_rainbow == 7)
{
violet("iteration", color);
cout << endl;
}
else if (number_for_rainbow == 6)
{
dark_blue("iteration", color);
}
else if (number_for_rainbow == 5)
{
blue("iteration", color);
}
else if (number_for_rainbow == 4)
{
green("iteration", color);
}
else if (number_for_rainbow == 3)
{
yellow("iteration", color);
}
else if (number_for_rainbow == 2)
{
orange("iteration", color);
}
else if (number_for_rainbow == 1)
{
red("iteration", color);
}

//if (color == 360)


// system("pause");

if (for_switcher_operation % 60 == 0)
{
shifter = !shifter; // genial juggling with a shifter bool
}

if (shifter == true)
switcher_operation = 0.6;
else if (shifter == false)
switcher_operation = -0.6;

for_switcher_operation++;
/*
for (size_t i = 0; i < 10; i++)
{
if (for_switcher_operation == 60 * i)
shifter = !shifter; // genial juggling with a shifter bool
}
*/
/*
int thirty = 60;
for_switcher_operation++;
if (for_switcher_operation % thirty == 0)
switcher_operation = -0.3;
else if (for_switcher_operation % 2 * thirty == 0 || for_switcher_operation
== 1)
switcher_operation = 0.6;
*/
/*
if (different_speed < 30 && different_speed >= 0)
{
switcher_operation = 0.6;
}
if (different_speed > 30 && different_speed < 35)
{
switcher_operation = -0.3;
}
different_speed += switcher_operation;
*/

different_speed += switcher_operation;
int sleep_time = different_speed;
Sleep(sleep_time);

n -= 1;
return recursion(shifter, n, number_for_rainbow);
}

int main()
{
recursion(false, 700, 0);
SetConsoleTextAttribute(hOUTPUT, FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE);
cout << endl << "END" << endl << "return recursion = " << recursion(true) <<
endl;
}

You might also like