algorithmic modeling for Rhino
Hi,
I am trying to write a very simple code to initialize a counter value for variable Y once variable X (inputted with a number slider) reaches a certain threshold. Also, the Y value should only increase if and when the x value does. This is why I think a while loop might not be the best solution. I tried a 'for each', but I cannot iterate over a non-iterable obviously.
For instance, once the input of x reaches n values, then I'd like to initialize y and then stop y's counter once it reaches a threshold. Here is my code: thank you
(attempt 1)
y = 0
while x > 10:
y += 0.5
if y >= 4.0:
break
a = y
(attempt2)
vals = []
inc = x + 0.05for val in vals:
vals.append(x)
if vals > 10:
y += inc
a = vals
Tags:
Sounds like you're in need of a persistent variable? If so, there are at least two different strategies for doing this within a GHPython component (both covered in this thread). I would recommend the most straightforward one outlined by Giulio here.
Hi,
let me know if this helps. Please find the file attached.
Thank you to both of you. @ Anders - yes, the links you posted are very helpful.
@ Devang, thank you your solution is very elegant. Much appreciated.
Thank you again
Turns out I have another issue which is crashing my system.
I am trying to reverse a number slider input once I meet a threshold with this code:
threshold = x/2
inc = float(.1)y = 0
while true:
if y >= len:
inc *= -1
y += inc
if y <= 0:
breaka = y
I would rather not use a while loop so that I can control the descent with a number slider
Hi,
Please find attached file. Is that what you're looking for?
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
© 2024 Created by Scott Davidson. Powered by