-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmatrix.c
84 lines (77 loc) · 1.89 KB
/
rmatrix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <curses.h>
#include <stdlib.h>
/* adjustment factors for other machines */
#define THICKNESS .15
#define MAXDELAY 100000
#define MINDELAY 1000
#define PLOT .5
int main() {
/* variables */
int maxy, maxx;
int x;
char inp;
/* init options */
srand(time(NULL));
srand48(time(NULL));
initscr();
start_color();
use_default_colors();
init_pair(1,COLOR_GREEN,-1);
init_pair(2,COLOR_WHITE,-1);
color_set(1,NULL);
noecho();
nodelay(stdscr,true);
curs_set(0);
/* declare matrix */
getmaxyx(stdscr, maxy, maxx);
unsigned int lines=(unsigned int)(drand48()*THICKNESS*(maxx*maxy)+1);
unsigned int delay=(unsigned int)((unsigned int)(MAXDELAY*(lines/(THICKNESS*(maxx*maxy))))+MINDELAY);
signed long int matrix[lines][5];
/* functions */
unsigned char randchr(){
return rand()%95+32;
}
void reinit(){
matrix[x][1] = -((unsigned long int)rand()%maxy*2);
matrix[x][2] = -((unsigned long int)rand()%maxy*2);
if(matrix[x][2]>=matrix[x][1]) matrix[x][2]-=(unsigned int)(rand()%maxy);
matrix[x][3]=(unsigned int)rand()%maxx;
matrix[x][0]=rand();
}
/* init matrix */
for(x=0;x<lines;x++){
reinit();
}
/* loop */
while(1){
getmaxyx(stdscr, maxy, maxx);
inp=getch();
if(inp=='q'||inp=='Q'){clear();refresh();endwin();exit(0);} /* quit */
for(x=0;x<lines;x++){
attron(COLOR_PAIR(1));
if(matrix[x][1]>=0){
mvprintw(matrix[x][1],matrix[x][3],"%c",matrix[x][4]);
}
if(matrix[x][0]>rand()){
matrix[x][1]++;
matrix[x][4]=randchr();
}
/* random plot */
if(rand()>(PLOT*RAND_MAX)){
move((unsigned int)rand()%maxy,(unsigned int)rand()%maxx);
if((unsigned char)(A_CHARTEXT&inch())!=' ') printw("%c",randchr());
}
attron(COLOR_PAIR(2));
if(matrix[x][1]>=0) mvprintw(matrix[x][1],matrix[x][3],"%c",matrix[x][4]);
if(matrix[x][0]>=rand()){
matrix[x][2]++;
if(matrix[x][2]>=matrix[x][1]) matrix[x][2]=matrix[x][1]-1;
if(matrix[x][2]>maxy)reinit();
}
if(matrix[x][2]>=0) mvprintw(matrix[x][2],matrix[x][3]," ");
}
refresh();
usleep(delay);
}
}