Populating
a unit with ability to vary within itself on 1) a surface 2) a spiral
1) UNIT
ON A SURFACE
import rhinoscriptsyntax as rs
import random
radius=10
circles=[]
def geometry(center,radius,factor):
circle=rs.AddCircle(center,radius)
divpts=rs.DivideCurve(circle,3,create_points=True)
line=rs.AddInterpCurve([center,divpts[0],divpts[1],divpts[2],center],3)
vector=rs.VectorCreate(center,divpts[1])
length=rs.VectorLength(vector)
scaledvector=rs.VectorScale(vector,length*factor)
mid=rs.VectorAdd(center,scaledvector)
middle=rs.AddPoint(mid)
trans=radius*2
movedmid=rs.MoveObject(middle,[0,0,trans])
piece=rs.ExtrudeCurvePoint(line,movedmid)
numberofelements=random.randint(5,15)
for i in range
(0,numberofelements):
rotatepiece=rs.RotateObject(piece,movedmid,(360/numberofelements)*i,copy=True)
rs.ScaleObject(rotatepiece,middle,[1+0.01*i,01+0.01*i,1+0.01*i])
def center (pointlist):
x=0
y=0
z=0
for i in range
(0,len(pointlist)):
x = x + pointlist[i][0]
y = y + pointlist[i][1]
z = z + pointlist[i][2]
x=x/len(pointlist)
y=y/len(pointlist)
z=z/len(pointlist)
return [x,y,z]
def samplesurface(strSrf, intUdivisions,intVdivisions):
listUdomain = rs.SurfaceDomain(strSrf,0)
listVdomain = rs.SurfaceDomain(strSrf,1)
floatUstep = (listUdomain[1]-listUdomain[0])/intUdivisions
floatVstep = (listVdomain[1]-listVdomain[0])/intVdivisions
listofrows = []
for i in rs.frange(listUdomain[0],listUdomain[1],floatUstep):
columnlist = []
for j in rs.frange(listVdomain[0],listVdomain[1]+floatVstep,floatVstep):
columnlist.append(rs.EvaluateSurface(strSrf,i,j))
listofrows.append(columnlist)
return listofrows
strSrf = rs.GetObject("surface",8)
intUdivisions = 10
intVdivisions = 10
listofpoints = samplesurface(strSrf,intUdivisions,intVdivisions)
circles=[]
midpoints=[]
vectorlist=[]
for i in range
(0,len(listofpoints)-1):
for j in range
(0,len(listofpoints[i])-1):
pointlist=[]
pointlist.extend([listofpoints[i][j],listofpoints[i][j+1],listofpoints[i+1][j+1],listofpoints[i+1][j]])
midpoint=center(pointlist)
midpoints.append(rs.AddPoint(midpoint))
radius=random.randint(5,15)
for i in range
(0,len(midpoints)-1):
center=midpoints[i]
factor=-.2*(i/100)
radius=10*(1+0.01*i)
geom=geometry(center,radius,factor)
2)UNIT
ON A SPIRAL
import rhinoscriptsyntax as rs
import math
import random
def geometry(center,radius,factor):
circle=rs.AddCircle(center,radius)
divpts=rs.DivideCurve(circle,3,create_points=True)
line=rs.AddInterpCurve([center,divpts[0],divpts[1],divpts[2],center],3)
vector=rs.VectorCreate(center,divpts[1])
length=rs.VectorLength(vector)
scaledvector=rs.VectorScale(vector,length*factor)
mid=rs.VectorAdd(center,scaledvector)
middle=rs.AddPoint(mid)
trans=radius*2
movedmid=rs.MoveObject(middle,[0,0,trans])
piece=rs.ExtrudeCurvePoint(line,movedmid)
numberofelements=random.randint(5,15)
for i in range
(0,numberofelements):
rs.RotateObject(piece,movedmid,(360/numberofelements)*i,copy=True)
radius=10
bigpoints=[]
pointlist=[]
for i in range(0,20):
r=i+1
x=7*r*math.sin(i)
y=7*r*math.cos(i)
points=rs.AddPoint(x,y,i*5)
bigpoints.append(points)
for j in range(0,20):
r=j+1
x=r*math.sin(j)
y=r*math.cos(j)
points=rs.AddPoint(x,y,j)
pointlist.append(points)
trans=rs.VectorCreate(pointlist[0],bigpoints[i])
pointlist.extend(rs.CopyObjects(points,translation=-trans))
for k in range
(0,len(pointlist)-1):
center=pointlist[k]
factor=-.3*(i/70)
No comments:
Post a Comment