DEFINITIONS
This source file includes following functions.
1 #!/usr/local/bin/ruby
2 # rain for a curses test
3
4 require "curses"
5 include Curses
6
7 def onsig(sig)
8 close_screen
9 exit sig
10 end
11
12 def ranf
13 rand(32767).to_f / 32767
14 end
15
16 # main #
17 for i in 1 .. 15 # SIGHUP .. SIGTERM
18 if trap(i, "SIG_IGN") != 0 then # 0 for SIG_IGN
19 trap(i) {|sig| onsig(sig) }
20 end
21 end
22
23 init_screen
24 nl
25 noecho
26 srand
27
28 xpos = {}
29 ypos = {}
30 r = lines - 4
31 c = cols - 4
32 for i in 0 .. 4
33 xpos[i] = (c * ranf).to_i + 2
34 ypos[i] = (r * ranf).to_i + 2
35 end
36
37 i = 0
38 while TRUE
39 x = (c * ranf).to_i + 2
40 y = (r * ranf).to_i + 2
41
42
43 setpos(y, x); addstr(".")
44
45 setpos(ypos[i], xpos[i]); addstr("o")
46
47 i = if i == 0 then 4 else i - 1 end
48 setpos(ypos[i], xpos[i]); addstr("O")
49
50 i = if i == 0 then 4 else i - 1 end
51 setpos(ypos[i] - 1, xpos[i]); addstr("-")
52 setpos(ypos[i], xpos[i] - 1); addstr("|.|")
53 setpos(ypos[i] + 1, xpos[i]); addstr("-")
54
55 i = if i == 0 then 4 else i - 1 end
56 setpos(ypos[i] - 2, xpos[i]); addstr("-")
57 setpos(ypos[i] - 1, xpos[i] - 1); addstr("/ \\")
58 setpos(ypos[i], xpos[i] - 2); addstr("| O |")
59 setpos(ypos[i] + 1, xpos[i] - 1); addstr("\\ /")
60 setpos(ypos[i] + 2, xpos[i]); addstr("-")
61
62 i = if i == 0 then 4 else i - 1 end
63 setpos(ypos[i] - 2, xpos[i]); addstr(" ")
64 setpos(ypos[i] - 1, xpos[i] - 1); addstr(" ")
65 setpos(ypos[i], xpos[i] - 2); addstr(" ")
66 setpos(ypos[i] + 1, xpos[i] - 1); addstr(" ")
67 setpos(ypos[i] + 2, xpos[i]); addstr(" ")
68
69
70 xpos[i] = x
71 ypos[i] = y
72 refresh
73 sleep(0.5)
74 end
75
76 # end of main