public
Description: particle attractor, multiverse, ruby game programming tutorial & 2d engine
Homepage: http://geeq.at
Clone URL: git://github.com/oneup/puituniverse.git
oneup (author)
Sun Jul 05 18:26:58 -0700 2009
commit  08023a13f8f9d7f3853b8c8165cdec5bda17904d
tree    81e330966097165f50a8fd35dfe79f4f53df7683
parent  4370f0bdb4aa857e625c818a5fb788baa808040f
puituniverse / kyoto_reconstruction.rb
100644 52 lines (45 sloc) 0.717 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Class
  def direct_descendents
    result = []
    ObjectSpace.each_object( Class ) do |c|
      result << c if c.superclass == self
    end
    return result
  end
end
 
module NamedRandom
  def randomly_between(range)
    range.begin + rand*(range.end-range.begin)
  end
  
  def with_probability(p)
    yield if (rand <= p)
  end
end
 
module NamedFractions
  def half
    0.5
  end
  
  def third
    1.0/3
  end
  
  def quarter
    0.25
  end
end
 
module Timer
  include NamedFractions
  def after(duration)
    Thread.new do
      sleep duration.to_f
      yield
    end
  end
  
  def every(duration)
    Thread.new do
      while true
        yield
        sleep duration.to_f
      end
    end
  end
end