Skip to content

Instantly share code, notes, and snippets.

@ryanveroniwooff
Last active October 8, 2017 10:56
Show Gist options
  • Save ryanveroniwooff/802b69dc07f626ab9f1fa5affbb1b90a to your computer and use it in GitHub Desktop.
Save ryanveroniwooff/802b69dc07f626ab9f1fa5affbb1b90a to your computer and use it in GitHub Desktop.
Download this file and run in your console for a merry christmas message!
# This Program creates and outputs a formatted and colorized chirstmas tree with "Merry Christmas!" below it
# This code handles colorization of console output
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
end
def green
colorize(32)
end
def yellow
colorize(33)
end
def blue
colorize(34)
end
def pink
colorize(35)
end
def light_blue
colorize(36)
end
end
# This creates a pyramid based on how many lines you wish to see
# MODIFICATION MADE TO FORMAT XMAS TREE!
# - REMOVE '(space * 6)' FROM LINE 44 TO RETURN TO ORIGINAL FORMATTING
def make_stars(size)
star = '*'
space = ' '
arr = []
for i in 1..size
arr << [i == 1 ? star : star * ((i * 2) - 2)]
end
arr = arr.map { |e| e.join().split('').join(' ') }
length = arr.last.length
arr = arr.each_with_index.map { |e,i| (space * 6) + (space * ((length - arr[i].size) / 2)) + e + (space * ((length - arr[i].size) / 2)) }
arr
end
# This is all ouput to create the tree
puts ("\n" * 2)
puts make_stars(6)[0].yellow
puts make_stars(6)[1]
pink = make_stars(6)[2].split('').each_with_index.map { |x,i|
if x == '*'
if i == 14 || i == 16
x.light_blue
else
x
end
else
x
end
}.join
puts pink
pink = make_stars(6)[3].split('').each_with_index.map { |x,i|
if x == '*'
if i == 12 || i == 18
x.pink
else
x
end
else
x
end
}.join
puts pink
blues = make_stars(6)[4].split('').each_with_index.map { |x,i|
if x == '*'
if i == 10 || i == 20 || i == 14 || i == 16
x.blue
else
x
end
else
x
end
}.join
puts blues
pink = make_stars(6)[3].split('').each_with_index.map { |x,i|
if x == '*'
if i == 12 || i == 18
x.pink
else
x
end
else
x
end
}.join
puts pink
red = make_stars(6)[4].split('').each_with_index.map { |x,i|
if x == '*'
if i == 10 || i == 20 || i == 14 || i == 16
x.red
else
x
end
else
x
end
}.join
puts red
blue = make_stars(6)[5].split('').each_with_index.map { |x,i|
if x == '*'
if i == 12 || i == 18 || i == 8 || i == 22
x.blue
else
x
end
else
x
end
}.join
puts blue
light = make_stars(6)[3].split('').each_with_index.map { |x,i|
if x == '*'
if i == 12 || i == 18
x.light_blue
else
x
end
else
x
end
}.join
puts light
blues = make_stars(6)[4].split('').each_with_index.map { |x,i|
if x == '*'
if i == 10 || i == 20 || i == 14 || i == 16
x.blue
else
x
end
else
x
end
}.join
puts blues
pinks = make_stars(6)[5].split('').each_with_index.map { |x,i|
if x == '*'
if i == 18 || i == 12 || i == 8 || i == 22
x.pink
else
x
end
else
x
end
}.join
puts pinks
4.times { puts make_stars(6)[1] }
puts ("\n" * 2) + (" " * 8) + "Merry ".red + "Christmas" + "!".yellow + ("\n" * 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment