Intro to Python Scripting: 05 For Loop and Math Library

Software: 
Tag: 
Video Duration: 
12 minutes
Author: 
Zach Downey

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)

Rating

Please rate this tutorial below. Thanks.

5
Average: 4.9 (13 votes)

Comments

Hi, I'm having a problem opening videos Lesson 00: Macros and Intro to Python Scripting: 02 Varibles and Input/Output in this course, I got these messages: - Fatal error: Cannot redeclare t5cd1() (previously declared in /home/jwbgchqj33pr/domains/designalyze.com/html/sites/all/libraries/geshi/geshi/html4strict.php:1) in /home/jwbgchqj33pr/domains/designalyze.com/html/sites/all/libraries/geshi/geshi/html4strict.php on line 1 - Fatal error: Cannot redeclare t5cd1() (previously declared in /home/jwbgchqj33pr/domains/designalyze.com/html/sites/all/libraries/geshi/geshi/html4strict.php:1) in /home/jwbgchqj33pr/domains/designalyze.com/html/sites/all/libraries/geshi/geshi/html4strict.php on line 1 do you have any idea what the problem might be

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.

:)