Class: Party

Inherits:
Object
  • Object
show all
Defined in:
lib/party.rb

Class Method Summary collapse

Class Method Details

.draw_line(lineNr, should_not_draw) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/party.rb', line 176

def self.draw_line(lineNr, should_not_draw)
  setpos(lineNr, 0)
  for i in 0..cols-1
    if (i/3)%3 == 0
      attron(color_pair(5))
    elsif (i/3)%3 == 1
      attron(color_pair(1))
    elsif (i/3)%3 == 2
      attron(color_pair(2))
    end
    unless should_not_draw.call(i, lineNr) 
      setpos(lineNr, i)
      addstr(" ")
    end
  end
end

.draw_lines_to(lineNr) ⇒ Object



193
194
195
196
197
# File 'lib/party.rb', line 193

def self.draw_lines_to(lineNr)
  for line in 0..lineNr
    draw_line(line)
  end
end

.draw_rect(leftX, leftY, l, h, rect_color, text_color, string) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/party.rb', line 148

def self.draw_rect(leftX, leftY, l, h, rect_color, text_color, string)
  setpos(leftY, leftX)
  attron(rect_color)
  addstr(spaceStr(l))
  for o in 1..(h-1) 
    setpos(leftY+o, leftX+l-2)
    attron(rect_color)
    addstr("  ")
  end
  for o in 1..(h-1) 
    setpos(leftY+o, leftX)
    addstr("  ")
  end
  setpos(leftY+h,leftX)
  attron(rect_color)
  addstr(spaceStr(l))
  attron(text_color)

  for j in 0..h-2
    setpos(leftY+1+j, leftX+2)
    for o in 1..(l-4)/string.length
      addstr(string)
    end
  end
  refresh
end

.spaceStr(length) ⇒ Object



199
200
201
202
203
204
205
# File 'lib/party.rb', line 199

def self.spaceStr(length)
  s = ""
  for _ in 1..length
    s += " "
  end
  return s
end

.start(silent, farewell, stuff_to_say) ⇒ Object



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
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
# File 'lib/party.rb', line 48

def self.start(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
      sem.synchronize {
        draw_rect(rec_left_x,rec_left_y,rec_width,rec_height, color_pair((i+3)%5), color_pair((i+3)%5), "PARTY")
      }
      sleep(sleep_time)
      sem.synchronize {
        draw_rect(rec_left_x,rec_left_y,rec_width,rec_height, color_pair(1), color_pair(1), "WOHOO")
      }
      sleep(sleep_time)
      i+=delta
      if i == 10 
        delta = -1
      end
      if i == 1
        delta = 1
      end
    end
  }

  saying = Thread.new {
    i = 0
    while !silent
      talking.synchronize{
        %x[say "#{stuff_to_say[i % (stuff_to_say.length) ]}" ];
      }
      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 
        %x(say #{farewell} );
      end
    }
  end
end