SHARE
TWEET

Untitled

a guest Oct 23rd, 2017 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import time
  3. import os
  4.  
  5. empty = ' '
  6. snow_flake = '*'
  7.  
  8.  
  9. def get_input():
  10.     width = height = 0
  11.     while width % 2 == 0 and height % 2 == 0:
  12.         width = int(input('Podaj nieparzystą szerokość planszy: '))
  13.         height = int(input('Podaj nieparzystą wysokość planszy: '))
  14.  
  15.     return width, height
  16.  
  17.  
  18. def create_matrix(width, height):
  19.     matrix = []
  20.     for i in range(height):
  21.         matrix.append([empty] * width)
  22.     return matrix
  23.  
  24.  
  25. def clear_matrix(matrix, width, height):
  26.     matrix = create_matrix(width, height)
  27.     return matrix
  28.  
  29.  
  30. def draw_square(matrix, width, height, s):
  31.     matrix = clear_matrix(matrix, width, height)
  32.     x1, y1 = width // 2, height // 2
  33.     x2, y2 = width // 2, height // 2
  34.     x1 -= (s - 1)
  35.     y1 -= (s - 1)
  36.     x2 += (s - 1)
  37.     y2 += (s - 1)
  38.     for x in range(x1, x2 + 1):
  39.         for y in range(y1, y2 + 1):
  40.             if x in (x1, x2) or y in (y1, y2):
  41.                 matrix[y][x] = snow_flake
  42.     return matrix
  43.  
  44.  
  45. def generate_new_frame(matrix, width, height, s):
  46.     matrix = draw_square(matrix, width, height, s)
  47.     return matrix
  48.  
  49.  
  50. def print_matrix(matrix):
  51.     for row in matrix:
  52.         print(*row)
  53.  
  54.  
  55. def clear_screen():
  56.     os.system('clear')
  57.  
  58.  
  59. def run():
  60.     width, height = get_input()
  61.     frame = create_matrix(width, height)
  62.     n = min(width, height) // 2 + 1
  63.  
  64.     while True:
  65.         for i in range(-n + 1, n-1):
  66.             print(n - abs(i))
  67.             clear_screen()
  68.             frame = generate_new_frame(frame, width, height, n - abs(i))
  69.             print_matrix(frame)
  70.             time.sleep(1/24)
  71.  
  72.  
  73. def main():
  74.     run()
  75.  
  76.  
  77. if __name__ == '__main__':
  78.     main()
RAW Paste Data
Top