Grasshopper

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

Views: 1154

Attachments:

Replies to This Discussion

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.

Attachments:

thank you guys!
i really appreciate you guys answering to very beginner's questions!helps a lot!!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service