fixed/unified formatting

This commit is contained in:
Solomon W. 2020-03-28 15:28:58 -04:00
parent d94bcdf287
commit 8ae935be78
2 changed files with 73 additions and 90 deletions

View File

@ -1,2 +1,5 @@
[Buildset] [Buildset]
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x0c\x00m\x00a\x00t\x00r\x00i\x00x) BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x0c\x00m\x00a\x00t\x00r\x00i\x00x)
[Project]
VersionControlSupport=kdevgit

View File

@ -17,32 +17,30 @@
#endif #endif
int main(int argc, char **argv) { int main(int argc, char **argv) {
WINDOW term = *initscr(); WINDOW term = *initscr();
start_color(); start_color();
init_pair(1,COLOR_GREEN,COLOR_BLACK); init_pair(1,COLOR_GREEN,COLOR_BLACK);
attron(COLOR_PAIR(1)); attron(COLOR_PAIR(1));
noecho(); noecho();
if(nodelay(&term,TRUE)==ERR) { if(nodelay(&term,TRUE)==ERR) {
puts("Error could not enter no-delay mode"); puts("Error could not enter no-delay mode");
return ERR; return ERR;
} }
int time; int time;
if(argc >= 3) { if(argc >= 3) {
time=atoi(argv[2]); time=atoi(argv[2]);
} else { } else {
time=20; time=20;
} }
timeout(time); timeout(time);
int maxX = COLS; int maxX = COLS;
int maxY = LINES; int maxY = LINES;
int initTailLen;
int initTailLen; if(argc >= 2) {
if(argc >= 2) {
initTailLen=atoi(argv[1]); initTailLen=atoi(argv[1]);
} else { } else {
initTailLen=10; initTailLen=10;
} }
int tailLen[maxX]; int tailLen[maxX];
for(int i=0; i<maxX; i++) { for(int i=0; i<maxX; i++) {
@ -55,83 +53,65 @@ int main(int argc, char **argv) {
} }
} }
} }
int cascade[maxX];
int cascade[maxX]; int tail[maxX];
int tail[maxX];
int jmpTail[maxX]; int jmpTail[maxX];
for(int i=0; i<maxX; i++) for(int i=0; i<maxX; i++)
cascade[i]=ERR; cascade[i]=ERR;
int pause = 0; int pause = 0;
int dir = DOWN; int dir = DOWN;
int limit = maxY; int limit = maxY;
int startPos = 0; int startPos = 0;
int get = getch(); int get = getch();
while(get!='q') { while(get!='q') {
if(get=='s') { if(get=='s') {
pause=TRUE; pause=TRUE;
} }
int xPos = rand()%maxX;//get random x position for the stream int xPos = rand()%maxX;//get random x position for the stream
if(cascade[xPos]==ERR) {//make sure the stream is set to active if(cascade[xPos]==ERR) {//make sure the stream is set to active
cascade[xPos]=startPos; cascade[xPos]=startPos;
} }
//---------swich to weird format----------- for(int i=0; i<maxX; i++) {//move the streams up/down
for(int i=0; i<maxX; i++) if(!pause) {
{//move the streams up/down if(cascade[i]!=ERR) {
if(!pause)
{
if(cascade[i]!=ERR)
{
if(dir==DOWN) { if(dir==DOWN) {
tail[i] = cascade[i]-tailLen[i]; tail[i] = cascade[i]-tailLen[i];
} else { } else {
tail[i] = cascade[i]+tailLen[i]; tail[i] = cascade[i]+tailLen[i];
} }
if(cascade[i]==limit) if(cascade[i]==limit) {//check if the position is at the bottom of the screen
{//check if the position is at the bottom of the screen cascade[i]=ERR;//set the position to ERR if it is at the bottom
cascade[i]=ERR;//set the position to ERR if it is at the bottom } else {
} if(rand()%10==1) {//check if the stream will jump
else if(!(jmpTail[i]<=maxY)) {
{ if(dir==DOWN) {
if(rand()%10==1)
{//check if the stream will jump
if(!(jmpTail[i]<=maxY))
{
if(dir==DOWN)
{
cascade[i]=cascade[i]+rand()%8; cascade[i]=cascade[i]+rand()%8;
jmpTail[i]=cascade[i]-tailLen[i]; jmpTail[i]=cascade[i]-tailLen[i];
} } else {
else
{
cascade[i]=cascade[i]-rand()%8; cascade[i]=cascade[i]-rand()%8;
jmpTail[i]=cascade[i]+tailLen[i]; jmpTail[i]=cascade[i]+tailLen[i];
} }
} }
} } else {
else if(dir==DOWN) {
{
if(dir==DOWN)
{
cascade[i]++;//increase the position cascade[i]++;//increase the position
} } else {
else
{
cascade[i]--; cascade[i]--;
} }
} }
} }
} }
} }
//-------Back to normal format------- //-------Back to normal format-------
if(tail[i]!=limit) {//keep iterating the tail intill it is at the limit if(tail[i]!=limit) {//keep iterating the tail intill it is at the limit
if(dir==DOWN) { if(dir==DOWN) {
tail[i]++; tail[i]++;
} else { } else {
tail[i]--; tail[i]--;
} }
} }
if(jmpTail[i]==maxY || jmpTail==0) { if(jmpTail[i]==maxY || jmpTail==0) {
jmpTail[i]=OK; jmpTail[i]=OK;
} else { } else {
@ -142,41 +122,41 @@ int main(int argc, char **argv) {
} }
} }
mvaddch(jmpTail[i],i,' '); mvaddch(jmpTail[i],i,' ');
mvaddch(tail[i],i,' '); mvaddch(tail[i],i,' ');
mvaddch(cascade[i],i,(rand()%60)+65); mvaddch(cascade[i],i,(rand()%60)+65);
} }
refresh(); refresh();
if(!pause) { if(!pause) {
timeout(time); timeout(time);
} else { } else {
timeout(-1); timeout(-1);
get=getch(); get=getch();
switch (get) { switch (get) {
case 's': case 's':
pause=!pause; pause=!pause;
break; break;
case 'r': case 'r':
pause=FALSE; pause=FALSE;
if(dir==DOWN) { if(dir==DOWN) {
dir=UP; dir=UP;
limit=0; limit=0;
startPos=maxY; startPos=maxY;
} else { } else {
dir=DOWN; dir=DOWN;
limit=maxY; limit=maxY;
startPos=0; startPos=0;
} }
break;
case 'q':
get='q';
break; break;
case 'q':
get='q';
break;
} }
timeout(time); timeout(time);
} }
if(get!='q') { if(get!='q') {
get=getch(); get=getch();
} }
} }
endwin(); endwin();
return 0; return 0;
} }