-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshapes.rb
More file actions
57 lines (53 loc) · 1.61 KB
/
shapes.rb
File metadata and controls
57 lines (53 loc) · 1.61 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
53
54
55
56
57
#
# Ruby For Kids Projects 4: Shapes
# Programmed By: Chris Haupt
# Experiment with drawing ASCII art shapes using code
#
puts "Welcome to Shapes"
print "How big do you want your shape? "
shape_size = gets
shape_size = shape_size.chomp
print "Outside letter: "
outside_letter = gets
outside_letter = outside_letter.chomp
print "Inside letter: "
inside_letter = gets
inside_letter = inside_letter.chomp
puts "About to draw a shape #{shape_size} big"
puts "using #{outside_letter} for the edge"
puts "and #{inside_letter} for the inside"
height = shape_size.to_i
width = shape_size.to_i
def rectangle(height, width, outside_letter, inside_letter)
# Rectangle code goes here
1.upto(height) do |row|
# Drawing code goes here
if row == 1
puts outside_letter * width
elsif row == height
puts outside_letter * width
else
middle = inside_letter * (width - 2)
puts "#{outside_letter}#{middle}#{outside_letter}"
end
end
end
# Above here is the end of the rectangle method
def triangle(height, outside_letter, inside_letter)
# Code for the triangle will go here
1.upto(height) do |row|
# Drawing code goes here
print ' ' * (height - row)
if row == 1
puts "#{outside_letter * 2}"
elsif row == height
puts outside_letter * height * 2
else
middle = inside_letter * (row - 2)
print "#{outside_letter}#{middle}#{inside_letter}"
puts "#{inside_letter}#{middle}#{outside_letter}"
end
end
end
triangle(height, outside_letter, inside_letter)
rectangle(height, width * 2, outside_letter, inside_letter)