contrib: add WoL application to menuconfig
[project/luci.git] / contrib / luacurses / test / rain.lua
1
2 require("curses");
3
4 curses.initscr();
5 curses.nl();
6 curses.noecho();
7
8
9 if (curses.has_colors()) then
10 curses.start_color();
11 curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK);
12 curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK);
13 end
14
15 curses.curs_set(0);
16 curses.timeout(0);
17
18 math.randomseed(os.time());
19
20 lines = curses.LINES();
21 cols = curses.COLS();
22
23 xpos = {};
24 ypos = {};
25 r = lines - 4;
26 c = cols - 4;
27 for i = 0, 4 do
28 xpos[i] = c * math.random() + 2;
29 ypos[i] = r * math.random() + 2;
30 end
31
32 function dec(i, max)
33 if (curses.has_colors()) then
34 local z = 3 * math.random();
35 local c = curses.COLOR_PAIR(z);
36 curses.attrset(c);
37 if (math.floor(z) > 0) then
38 curses.attron(curses.A_BOLD);
39 end
40 end
41
42 if (i > 0) then return i - 1;
43 else return max;
44 end
45 end
46
47 i = 0;
48 while(true) do
49 x = c * math.random() + 2;
50 y = r * math.random() + 2;
51
52 curses.mvaddstr(y, x, ".");
53
54 curses.mvaddstr(ypos[i], xpos[i], "o");
55
56 i = dec(i, 4);
57 curses.mvaddstr(ypos[i], xpos[i], "O");
58
59 i = dec(i, 4);
60 curses.mvaddstr(ypos[i] - 1, xpos[i], "-");
61 curses.mvaddstr(ypos[i], xpos[i] - 1, "|.|");
62 curses.mvaddstr(ypos[i] + 1, xpos[i], "-");
63
64 i = dec(i, 4);
65 curses.mvaddstr(ypos[i] - 2, xpos[i], "-");
66 curses.mvaddstr(ypos[i] - 1, xpos[i] - 1, "/ \\");
67 curses.mvaddstr(ypos[i], xpos[i] - 2, "| O |");
68 curses.mvaddstr(ypos[i] + 1, xpos[i] - 1, "\\ /");
69 curses.mvaddstr(ypos[i] + 2, xpos[i], "-");
70
71 i = dec(i, 4);
72 curses.mvaddstr(ypos[i] - 2, xpos[i], " ");
73 curses.mvaddstr(ypos[i] - 1, xpos[i] - 1, " ");
74 curses.mvaddstr(ypos[i], xpos[i] - 2, " ");
75 curses.mvaddstr(ypos[i] + 1, xpos[i] - 1, " ");
76 curses.mvaddstr(ypos[i] + 2, xpos[i], " ");
77
78
79 xpos[i] = x;
80 ypos[i] = y;
81
82 local ch = curses.getch();
83 if (ch == string.byte('q', 1)) or (ch == string.byte('Q', 1)) then break; end
84 curses.refresh();
85 curses.napms(50);
86 end
87
88 curses.endwin();
89