64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/party.rb', line 64
def self.start(written_words, silent, farewell, stuff_to_say)
interrupted = false
cols = (%x( tput cols )).to_i
lines = (%x( tput lines )).to_i
rec_width = 54
rec_height = 20
rec_left_x = cols/2-rec_width/2
rec_left_y = lines/2-rec_height/2
init_screen
start_color
init_pair(0,COLOR_BLACK, COLOR_YELLOW)
init_pair(1,COLOR_WHITE, COLOR_BLUE)
init_pair(2,COLOR_BLACK,COLOR_RED)
init_pair(3,COLOR_RED,COLOR_BLACK)
init_pair(4,COLOR_BLACK,COLOR_WHITE)
init_pair(5,COLOR_BLACK,COLOR_MAGENTA)
sem = Mutex.new
talking = Mutex.new
rect = Thread.new {
i = 1
delta = 1
while !interrupted
sleep_time = (1.0/i.to_f)*1.3
written_words.each.with_index do |word, w_i|
sem.synchronize {
if w_i % 2 == 0
draw_rect(rec_left_x,rec_left_y,rec_width,rec_height, color_pair((i+3)%5), color_pair((i+3)%5), word)
else
draw_rect(rec_left_x,rec_left_y,rec_width,rec_height, color_pair(1), color_pair(1), word)
end
}
sleep(sleep_time)
end
i+=delta
if i == 10
delta = -1
end
if i == 1
delta = 1
end
end
}
saying = Thread.new {
i = 0
words = stuff_to_say.cycle
while !silent
talking.synchronize{
system "say", words.next
}
i+=1
end
}
bg_lines = Thread.new {
color = 0
while !interrupted
sleep(1)
i=0
while i < lines
sem.synchronize {
draw_line(i, lambda { |col, line| rec_left_y <= line && rec_left_y+rec_height >= line && rec_left_x <= col && rec_left_x+rec_width > col})
refresh
}
sleep(0.04)
i+=1
end
sleep(0.5)
for i in 0..lines
for j in 0..cols
sem.synchronize {
unless rec_left_y <= i && rec_left_y+rec_height >= i && rec_left_x <= j && rec_left_x+rec_width > j
setpos(i,j)
attron(color_pair((color%3)+1))
addstr(" ")
refresh
end
}
sleep(0.0004)
end
end
color += 1
end
}
trap("INT") {
rect.kill()
bg_lines.kill()
saying.kill()
}
bg_lines.join
rect.join
saying.join
close_screen
if (!silent)
talking.synchronize {
if farewell
system "say", farewell
end
}
end
end
|