091105_SHOW ME THE CODE!! pythomata (cellular automata in python)

noviembre 5, 2009

ca

this is the code for the cellular automatta posted before (rhitomata), but now for it´s aplication in maya (python).

so , here´s the code.

you can visit http://digifab.wordpress.com for the MEL code.

#celullar automata

import maya.cmds as mc
import random

#Ejercicio final clase MELsCRIPT Arturo Lyon – Traduccion a Python por Diego Pinochet

divx= int(raw_input(“celulas en x:”))
divy= int(raw_input(“celulas en y: “))

#w = (raw_input(“inserte un decimal entre 0.01 y 0.99: “))

arrsph=[]

numlist= divx

arrsph=[]
rnd=[]
for i in range(numlist):
arrsph.append ([0]*divx)
rnd.append ([0]*divx)
#print arrsph

for x in range (divx):
for y in range (divy):
arrsph[x][y]= mc.polyCube (h=0.9,w=0.9)
mc.move (x,y,1)

for x in range (divx):
for y in range (divy):
rnd[x][y]= (random.uniform (0,1))
if rnd[x][y] < 0.5:
mc.select (arrsph[x][y])
mc.setAttr (‘.visibility’,0)

for x in range (1,(divx-1)):
for y in range (1,(divy-1)):

count =0

mc.select (arrsph[x-1][y-1])
s= mc.getAttr (‘.visibility’)
if s==0:
count =count+1

mc.select (arrsph[x-1][y])
s= mc.getAttr (‘.visibility’)
if s==0:
count=count+1

mc.select (arrsph[x-1][y+1])
s= mc.getAttr (‘.visibility’)
if s==0:
count=count+1

mc.select (arrsph[x][y-1])
s= mc.getAttr (‘.visibility’)
if s==0:
count=count+1

mc.select (arrsph[x][y+1])
s= mc.getAttr (‘.visibility’)
if s==0:
count=count+1

mc.select (arrsph[x+1][y-1])
s= mc.getAttr (‘.visibility’)
if s==0:
count=count+1

mc.select (arrsph[x+1][y])
s= mc.getAttr (‘.visibility’)
if s==0:
count=count+1

mc.select (arrsph[x+1][y+1])
s= mc.getAttr (‘.visibility’)
if s==0:
count=count+1

#print “ou yeah madafaca”

if count<4:
mc.select (arrsph[x][y])
mc.setAttr (‘.visibility’,1)

if count>4:
mc.select (arrsph[x][y])
mc.setAttr (‘.visibility’,0)

#end of code
————————————————————————-

So simple ….yet so emergent!!! (haha). i just love python.

Anuncios

3 comentarios to “091105_SHOW ME THE CODE!! pythomata (cellular automata in python)”

  1. rodrigo Says:

    Diego,

    you should use the

     tag when publishing python code, so the indenting is maintained.
    
    Great work!
    
    Rodrigo
  2. rodrigo Says:

    woops, that’s the <pre> tag.


Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: