100330_{Show me the CODE} – RhinoPYthomata – lesson 2

marzo 30, 2010

The good and old celullar authomata i did in mel and rhinoscript some time ago… based in arturo´s lyon code. i wrote it now in python for rhino 5.

so , show the code!!!!….

#Script by Arturo lyon, translated to python by Diego Pinochet Puentes
#escripto.wordpress.com

import rhinoscript as rs
import System as ran
import rhinoscript.curve as crv
import Rhino.Geometry as rg
import sys
sys.path.append("C:\\Python26\\Lib")
import random

from time import strftime
print strftime("rhinopythomata celular initiated at" " %H:%M:%S" "-of-" "%Y-%m-%d")

divx= rs.userinterface.GetInteger ("celulas en x")
divy= rs.userinterface.GetInteger ("celulas en y")
dens= rs.userinterface.GetReal ("densidad del patron")

arrcell=[]
numlist=divx
rnd=[]

for i in range (numlist):
 arrcell.append ([0]*divx)
 rnd.append([0]*divx)

for x in range(divx):
 for y in range(divy):
 arrcell[x][y]= crv.AddCircle (rg.Point3d(x,y,0),0.2)
 rnd[x][y]= random.uniform (0,1)
print rnd

for i in range(divx-1):
 for j in range(divy-1):
 if rnd[i][j] < dens:
 rs.object.HideObject (arrcell[i][j])
 #elif rnd[i][j] == dens:
 #rs.object.HideObject (arrcell[i][j])

for i in range (divx-2):
 for j in range (divy-2):
 count =0

 if rs.object.IsObjectHidden (arrcell[i-1][j-1]):
 count= count+1
 else:
 print "celula prendida"
 print count

 if rs.object.IsObjectHidden (arrcell[i-1][j]):
 count= count+1
 else:
 print "celula prendida"
 print count

 if rs.object.IsObjectHidden (arrcell[i-1][j+1]):
 count= count+1
 else:
 print "celula prendida"
 print count

 if rs.object.IsObjectHidden (arrcell[i][j-1]):
 count= count+1
 else:
 print "celula prendida"
 print count

 if rs.object.IsObjectHidden (arrcell[i][j+1]):
 count= count+1
 else:
 print "celula prendida"
 print count

 if rs.object.IsObjectHidden (arrcell[i+1][j-1]):
 count= count+1
 else:
 print "celula prendida"
 print count

 if rs.object.IsObjectHidden (arrcell[i+1][j]):
 count= count+1
 else:
 print "celula prendida"
 print count

 if rs.object.IsObjectHidden (arrcell[i+1][j+1]):
 count= count+1
 else:
 print "celula prendida"
 print count

 if count < 4:
 rs.object.DeleteObject (arrcell[i][j])
 rs.curve.AddCircle (rg.Point3d(i,j,0),0.2)

 else:
 print "celula Viva"
 print count
 if count > 4:
 rs.object.HideObject (arrcell[i][j])
 else:
 print "celula muerta"
 print count

print strftime("rhinopythomata ready" "-at" "%Y-%m-%d" "-hours")
#end of the script

im so noob in python. but i hope this examples help you to understand a little bit of this amazing programming language.

Anuncios

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: