#!/usr/bin/env python from numpy import * from numpy.random import randint import pygame import sys import pyximport pyximport.install(setup_args={"include_dirs":get_include()}) import fhp def draw_states(states): screen.fill((200,200,220)) n = shape(states)[-2] tr = .35 #token radius for i in range(n): for j in range(n): dx = (j%2)/2. pygame.draw.circle(screen, (0,255,0), (int(pix2site*(i+dx)),int(pix2site*j)), int(.2*pix2site)) if states[i,j][0]: pygame.draw.circle(screen, (240,0,0), (int(pix2site*(i-tr+dx)),int(pix2site*j)), int(.1*pix2site)) if states[i,j][1]: pygame.draw.circle(screen, (240,0,0), (int(pix2site*(i-.5*tr+dx)),int(pix2site*(j+.866*tr))), int(.1*pix2site)) if states[i,j][2]: pygame.draw.circle(screen, (240,0,0), (int(pix2site*(i-.5*tr+dx)),int(pix2site*(j-.866*tr))), int(.1*pix2site)) if states[i,j][3]: pygame.draw.circle(screen, (240,0,0), (int(pix2site*(i+.5*tr+dx)),int(pix2site*(j+.866*tr))), int(.1*pix2site)) if states[i,j][4]: pygame.draw.circle(screen, (240,0,0), (int(pix2site*(i+.5*tr+dx)),int(pix2site*(j-.866*tr))), int(.1*pix2site)) if states[i,j][5]: pygame.draw.circle(screen, (240,0,0), (int(pix2site*(i+tr+dx)),int(pix2site*j)), int(.1*pix2site)) pygame.display.update() n = 2*20 #world has n**2 sites pix2site = 30 sr = 5 #radius of seeded region #world = zeros((n,n,6),dtype=int) world = randint(0,2,(n,n,6)) world[n/2-sr:n/2+sr, n/2-sr:n/2+sr] = array([1,1,1,1,1,1],dtype=int8) pygame.init() screen = pygame.display.set_mode((pix2site*n,pix2site*n)) clock = pygame.time.Clock() fps = 10 i=0 while(True): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit(); sys.exit(); fhp.apply_rules(world) msElapsed = clock.tick(fps) draw_states(world) pygame.image.save(screen,"frames/fhp1/%04d.bmp"%i) i+=1 #transport temp = zeros((n,n,6),dtype=int) temp[:-1,:,5] = world[1:,:,0] temp[1:,:, 0] = world[:-1,:,5] temp[1:,:-1,1] = world[:-1,1:,4] temp[0,1:-1:2,1] = 0 #ragged edge temp[:-1,:-1,3] = world[1:,1:,2] temp[-1,:-1:2,3] = 0 #ragged edge temp[1:,1:, 2] = world[:-1,:-1,3] temp[0,1:-1:2,2] = 0 #ragged edge temp[:-1,1:,4] = world[1:,:-1,1] temp[0,:-1:2,4] = 0 #ragged edge world = temp msElapsed = clock.tick(fps) draw_states(world) pygame.image.save(screen,"frames/fhp1/%04d.bmp"%i) i+=1