Skip to content

Instantly share code, notes, and snippets.

@astynax
Created January 1, 2026 13:08
Show Gist options
  • Select an option

  • Save astynax/f29e6ea97ec7939687adeef57667c771 to your computer and use it in GitHub Desktop.

Select an option

Save astynax/f29e6ea97ec7939687adeef57667c771 to your computer and use it in GitHub Desktop.
Xmas Tree in ASCII

This script prints a Xmas Tree as an ASCII-Art piece. Output looks like:

           |
          +|
          0|+
         ++|0
         10|++
        +++|01
        010|+++
       ++++|010
       1010|++++
      +++++|0101
      01010|+++++
     ++++++|01010
     101010|++++++
    +++++++|010101
    0101010|+++++++
   ++++++++|0101010
   10101010|++++++++
  +++++++++|01010101
  010101010|+++++++++
 ++++++++++|010101010
 1010101010|++++++++++

But the real one is also colored :)

#!/usr/bin/env python3
def c256(c, s):
return f"\033[38;5;{c}m{s}\033[0m"
def colorize(s, f):
return "".join(c256(f(x), x) for x in s)
def draw(s, f):
l = len(s) // 2
rows = []
row = []
for x in s:
row = [x] + row[::-1]
rows.append(row)
for i, row in enumerate(rows):
print(" " * (l - (i - 1) // 2) + colorize(row, f))
if __name__ == "__main__":
draw("|" + "+0+1" * 5, {"|": 94, "+": 22, "0": 40, "1": 202}.get)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment