Mildly entertaining extrasJust since playing with ascii terminals isn't all that exciting, here are some functions that let you
To include the set of functions in a program, just make sure you copy the effects.h file to the same directory as the rest of your code, and in your .cpp or .C file add #include "effects.h" The functions it provides are:
|
Example:
|
Here are more details on the various functions:
// usage
char ch;
if (keyQuick(ch)) {
// user pressed a key, the character is in ch, do what you will
......
}
// usage sysPause(0.1); // pause 0.1 seconds
// usage long height, width; getTermSize(height, width);
// usage clear();
// usage chgText(Red); chgBack(Green);
// usage chgFormat(Bold);
// The sample program that produces the image at the top of the page
#include "effects.h"
#include <iostream>
using namespace std;
int main()
{
clear();
chgText(Red);
cout << "\nEXPERIMENTING WITH ";
chgFormat(Underline);
cout << "EFFECTS";
chgFormat(DefForm);
cout << endl << endl;
chgText(Blue);
long height, width;
getTermSize(height, width);
cout << "The terminal size is: " << height << "," << width << endl;
chgText(Green);
cout << "Hit a key when you're ready" << endl;
char ch;
int count = 0;
while (true) {
if (keyQuick(ch)) break;
cout << ".";
cout.flush();
sysPause(0.1);
count++;
}
cout << "\n\nIt took you " << (0.1*count) << " seconds to hit " << ch << endl << endl;
chgFormat(Bold);
cout << "\nBYE NOW!!\n\n";
chgText(DefCol);
chgFormat(DefForm);
}
|
// And a program to throw random X's across your window
#include "effects.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void drawBlack(long rows, long cols);
void throwDarts(long rows, long cols, long darts);
int main()
{
long rows, cols;
getTermSize(rows,cols);
drawBlack(rows,cols);
throwDarts(rows,cols, rows*cols);
chgText(DefCol);
chgBack(DefCol);
chgFormat(DefForm);
}
void drawBlack(long rows, long cols)
{
chgBack(Black);
clear();
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
cout << " ";
}
cout << "\n";
}
}
void throwDarts(long rows, long cols, long darts)
{
srand(time(NULL));
chgText(Red);
chgFormat(Bold);
for (int d = 0; d < darts; d++) {
sysPause(0.2);
long r = 1 + rand() % rows;
long c = 1 + rand() % cols;
moveCursor(r,c);
cout << "X";
cout.flush();
}
}
|