Archivo : estructura.py
#Graficador de estructura usando VRML y Python
#20 nov 2011 1:47
#Ejemplo:
#import estructura
#estructura.estructura(2,3,2)
import os
def estructura(n,m,a):
inp=open("plantillaestruc.wrl","r")
outp=open("estructuraVRML.wrl","w")
for linea in inp.readlines():
outp.write(linea)
inp.close()
outp.close()
inp=open("estructuraVRML.wrl","a")
for i in range(1,a+1):
for j in range(n+1):
inp.write("Transform { \nrotation 0 0 1 1.57\ntranslation")
x=m*1.5
y=j*3.0
z=i*3.0
cad=str(x)+" "+str(y)+" "+str(z)
inp.write(" "+cad+"\n")
h=m*3.0
cad=str(h)
inp.write("children [ \nShape {\ngeometry Cylinder {\nradius 0.1\nheight "+cad+"}")
inp.write("\nappearance Appearance {\nmaterial Material {"\
+"diffuseColor 0.1 0.1 0.9 }\n}}]}")
for j in range(m+1):
inp.write("Transform { \ntranslation")
x=j*3.0
y=n*1.5
z=i*3.0
cad=str(x)+" "+str(y)+" "+str(z)
inp.write(" "+cad+"\n")
h=n*3.0
cad=str(h)
inp.write("children [ \nShape {\ngeometry Cylinder {\nradius 0.1\nheight "+cad+"}")
inp.write("\nappearance Appearance {\nmaterial Material {"\
+"diffuseColor 0.1 0.1 0.9 }\n}}]}")
for j in range(n+1):
for i in range(m+1):
inp.write("Transform { \nrotation 1 0 0 1.57\ntranslation")
x=i*3.0
y=j*3.0
z=a*1.5
cad=str(x)+" "+str(y)+" "+str(z)
inp.write(" "+cad+"\n")
h=a*3.0
cad=str(h)
inp.write("children [ \nShape {\ngeometry Cylinder {\nradius 0.1\nheight "+cad+"}")
inp.write("\nappearance Appearance {\nmaterial Material {"\
+"diffuseColor 0.1 0.1 0.9 }\n}}]}")
inp.close()
os.system('./bscontact estructuraVRML.wrl')
Archivo : plantillaestruc.wrl
#VRML V2.0 utf8
#PLANTILLA PARA EL GRAFICADOR
Background {
skyColor [0 0 0, 0 1 0, 1 1 1]
}
#____________________EJES_COORDENADOS_______________
Shape {
geometry IndexedLineSet {
coord Coordinate {
point [5 0 0,-5 0 0,0 5 0,0 -5 0,0 0 5,0 0 -5]}
coordIndex [0,1,-1,2,3,-1,4,5,-1]
color Color {
color [ 1 0 0,0 0 0,0 0 1]}
colorIndex [0,1,2]
colorPerVertex FALSE }
}
Ejemplo:
No hay comentarios:
Publicar un comentario