Me intereso bastante cuando vi el efecto que producia unas simples leyes dentro de una matriz "Juego de la vida" este codigo lo encontre en un manual de python, el cual lo modifique para usar con pygame aqui se los dejo y modifiquen a su gusto xD.......(Hay partes del codigo que no se usan por que? bueno tambien estoy creando mi universo jajaja en fin ^^)
#! /usr/bin/env python
import pygame, serial, sys, MySQLdb, time
from pygame.locals import *
from random import random
from random import randint
pygame.init()
pygame.font.init()
def MostrarMundo():
for y in range(filas):
for x in range(columnas):
if Mundo[y][x]== 1:
pygame.draw.rect(screen,rojo,(x*10,y*10,10,10))
pygame.display.flip()
elif Mundo[y][x] == 2:
pygame.draw.rect(screen,verde,(x*10,y*10,10,10))
pygame.display.flip()
elif Mundo[y][x] == 3:
pygame.draw.rect(screen,azul,(x*10,y*10,10,10))
pygame.display.flip()
elif Mundo[y][x] == 4:
pygame.draw.rect(screen,blanco,(x*10,y*10,10,10))
pygame.display.flip()
elif Mundo[y][x] == 0:
pygame.draw.rect(screen,negro,(x*10,y*10,10,10))
pygame.time.wait(500)
def LaGranExplosion():
for i in range(randint(1,200)):
a = randint(0,21)
b = randint(0,21)
Mundo[a][b]=4
def Accion():
for y in range(filas):
for x in range(columnas):
n = 0
if y > 0 and x > 0 and Mundo[y-1][x-1]:
n+=1
if x > 0 and Mundo[y][x-1]:
n+=1
if y <> 0 and Mundo[y-1][x]:
n+=1
if y <>0 and Mundo[y+1][x]:
n+=1
if y>0 and x < columnas-1 and Mundo[y-1][x+1]:
n+=1
if x < columnas -1 and Mundo[y][x+1]:
n+=1
if y < filas-1 and x < columnas-1 and Mundo[y+1][x+1]:
n+=1
if Mundo[y][x] and (n==2 or n==3): #Nacimiento
Mundo[y][x]=1
elif not Mundo[y][x] and n==3: #Permanencia
Mundo[y][x]=1
else:
Mundo[y][x]=0 #Expiracion
MostrarMundo()
#---------------------------------------------------------------------
screen = pygame.display.set_mode((240, 240))
pygame.display.set_caption('JMQ')
running = 1
verde = 0 , 255, 0
rojo = 255, 0, 0
azul = 0, 0, 255
neg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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
LaGranExplosion()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#pygame.draw.rect(screen, Color, (x, y, x_size, y_size))
Accion()
screen.fill(negro)
pygame.display.flip()
Tengan en cuenta la identacion......... xD
viernes, 9 de noviembre de 2007
Suscribirse a:
Enviar comentarios (Atom)
IRC
#freenode->#usljujuy
Seguidores
Eventos n_n
Tira Ecol Nano,Bilo y Luca
Link's interesantes ^^
Archivo del blog
-
►
2009
(19)
- ► septiembre (5)
-
►
2008
(25)
- ► septiembre (4)
-
▼
2007
(23)
-
▼
noviembre
(17)
- Taller xD II
- Taller xD
- Rasti Tecnico !! otro recuerdo de infancia T_T
- Motobox45 mi manual!!! T_T que recuerdo....
- PicProg
- Programador ICD2
- Piklab en accion!!
- ktechlab !! un completo simulador de electronica y...
- Datalogger Parte II
- Datalogger Parte I
- Python - Juego de la Vida (Automatas Celulares)
- Osciloscopio en accion xD
- Usando Pygame para un Osciloscopio
- Puerto Serial - Python
- GPSIM en accion
- Usando GPSIM
- Construyendo nuestro programador FreeICD2
-
▼
noviembre
(17)
1 comentario:
hola chispo me gusta la idea de probar esto vamos a ver si puedo instalar pygames y largarlo a interpretar
Publicar un comentario