Question about lists - scaleVect


#1

Hi,

I have found a scaling tutorial on designalyze.com by Zach Downey and I got lost near the row :

scaleVect = [x - sc for x in scaleVect].

What is going on here exactly? I do not understand that “x” as variable has been introduced but how the script knows that “x” refers to the 1st member of the scaleVect list ?

import rhinoscriptsyntax as rs
 
def RecursiveScale(objID,scalePt,scaleFact, scaleVect, num):
    if num == 0:
        return 0
    else:
        sc = (1.0 / scaleFact)
        scaleVect = [x - sc for x in scaleVect]
        rs.ScaleObject(objID, scalePt, scaleVect, True)
        return RecursiveScale(objID, scalePt, scaleFact, scaleVect, num-1)
 
 
objID = rs.GetObject()
scalePt = rs.GetPoint("Pick Scale Center")
scaleFact = rs.GetReal("Enter a scale Factor", 10, 0)
scaleVect = [1.0, 1.0, 1.0]
num = rs.GetInteger("Enter a the number of iterations", 10, 1)
 
RecursiveScale(objID, scalePt, scaleFact, scaleVect, num)
    indent preformatted text by 4 spaces

#2

@onrender,

scaleVect = [x - sc for x in scaleVect]

that is a list comprehension, read more about it here.

c.


#3

Thanks Clement