import random
screen_lines = 30
screen_columns = 100
# Building-row parameters
# Each row has: Graphic chars, building width,
# min height, max height, height list (that will be filled later)
params = [["#H", 8, 4, 20, []],
["I/", 4, 6, 24, []]]
star_prob = 0
# Create the building height lists
def prepare():
for p in params:
total_width = 0
lst = []
while total_width < screen_columns:
lst = lst + [random.randint(p[2], p[3])]
total_width = total_width + p[1]
p[4] = lst
# Check which building is seen in a specific coordinate
def get_char(curr_x, curr_y):
for p in params:
b_index = curr_x // p[1]
if curr_y <= p[4][b_index]:
return p[0][b_index % 2]
if random.random() < star_prob:
return random.choice(["*", "."])
else:
return " "
while True:
print("_" * screen_columns)
seed = input("Random seed [empty to quit] = ")
if seed == "":
break
random.seed(seed)
prepare()
star_prob = random.random() / 15
y = screen_lines
while y > 0:
x = 0
s = ""
while x < screen_columns:
s = s + get_char(x, y)
x = x + 1
print(s)
y = y - 1
Comments