summaryrefslogtreecommitdiffhomepage
path: root/contrib/luacurses/test/rain.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-08-31 11:16:52 +0000
committerSteven Barth <steven@midlink.org>2008-08-31 11:16:52 +0000
commitdf52b711a78dbe8808628ae873acc1f3edefb1cf (patch)
tree00b4c145e7ab0501a6de277478b659d51e50fc92 /contrib/luacurses/test/rain.lua
parent36c76090638e80d1cb9ad2dd060aae65976f24c8 (diff)
Reorganise luacurses
Diffstat (limited to 'contrib/luacurses/test/rain.lua')
-rw-r--r--contrib/luacurses/test/rain.lua89
1 files changed, 89 insertions, 0 deletions
diff --git a/contrib/luacurses/test/rain.lua b/contrib/luacurses/test/rain.lua
new file mode 100644
index 0000000000..35e4691021
--- /dev/null
+++ b/contrib/luacurses/test/rain.lua
@@ -0,0 +1,89 @@
+
+require("curses");
+
+curses.initscr();
+curses.nl();
+curses.noecho();
+
+
+if (curses.has_colors()) then
+ curses.start_color();
+ curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK);
+ curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK);
+end
+
+curses.curs_set(0);
+curses.timeout(0);
+
+math.randomseed(os.time());
+
+lines = curses.LINES();
+cols = curses.COLS();
+
+xpos = {};
+ypos = {};
+r = lines - 4;
+c = cols - 4;
+for i = 0, 4 do
+ xpos[i] = c * math.random() + 2;
+ ypos[i] = r * math.random() + 2;
+end
+
+function dec(i, max)
+ if (curses.has_colors()) then
+ local z = 3 * math.random();
+ local c = curses.COLOR_PAIR(z);
+ curses.attrset(c);
+ if (math.floor(z) > 0) then
+ curses.attron(curses.A_BOLD);
+ end
+ end
+
+ if (i > 0) then return i - 1;
+ else return max;
+ end
+end
+
+i = 0;
+while(true) do
+ x = c * math.random() + 2;
+ y = r * math.random() + 2;
+
+ curses.mvaddstr(y, x, ".");
+
+ curses.mvaddstr(ypos[i], xpos[i], "o");
+
+ i = dec(i, 4);
+ curses.mvaddstr(ypos[i], xpos[i], "O");
+
+ i = dec(i, 4);
+ curses.mvaddstr(ypos[i] - 1, xpos[i], "-");
+ curses.mvaddstr(ypos[i], xpos[i] - 1, "|.|");
+ curses.mvaddstr(ypos[i] + 1, xpos[i], "-");
+
+ i = dec(i, 4);
+ curses.mvaddstr(ypos[i] - 2, xpos[i], "-");
+ curses.mvaddstr(ypos[i] - 1, xpos[i] - 1, "/ \\");
+ curses.mvaddstr(ypos[i], xpos[i] - 2, "| O |");
+ curses.mvaddstr(ypos[i] + 1, xpos[i] - 1, "\\ /");
+ curses.mvaddstr(ypos[i] + 2, xpos[i], "-");
+
+ i = dec(i, 4);
+ curses.mvaddstr(ypos[i] - 2, xpos[i], " ");
+ curses.mvaddstr(ypos[i] - 1, xpos[i] - 1, " ");
+ curses.mvaddstr(ypos[i], xpos[i] - 2, " ");
+ curses.mvaddstr(ypos[i] + 1, xpos[i] - 1, " ");
+ curses.mvaddstr(ypos[i] + 2, xpos[i], " ");
+
+
+ xpos[i] = x;
+ ypos[i] = y;
+
+ local ch = curses.getch();
+ if (ch == string.byte('q', 1)) or (ch == string.byte('Q', 1)) then break; end
+ curses.refresh();
+ curses.napms(50);
+end
+
+curses.endwin();
+