algorithmic modeling for Rhino
hey guys!
I've been working with grashopper for quite some time and since I came to some limitations concerning recursive loops i want to dig into python and scripting.
what i want to do is wirte a function that draws a circle and divides the circle.
then i want to redo the function for every division-point but reducing the new radius by 1 ...i want to redo this function just as long as my radius is higher than 0.
the script i managed to write so far looks like this:
________________________________________________
import rhinoscriptsyntax as rs
def recursion(pt,r,div):
if r > 0:
circle = rs.AddCircle(pt,r)
division = rs.DivideCurve(circle,div,True,True)
for d in division:
return recursion(d,r-1,div)
recursion([0,0,0],10,5)
__________________________________________
but somehow my function isn't applied to every divison point...do you know what to change or how to rewrite the function?
thanks in advance
Tags:
for d in division
return recursion...
The return statement is the problem I'll bet. If you return out of the loop, you'll only iterate once.
As David already pointed out, you are "breaking" your loop each time with return statement - meaning only the first item in the "division" list gets passed to each recursive function call. So just generate your list points first, before calling the function:
import rhinoscriptsyntax as rs
def recursion(pts,r,div,n):
if n > 0:
divisionPtsL = []
for pt in pts:
circle = rs.AddCircle(pt,r)
divisionPts = rs.DivideCurve(circle,div,True,True)
for pt2 in divisionPts:
divisionPtsL.append(pt2)
return recursion(divisionPtsL,r*0.35,div,n-1)
else:
return
recursion([[0,0,0]],10,5,3)
Attached is a grasshopper version too.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by