/*
IDEA BY OUR SIR
Programmer - Aditya Gupta (aka. Techy15)
Language - C++
NAMASTE !
*/
//Known Bug : It doesn't scroll if it the length of the bigger string matches the terminal width, for a second or so
/*LEARNT ThINGS :
* VIM : :%s/foo/bar/g finds and replaces ALL 'foo' with 'bar'
* A - 65
* a - 97
*Observation - Terminal in windowed mode has a heiht of 23 lines, width of 80 characters; and in full screen, has a height of 38 lines, and width of 169 characters [Useful for creating clrscr alternative with newlines] */
#include <iostream>
#include <string>
#include <unistd.h>
#ifdef _WIN32 //Macro defined by MSVC (Microsoft Visual C++) compiler (not g++)
#include <windows.h>
#elif __linux__
#include <sys/ioctl.h>
#elif __MINGW32__ //MinGW (g++)
#include <windows.h>
#elif __CYGWIN__ //CygWin (g++)
#include <windows.h>
#endif
using namespace std;
//char l[12][8][10]={{"---------","| --- |","| | | |","| --- |","| | | |","| | | |","| | | |","---- ----"},{"--------|","| --- |","| | | |","| --- /","| --- |","| | | |","| --- |","--------/"},{"--------|","| |","| -----/","| |","| |","| -----|","| |","--------/"},{"--------|","| ---| |","| | | |","| | | |","| | | |","| | | |","| ---/ |","--------/"},{"---------","| |","| ------","| --|","| --/","| ------","| |","---------"},{"---------","| |","| ------","| |","| ====","| |","| |","----"},{"--------|","| |","| -----/","| |","| |=====","| | |","| | |","-----/ |"},{"--- ---","| | | |","| | | |","| ----- |","| ----- |","| | | |","| | | |","--- ---"},{"---------","|--- ---|"," | | "," | | "," | | "," | | ","|--- ---|","---------"},{"---------","|--- ---|"," | | "," | | "," | | "," | | ","/--- - ","|----/ "},{"--- ---","| | / /","| | / /","| / /","| | |","| | | |","| | | |","--- ---"},{"---- ","| | ","| | ","| | ","| | ","| | ","|-------|","|-------|"}};
string l[26][8]={{"---------","| --- |","| | | |","| --- |","| | | |","| | | |","| | | |","---- ----"},{"--------\\","| --- |","| | | |","| --- /","| --- \\","| | | |","| --- |","--------/"},{"--------\\","| |","| -----/","| | ","| | ","| -----\\","| |","--------/"},{"--------\\","| ---\\ |","| | | |","| | | |","| | | |","| | | |","| ---/ |","--------/"},{"---------","| |","| ------","| --\\ ","| --/ ","| ------","| |","---------"},{"---------","| |","| ------","| | ","| ==== ","| | ","| | ","---- "},{"--------\\","| |","| -----/","| | ","| \\=====","| | |","| | |","-----/ |"},{"--- ---","| | | |","| | | |","| ----- |","| ----- |","| | | |","| | | |","--- ---"},{"---------","|--- ---|"," | | "," | | "," | | "," | | ","|--- ---|","---------"},{"---------","|--- ---|"," | | "," | | "," | | "," | | ","/--- - ","|----/ "},{"--- ---","| | / / ","| | / / ","| / / ","| \\ \\ ","| | \\ \\ ","| | \\ \\ ","--- ---"},{"--- ","| | ","| | ","| | ","| | ","| | ","|--- ---|","\\-------|"},{"--- ---","| \\ / |","| |","| \\ / |","| | | |","| | | |","| | | |","---- ----"},{"--- ---","|\\\\ | |","| \\\\ | |","| |\\\\ | |","| | \\\\| |","| | \\\\ |","| | \\\\|","--- ---"},{"---------","| ----- |","| | | |","| | | |","| | | |","| | | |","| ----- |","---------"},{"---------","| ----- |","| | | |","| -----/ ","| | ","| | ","| | ","--- "},{"---------","| ----- |","| | | |","| | | |","| | | |","| =======","| ======|","---------"},{"---------","| ----- |","| | | |","| ----- /","| |\\ \\ ","| | \\ \\ ","| | \\ \\","--- ---"},{"---------","| | ","| | "," \\ --- \\ "," | |"," | |","|--- ---|","\\-------|"},{"---------","---| |---"," | | "," | | "," | | "," | | "," | | "," --- "},{"--- ---","| | | |","| | | |","| | | |","| | | |","| | | |","\\ ----- /"," ------- "},{"--- ---","| | | |","| | | |","| | | |","| | | |","\\ \\ / /"," \\ - / "," ----- "},{"-- --","|| ||","|| ||","|| ||","|| ||","\\\\ | //"," \\\\/ \\// "," - - "},{"-- --"," \\\\ // "," \\\\ // "," \\ / "," / \\ "," // \\\\ "," // \\\\ ","-- --"},{"--- ---","\\ \\ / /"," \\ \\ / / "," \\ / "," | | "," | | "," | | "," --- "},{"---------","-------/ "," // "," // "," // "," // "," /-------","---------"}};
void scrollstr(string);
void printstr(string,int); //spac takes space
void capitallize(string*);
int numspaces(string);
void clearscr(void);
void set_h_w(void); //Set terminal height & width
int terminal_height, terminal_width;
int main(){
clearscr();
string str;
set_h_w();
cout<<"Enter String (length<"<<int(terminal_width/10)<<") : ";
getline( cin , str);
cout<<'\n';
capitallize(&str);
set_h_w();
scrollstr(str);
return 0;
}
void set_h_w(){ //USE MORE ADVANCED
#ifdef __linux__
winsize w; //struct winsize
ioctl (STDOUT_FILENO, TIOCGWINSZ, &w);
terminal_height = w.ws_row;
terminal_width = w.ws_col;
#else
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo( GetStdHandle(STD_OUTPUT_HANDLE), &csbi );
terminal_height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
terminal_width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
#endif
}
void capitallize(string *s){
for(int i=0; i<(s->size()) ; i++)
(*s)[i] = toupper((*s)[i]);
}
void scrollstr(string s){
short space=0, length = 10*(s.size()) - 6*numspaces(s), tmp_width = terminal_width;
bool flag=true;
while(true){
set_h_w();
while ( terminal_width < length ){ //110 -
clearscr();
tmp_width = terminal_width;
cout<<"\nCan't Display in this Resolution!\nYou May Change Back!";
cout<<"Terminal Width ("<<terminal_width<<") is less than Required Width("<<length<<')'<<endl;
while( tmp_width == terminal_width ){ //to prevent it doing it thousand times
usleep(500000);
set_h_w();
}
}
printstr(s,space);
if (space >= terminal_width - length )
flag=false;
else if( space == 0 )
flag=true;
if(flag) space++;
else space--;
tmp_width = terminal_width;
usleep(70000); //arguments in microseconds
clearscr();
}
}
void printstr(string st,int spac){
int i,j,k;
for(i=0;i<8;i++){ //Prints the characters linewise (NOTE: Till now, it doesnt actually know... which character?... This is actually being managed by the 3rd for loop)
for(j=0;j<spac;j++) cout<<" "; //Animates the SCROLLING
for(k=0;st[k]!='\0';k++){
if(st[k]==' ') cout<<" ";
else cout<<l[(int)(st[k])-65][i];//Prints the lines of the given character (NOTE: the expression int()-65 is to actually relate the ASCII Value of entered value to the location in array)
cout<<" ";
}
cout<<'\n';
}
cout<<'\n';
}
int numspaces(string s){
short i=s.size(),j=0;
while(i--){
if(s[i]==' ') ++j;
}
return j;
}
void clearscr(){
for(int i=0 ; i<terminal_height; i++)
cout<<'\n';
}
IDEA BY OUR SIR
Programmer - Aditya Gupta (aka. Techy15)
Language - C++
NAMASTE !
*/
//Known Bug : It doesn't scroll if it the length of the bigger string matches the terminal width, for a second or so
/*LEARNT ThINGS :
* VIM : :%s/foo/bar/g finds and replaces ALL 'foo' with 'bar'
* A - 65
* a - 97
*Observation - Terminal in windowed mode has a heiht of 23 lines, width of 80 characters; and in full screen, has a height of 38 lines, and width of 169 characters [Useful for creating clrscr alternative with newlines] */
#include <iostream>
#include <string>
#include <unistd.h>
#ifdef _WIN32 //Macro defined by MSVC (Microsoft Visual C++) compiler (not g++)
#include <windows.h>
#elif __linux__
#include <sys/ioctl.h>
#elif __MINGW32__ //MinGW (g++)
#include <windows.h>
#elif __CYGWIN__ //CygWin (g++)
#include <windows.h>
#endif
using namespace std;
//char l[12][8][10]={{"---------","| --- |","| | | |","| --- |","| | | |","| | | |","| | | |","---- ----"},{"--------|","| --- |","| | | |","| --- /","| --- |","| | | |","| --- |","--------/"},{"--------|","| |","| -----/","| |","| |","| -----|","| |","--------/"},{"--------|","| ---| |","| | | |","| | | |","| | | |","| | | |","| ---/ |","--------/"},{"---------","| |","| ------","| --|","| --/","| ------","| |","---------"},{"---------","| |","| ------","| |","| ====","| |","| |","----"},{"--------|","| |","| -----/","| |","| |=====","| | |","| | |","-----/ |"},{"--- ---","| | | |","| | | |","| ----- |","| ----- |","| | | |","| | | |","--- ---"},{"---------","|--- ---|"," | | "," | | "," | | "," | | ","|--- ---|","---------"},{"---------","|--- ---|"," | | "," | | "," | | "," | | ","/--- - ","|----/ "},{"--- ---","| | / /","| | / /","| / /","| | |","| | | |","| | | |","--- ---"},{"---- ","| | ","| | ","| | ","| | ","| | ","|-------|","|-------|"}};
string l[26][8]={{"---------","| --- |","| | | |","| --- |","| | | |","| | | |","| | | |","---- ----"},{"--------\\","| --- |","| | | |","| --- /","| --- \\","| | | |","| --- |","--------/"},{"--------\\","| |","| -----/","| | ","| | ","| -----\\","| |","--------/"},{"--------\\","| ---\\ |","| | | |","| | | |","| | | |","| | | |","| ---/ |","--------/"},{"---------","| |","| ------","| --\\ ","| --/ ","| ------","| |","---------"},{"---------","| |","| ------","| | ","| ==== ","| | ","| | ","---- "},{"--------\\","| |","| -----/","| | ","| \\=====","| | |","| | |","-----/ |"},{"--- ---","| | | |","| | | |","| ----- |","| ----- |","| | | |","| | | |","--- ---"},{"---------","|--- ---|"," | | "," | | "," | | "," | | ","|--- ---|","---------"},{"---------","|--- ---|"," | | "," | | "," | | "," | | ","/--- - ","|----/ "},{"--- ---","| | / / ","| | / / ","| / / ","| \\ \\ ","| | \\ \\ ","| | \\ \\ ","--- ---"},{"--- ","| | ","| | ","| | ","| | ","| | ","|--- ---|","\\-------|"},{"--- ---","| \\ / |","| |","| \\ / |","| | | |","| | | |","| | | |","---- ----"},{"--- ---","|\\\\ | |","| \\\\ | |","| |\\\\ | |","| | \\\\| |","| | \\\\ |","| | \\\\|","--- ---"},{"---------","| ----- |","| | | |","| | | |","| | | |","| | | |","| ----- |","---------"},{"---------","| ----- |","| | | |","| -----/ ","| | ","| | ","| | ","--- "},{"---------","| ----- |","| | | |","| | | |","| | | |","| =======","| ======|","---------"},{"---------","| ----- |","| | | |","| ----- /","| |\\ \\ ","| | \\ \\ ","| | \\ \\","--- ---"},{"---------","| | ","| | "," \\ --- \\ "," | |"," | |","|--- ---|","\\-------|"},{"---------","---| |---"," | | "," | | "," | | "," | | "," | | "," --- "},{"--- ---","| | | |","| | | |","| | | |","| | | |","| | | |","\\ ----- /"," ------- "},{"--- ---","| | | |","| | | |","| | | |","| | | |","\\ \\ / /"," \\ - / "," ----- "},{"-- --","|| ||","|| ||","|| ||","|| ||","\\\\ | //"," \\\\/ \\// "," - - "},{"-- --"," \\\\ // "," \\\\ // "," \\ / "," / \\ "," // \\\\ "," // \\\\ ","-- --"},{"--- ---","\\ \\ / /"," \\ \\ / / "," \\ / "," | | "," | | "," | | "," --- "},{"---------","-------/ "," // "," // "," // "," // "," /-------","---------"}};
void scrollstr(string);
void printstr(string,int); //spac takes space
void capitallize(string*);
int numspaces(string);
void clearscr(void);
void set_h_w(void); //Set terminal height & width
int terminal_height, terminal_width;
int main(){
clearscr();
string str;
set_h_w();
cout<<"Enter String (length<"<<int(terminal_width/10)<<") : ";
getline( cin , str);
cout<<'\n';
capitallize(&str);
set_h_w();
scrollstr(str);
return 0;
}
void set_h_w(){ //USE MORE ADVANCED
#ifdef __linux__
winsize w; //struct winsize
ioctl (STDOUT_FILENO, TIOCGWINSZ, &w);
terminal_height = w.ws_row;
terminal_width = w.ws_col;
#else
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo( GetStdHandle(STD_OUTPUT_HANDLE), &csbi );
terminal_height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
terminal_width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
#endif
}
void capitallize(string *s){
for(int i=0; i<(s->size()) ; i++)
(*s)[i] = toupper((*s)[i]);
}
void scrollstr(string s){
short space=0, length = 10*(s.size()) - 6*numspaces(s), tmp_width = terminal_width;
bool flag=true;
while(true){
set_h_w();
while ( terminal_width < length ){ //110 -
clearscr();
tmp_width = terminal_width;
cout<<"\nCan't Display in this Resolution!\nYou May Change Back!";
cout<<"Terminal Width ("<<terminal_width<<") is less than Required Width("<<length<<')'<<endl;
while( tmp_width == terminal_width ){ //to prevent it doing it thousand times
usleep(500000);
set_h_w();
}
}
printstr(s,space);
if (space >= terminal_width - length )
flag=false;
else if( space == 0 )
flag=true;
if(flag) space++;
else space--;
tmp_width = terminal_width;
usleep(70000); //arguments in microseconds
clearscr();
}
}
void printstr(string st,int spac){
int i,j,k;
for(i=0;i<8;i++){ //Prints the characters linewise (NOTE: Till now, it doesnt actually know... which character?... This is actually being managed by the 3rd for loop)
for(j=0;j<spac;j++) cout<<" "; //Animates the SCROLLING
for(k=0;st[k]!='\0';k++){
if(st[k]==' ') cout<<" ";
else cout<<l[(int)(st[k])-65][i];//Prints the lines of the given character (NOTE: the expression int()-65 is to actually relate the ASCII Value of entered value to the location in array)
cout<<" ";
}
cout<<'\n';
}
cout<<'\n';
}
int numspaces(string s){
short i=s.size(),j=0;
while(i--){
if(s[i]==' ') ++j;
}
return j;
}
void clearscr(){
for(int i=0 ; i<terminal_height; i++)
cout<<'\n';
}
Comments
Post a Comment
You are free to leave any kind of suggestion, or improvement. It doesn't require you to sign in either.