Grasshopper

algorithmic modeling for Rhino

[Python] Attractor point recursive subdivision[PROBLEM_Error]

Hi everyone,

I have tried a simple test to write a recursive subdivision function in Python but there is something wrong with the loop because even with only 2 steps it produce 132 faces... that I can not figure out how to write it properly. So please help me out. Thank you.

Cheers,

Zumii

Views: 1258

Attachments:

Replies to This Discussion

Hi Zumii

I am not exactly sure what this script should do. A recursive function, generally, does not need a for loop inside. You should try to think of a way to remove that for loop. Also, have a counter of generations, and each time you call your function again, increase it.

If you need any more help, please let me know.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Giulio is totally right, a recursive function or algorithm calls itself to create the repetitive behaviour in the task they do. Try this and see if you understand the concept. Iteration is the other way to go and usually it uses loops in order to create repetition.

a = 0

def recursive_add(variable):

   if variable >10:

      return variable

   else:

      variable++

      print variable

      recursive_add(variable)

 

recursive_add(a)

Cheers.

Ángel.

I'm not sure Python supports the ++ style of incrementing a variable. If not this should work:

variable += 1

Hehehe!,

Yeah, you're right. Sorry, I've been coding in Processing last month :P It seams that I contaminated my python knowledge a bit :P

Hehe, been there myself :)

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service