-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_mountain_gen.rb
More file actions
48 lines (43 loc) · 941 Bytes
/
basic_mountain_gen.rb
File metadata and controls
48 lines (43 loc) · 941 Bytes
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
class Line
attr_reader :from, :to
def initialize(from, to)
@from = from
@to = to
end
end
def setup
size(600, 600)
@r = height/2
from_y = random(height/2) + height/2
to_y = random(height/2) + height/2
@lines = [Line.new(PVector.new(0, from_y), PVector.new(width, to_y))]
end
def draw
background(110, 140, 220)
fill(75, 110, 10)
begin_shape
vertex(0, height)
@lines.each do |line|
from = line.from
to = line.to
vertex(from.x, from.y)
vertex(to.x, to.y)
end
vertex(width, height)
end_shape(CLOSE)
end
def mouse_pressed
generate if @r > 1
end
def generate
new_lines = []
@lines.each do |line|
mid_y = ((line.from.y + line.to.y) / 2) + random(-@r, @r/3)
mid_x = (line.from.x + line.to.x) / 2
mid_point = PVector.new(mid_x, mid_y)
new_lines << Line.new(line.from, mid_point)
new_lines << Line.new(mid_point, line.to)
end
@lines = new_lines
@r /= 1.8
end