Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- import os
- empty = ' '
- snow_flake = '*'
- def get_input():
- width = height = 0
- while width % 2 == 0 and height % 2 == 0:
- width = int(input('Podaj nieparzystą szerokość planszy: '))
- height = int(input('Podaj nieparzystą wysokość planszy: '))
- return width, height
- def create_matrix(width, height):
- matrix = []
- for i in range(height):
- matrix.append([empty] * width)
- return matrix
- def clear_matrix(matrix, width, height):
- matrix = create_matrix(width, height)
- return matrix
- def draw_square(matrix, width, height, s):
- matrix = clear_matrix(matrix, width, height)
- x1, y1 = width // 2, height // 2
- x2, y2 = width // 2, height // 2
- x1 -= (s - 1)
- y1 -= (s - 1)
- x2 += (s - 1)
- y2 += (s - 1)
- for x in range(x1, x2 + 1):
- for y in range(y1, y2 + 1):
- if x in (x1, x2) or y in (y1, y2):
- matrix[y][x] = snow_flake
- return matrix
- def generate_new_frame(matrix, width, height, s):
- matrix = draw_square(matrix, width, height, s)
- return matrix
- def print_matrix(matrix):
- for row in matrix:
- print(*row)
- def clear_screen():
- os.system('clear')
- def run():
- width, height = get_input()
- frame = create_matrix(width, height)
- n = min(width, height) // 2 + 1
- while True:
- for i in range(-n + 1, n-1):
- print(n - abs(i))
- clear_screen()
- frame = generate_new_frame(frame, width, height, n - abs(i))
- print_matrix(frame)
- time.sleep(1/24)
- def main():
- run()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement