tag:blogger.com,1999:blog-81833950942798134.post1574876143416189352..comments2009-07-13T19:36:13.465+02:00Comments on Generative Scripting II: Alice_Assignment 01B script trialdanrochahttp://www.blogger.com/profile/04468836977853242830noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-81833950942798134.post-57911966246520455382009-05-25T13:37:18.445+02:002009-05-25T13:37:18.445+02:00This comment has been removed by the author.alicehttps://www.blogger.com/profile/13826062750165810811noreply@blogger.comtag:blogger.com,1999:blog-81833950942798134.post-79140107418253612422009-05-23T15:12:41.861+02:002009-05-23T15:12:41.861+02:00Hi Alice,
Nice and clear script. Here some commen...Hi Alice,<br /><br />Nice and clear script. Here some comments:<br /><br />1) You'll have a problem with the 3 random points (line 7), as you create them outside of the function definition. What will happen is the following: you create it first time. Then in the first iteration of the pointBoundary function, it will use these values, and then generate new values for these variables inside the function (lines 57-70). But then, on the following iteration, the function will still use the values you created on the first time. Why? because of the variable scope: variables created on the root of the script, outside of any functions or loops, are accessible globally. That's what happens with ptA, ptB and ptC in lines 7-10. Variables created inside functions or loops exist only inside these functions or loops: their scope is local. Everytime the function terminates or is executed again, or in every iteration of the loop, these local variables are deleted from memory and do not retain their value. So how could you still grab and use these values? By passing them as arguments to your function. Your function definition should actually be:<br /><br />def pointBoundary(iterations, ptA, ptB, ptC):<br /><br />and then when you call it again on the recursive call (last line), you have to pass the newly created values from lines 61-70 when you call the function again.<br /><br />2) On line 83, when you call the function again, be careful with the identation: it should be idented under the else statement, so that it is executed only if iterations are not equal to 0. Also, when you call a function, you don't use the "def" word, just the function name.<br /><br />3) about how to get those random points in the beginning (7-10): it is not hard. If you imagine your square is plotted on a (x,y) plane, you know that the center of it is on (0,0) (as you did not define a center in the nurbsSquare command, it goes to the default 0,0,0). This way you can get the corner coordinates of it if you know the side lengths, which you leaves you with the x-minimum, x-maximum, y-minimun and y-maximum. You can then use these values to get any random point inside the square:<br /><br />from random import *<br /><br />x = uniform(xmin, xmax)<br />y = uniform(ymin, ymax)<br /><br />In general I think you are going on a good direction. You just have to test test and test, and according to the results you can find where the problem is. Give it a try and post here!danrochahttps://www.blogger.com/profile/04468836977853242830noreply@blogger.com