igendel

Skyline

Jun 3rd, 2021 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. import random
  2.  
  3. screen_lines = 30
  4. screen_columns = 100
  5.  
  6. # Building-row parameters
  7. # Each row has: Graphic chars, building width,
  8. #               min height, max height, height list (that will be filled later)
  9. params = [["#H", 8, 4, 20, []],
  10.           ["I/", 4, 6, 24, []]]
  11. star_prob = 0
  12.  
  13.  
  14. # Create the building height lists
  15. def prepare():
  16.     for p in params:
  17.         total_width = 0
  18.         lst = []
  19.         while total_width < screen_columns:
  20.             lst = lst + [random.randint(p[2], p[3])]
  21.             total_width = total_width + p[1]
  22.         p[4] = lst
  23.  
  24.  
  25. # Check which building is seen in a specific coordinate
  26. def get_char(curr_x, curr_y):
  27.     for p in params:
  28.         b_index = curr_x // p[1]
  29.         if curr_y <= p[4][b_index]:
  30.             return p[0][b_index % 2]
  31.     if random.random() < star_prob:
  32.         return random.choice(["*", "."])
  33.     else:
  34.         return " "
  35.  
  36.  
  37. while True:
  38.     print("_" * screen_columns)
  39.     seed = input("Random seed [empty to quit] = ")
  40.     if seed == "":
  41.         break
  42.    
  43.     random.seed(seed)
  44.     prepare()
  45.     star_prob = random.random() / 15
  46.    
  47.     y = screen_lines
  48.     while y > 0:
  49.         x = 0
  50.         s = ""
  51.         while x < screen_columns:
  52.             s = s + get_char(x, y)
  53.             x = x + 1
  54.         print(s)
  55.         y = y - 1
Add Comment
Please, Sign In to add comment