Intro to Python Scripting: 18 Simple Growth 02
Course or Collection:
Tag:
Video Duration:
6 minutes
In this tutorial, we modify a couple of lines from the last tutorial to change our circles to spheres and we add the 3rd dimension to our growth. In the code snippet below, I've simply commented out the code for 2D cirlces and replaced those lines with 3D spheres. Instead of rs.AddCircle() we are using rs.AddSphere().
import rhinoscriptsyntax as rs import random def placePt(x_range,y_range,z_range): x = random.uniform(0,x_range) y = random.uniform(0,y_range) z = random.uniform(0,z_range) pt = [x,y,z] return pt rs.EnableRedraw(False) ptZero = [50,50,50] pts = [] pts.append(ptZero) #circleZero = rs.AddCircle(ptZero,0.5) sphereZero = rs.AddSphere(ptZero, 0.5) for i in range(0,1000): pt = rs.AddPoint(placePt(100,100,100)) index = rs.PointArrayClosestPoint(pts,pt) cp = pts[index] vect = rs.VectorCreate(cp,pt) unitVect = rs.VectorUnitize(vect) subVect = vect - unitVect newPt = rs.MoveObject(pt,subVect) #rs.AddCircle(newPt,0.5) rs.AddSphere(newPt,0.5) pts.append(newPt) rs.Redraw()
Want to Contribute?
Want to be an author? Drop us a line here we'd love to have you.
Already have a video you'd like to post? Send us a link and we'll get you going.
:)
Comments
Charles_design replied on Permalink