Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import turtle
- import threading
- wn = turtle.Screen()
- t = turtle.Turtle()
- t.penup()
- t.speed(0)
- t.ht()
- mode = int(input("What mode do you want to use to get the initial state? (1 - from a .cgol file,2 - random)"))
- speed = float(input("How long is the delay between generations (seconds)"))
- CellList = []
- #length = 0
- if mode == 1:
- file = open(input('Please input the .cgol file name: ')+'.cgol','r')
- code = file.readlines()
- for i in code:
- templist = list(i)
- while 'n' in templist:
- templist.remove('n')
- templist2 = []
- for u in templist:
- templist2.append(int(u))
- CellList.append(templist2)
- if mode == 2:
- import random
- length = int(input("How many cells across is the grid?"))
- for i in range(0,length):
- ShortList = []
- for u in range(0,length):
- ShortList.append(int(random.randrange(0,2)))
- CellList.append(ShortList)
- Display = []
- FriendList = []
- for i in range(0, len(CellList)):
- FriendList.append([])
- while True:
- wn.tracer(0,0)
- Display = []
- for y in range(0,len(CellList)):
- for x in range(0,len(CellList)):
- ymin = y - 1
- xmin = x - 1
- yplus = y + 1
- xplus = x + 1
- if yplus > len(CellList)-1:
- yplus = 0
- if ymin < 0:
- ymin = len(CellList)-1
- if xplus > len(CellList)-1:
- xplus = 0
- if xmin < 0:
- xmin = len(CellList)-1
- FriendList[y].append(CellList[xmin][ymin] + CellList[xmin][yplus] + CellList[xmin][y] + CellList[xplus][ymin] + CellList[xplus][yplus] + CellList[xplus][y] + CellList[x][ymin] + CellList[x][yplus])
- for x in range(0,len(CellList)):
- Display.append("n")
- for y in range(0,len(CellList)):
- if CellList[x][y] == 1:
- if FriendList[y][x] > 3:
- CellList[x][y] = 0
- if FriendList[y][x] < 2:
- CellList[x][y] = 0
- else:
- if FriendList[y][x] == 3:
- CellList[x][y] = 1
- Display.append(str(CellList[x][y]))
- for i in range(0,(len(CellList)**2)+len(CellList)):
- if Display[i] == '1':
- Display[i] = '||'
- if Display[i] == '0':
- Display[i] = ' '
- for y in range(0,len(CellList)):
- for x in range(0,len(CellList)):
- if CellList[y][x] == 1:
- t.goto(x*10,-y*10)
- t.dot(10)
- FriendList = []
- for i in range(0, len(CellList)):
- FriendList.append([])
- print("".join(Display))
- Display = []
- wn.update()
- t.clear()
- time.sleep(speed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement