Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. import time
  2. import turtle
  3. import threading
  4. wn = turtle.Screen()
  5. t = turtle.Turtle()
  6. t.penup()
  7. t.speed(0)
  8. t.ht()
  9. mode = int(input("What mode do you want to use to get the initial state? (1 - from a .cgol file,2 - random)"))
  10. speed = float(input("How long is the delay between generations (seconds)"))
  11. CellList = []
  12. #length = 0
  13. if mode == 1:
  14. file = open(input('Please input the .cgol file name: ')+'.cgol','r')
  15. code = file.readlines()
  16. for i in code:
  17. templist = list(i)
  18. while 'n' in templist:
  19. templist.remove('n')
  20. templist2 = []
  21. for u in templist:
  22. templist2.append(int(u))
  23. CellList.append(templist2)
  24. if mode == 2:
  25. import random
  26. length = int(input("How many cells across is the grid?"))
  27. for i in range(0,length):
  28. ShortList = []
  29. for u in range(0,length):
  30. ShortList.append(int(random.randrange(0,2)))
  31. CellList.append(ShortList)
  32.  
  33. Display = []
  34. FriendList = []
  35. for i in range(0, len(CellList)):
  36. FriendList.append([])
  37. while True:
  38. wn.tracer(0,0)
  39. Display = []
  40. for y in range(0,len(CellList)):
  41. for x in range(0,len(CellList)):
  42. ymin = y - 1
  43. xmin = x - 1
  44. yplus = y + 1
  45. xplus = x + 1
  46. if yplus > len(CellList)-1:
  47. yplus = 0
  48. if ymin < 0:
  49. ymin = len(CellList)-1
  50. if xplus > len(CellList)-1:
  51. xplus = 0
  52. if xmin < 0:
  53. xmin = len(CellList)-1
  54. 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])
  55. for x in range(0,len(CellList)):
  56. Display.append("n")
  57. for y in range(0,len(CellList)):
  58. if CellList[x][y] == 1:
  59. if FriendList[y][x] > 3:
  60. CellList[x][y] = 0
  61. if FriendList[y][x] < 2:
  62. CellList[x][y] = 0
  63. else:
  64. if FriendList[y][x] == 3:
  65. CellList[x][y] = 1
  66. Display.append(str(CellList[x][y]))
  67. for i in range(0,(len(CellList)**2)+len(CellList)):
  68. if Display[i] == '1':
  69. Display[i] = '||'
  70. if Display[i] == '0':
  71. Display[i] = ' '
  72. for y in range(0,len(CellList)):
  73. for x in range(0,len(CellList)):
  74. if CellList[y][x] == 1:
  75. t.goto(x*10,-y*10)
  76. t.dot(10)
  77. FriendList = []
  78. for i in range(0, len(CellList)):
  79. FriendList.append([])
  80. print("".join(Display))
  81. Display = []
  82. wn.update()
  83. t.clear()
  84. time.sleep(speed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement