-
Notifications
You must be signed in to change notification settings - Fork 0
/
filler.rb
80 lines (68 loc) · 1.33 KB
/
filler.rb
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
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
class Filler
attr_accessor :life, :desk
def initialize(life)
@life = life
@desk = []
end
def fill
case life.content
when "Random"
fill_random
when "Random symmetry"
fill_symmetry
when "Empty"
fill_empty
when "Small random pattern"
fill_small_pattern
when "Big random pattern"
fill_big_pattern
end
@desk
end
def fill_random
(0...life.y).each do |i|
@desk << []
(0...life.x).each do |j|
@desk[i] << random_cell
end
end
end
def fill_symmetry
(0...life.y).each do |i|
@desk << []
(0...life.x/2).each do |j|
@desk[i] << random_cell
end
@desk[i] += @desk[i].reverse
end
end
def fill_small_pattern
(0...7).each do |i|
@desk[i] = pattern_line(7) * (life.x/7)
end
(7...life.y).each do |i|
@desk << @desk[i%7]
end
end
def fill_big_pattern
(0...14).each do |i|
@desk[i] = pattern_line(14) * (life.x/14)
end
(14...life.y).each do |i|
@desk << @desk[i%14]
end
end
def pattern_line(lenght)
line = []
lenght.times do
line << random_cell
end
line
end
def random_cell
Сellule.new("random")
end
def fill_empty
@desk = Array.new( life.y, Array.new(life.x, Сellule.new(0)) )
end
end