import random import time import os size = int(input("Enter a size:")) rows = cols = size #Generate 2d array graphic = [] for i in range(rows): col = [] for j in range(cols): col.append(0) graphic.append(col) #'Easy' way to make a 2D array #graphic = [[0 for i in range(cols)] for j in range(rows)] #Fill array with random values #for i in range(0,size): #for j in range(0,size): #graphic[i][j] = random.randint(0,1) graphic[int(cols/2)][int(rows/2)] = 1 #print(graphic) def print_array(arr): for i in range(0,len(arr)): for j in range(0,len(arr[0])): if (arr[i][j] == 1): print("#",end="") else: print(" ",end="") print("") #Change array to make fancy effect def update_array(arr, turn): for i in range(0,len(arr)): for j in range(0,len(arr[0])): if (arr[i][j] == 1 and i > 0 and i < rows-1 and j > 0 and j < cols-1): if (arr[i][j+1] == 0): arr[i][j+1] = 2 #2 is a temporary state if (arr[i][j-1] == 0): arr[i][j-1] = 2 if (arr[i+1][j] == 0): arr[i+1][j] = 2 if (arr[i-1][j] == 0): arr[i-1][j] = 2 arr[i][j] = -2 for i in range(0, len(arr)): for j in range(0, len(arr[0])): if (arr[i][j] == 2): arr[i][j] = 1 if (arr[i][j] < 0): arr[i][j] += 1 if (turn % 5 == 0): arr[int(cols/2)][int(rows/2)] = 1 turn = 1 while True: os.system('cls||clear') print_array(graphic) update_array(graphic, turn) turn += 1 time.sleep(1) print()