-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.rb
59 lines (50 loc) · 854 Bytes
/
rectangle.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
require File.join('.', 'drawing')
class Rectangle < Drawing
def initialize
@origin = 0
@column = @origin
@line = @origin
@width = 20
@height = 10
end
def reset
@origin = rand(20) + 1 # y'know, in case of zero.
@column = @origin
@line = @origin
@width = 20 + @origin
@height = 10 + @origin
write(0, 0, "Origin: #{@origin}")
refresh
end
def check_reset
if @line > @height
wait = 0.5
sleep wait
clear
reset
sleep wait
end
end
def set_values
@column += 1
if @column % @width == 0
@line += 1
@column = @origin
end
end
def draw
check_reset
if @line == @origin || @line == @height
write(@line, @column, "+")
else
if @column == @origin || @column == @width - 1
write(@line, @column, "+")
end
end
set_values
end
def sleep_time
0.005
end
end
Rectangle.new.run