Intro to Python Scripting: 05 For Loop and Math Library
Course or Collection:
Tag:
Video Duration:
12 minutes
In this tutorial we take a closer look at the for loop. Specifically the for range loop and the frange loop (which is unique to rhinoscript). We also introduce the sin and cosine function via python's Math library. This is done by import the math library with an import statment. We create a couple of 2D sine waves and and spiral by combining the functions.
#For Loop to Create Points #For Loop using the range and frange functions import rhinoscriptsyntax as rs import math #Simple Count for i in range(0,50): print(i) #Count by Even Numbers for i in range(0, 50, 2): print(i) #Count by Odd Numbers for i in range(1,50,2): print(i) #Using Rhinoscript's frange to step with floats for d in rs.frange(0.0, 10.0, 0.1): print(d) for d in rs.frange(0.0, 10.0, 0.1): rs.AddPoint(d,0,0) points = [] for d in rs.frange(0.0, 10.0, 0.1): x = d*math.sin(d) y = d*math.cos(d) z = 0.0 rs.AddPoint(x,y,z) pt = (x,y,z) points.append(pt) curve = rs.AddCurve(points)
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
Nabihh replied on Permalink