Guest User

Untitled

a guest
Apr 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import pygame
  2. from random import random
  3. S=200
  4. s=pygame.display.set_mode((S,S))
  5. t=[[random()>0.75 for x in xrange(S)] for y in xrange(S)]
  6. def sim(s,n):
  7.     d={0:0,1:1,2:2,3:3,4:1,5:3,6:3,7:7,8:2,9:3,10:3,11:11,12:3,13:7,14:11,15:15}
  8.     for y in xrange(n&1, S-1, 2):
  9.         for x in xrange(n&1, S, 2):
  10.             p=d[t[x][y]*8+t[(x+1)%S][y]*4+t[x][y+1]*2+t[(x+1)%S][y+1]]
  11.             t[x][y]=(p&8)!=0
  12.             t[(x+1)%S][y]=(p&4)!=0
  13.             t[x][y+1]=(p&2)!=0
  14.             t[(x+1)%S][y+1]=p&1
  15.             s.set_at((x,y),(255*(p&8!=0),)*3)
  16.             s.set_at(((x+1)%S,y),(255*(p&4!=0),)*3)
  17.             s.set_at((x,y+1),(255*(p&2!=0),)*3)
  18.             s.set_at(((x+1)%S,y+1),(255*(p&1!=0),)*3)
  19. n=0
  20. while True:
  21.     sim(s,n)
  22.     n+=1
  23.     pygame.display.flip()
  24.     if pygame.event.poll().type==pygame.KEYDOWN: break
Add Comment
Please, Sign In to add comment