Last active
October 1, 2018 06:56
-
-
Save avalanchy/6592523 to your computer and use it in GitHub Desktop.
Choinka Generator Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import logging | |
C = 80 # console width | |
def cen(text): | |
return text.center(C) | |
if len(sys.argv) == 3: | |
try: | |
w, h = int(sys.argv[1]), int(sys.argv[2]) | |
except ValueError: | |
logging.error('Please provide integer args for width and height') | |
sys.exit(1) | |
else: | |
logging.error('Please provide args for width and height') | |
sys.exit(1) | |
if not (120 >= h > 0 and 80 >= w > 0): | |
logging.error('Please keep range in: 120>=height>0 and 80>=width>0') | |
sys.exit(1) | |
tw, th = int(.1*h) or 1, int(.1*w) or 1 | |
h -= th | |
tree = [cen('#'*int(w*i/h)) for i in range(1, h+1)] | |
tree += [cen('#'*tw) for i in range(th)] | |
print('\n'.join(tree)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3 | |
import sys | |
szerokosc = int(sys.argv[1]) | |
wysokosc = int(sys.argv[2]) | |
P = 0.8 # wysokość choinki bez pieńka | |
E = 79 # szerokość ekranu | |
si = szerokosc # szerokość igieł | |
wi = int(wysokosc * P) # wysokość igieł | |
sp = int(szerokosc * (1 - P)) # szerokosc pieńka | |
wp = wysokosc - wi # wysokość pieńka | |
# rysowanie igieł | |
for n in range(1, wi + 1): | |
p = n / wi # procent pełnej wysokości | |
sl = int(si * p) # szerokość igieł | |
l = ('#' * sl).center(E) | |
print(l) | |
# rysowanie pieńka | |
for i in range(1, wp + 1): | |
l = ('#' * sp).center(E) | |
print(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment