pythonrhino3d

Reverse Count after threshold


I am feeding a number slider in RhinoPython to increment the y value. I wish to reverse the increment when y equals a certain value. I have figured out how to make it negative, but that is not what I'm after. Sorry, for the simplicity of this question and thank you. In short the number slider increments the variable and once it reaches 45, then it would count down with every increment of the number slider.

len = 45
inc = float(.1)

if y >= len:
    y *= -inc
print (y)

Solution

  • First of all, don't call a variable len, because it is a name of standard library function. If I understood the question correctly, the code would be

    threshold = 45
    inc = .1
    y = 0
    
    while True:  # goes forever, put your own code here
        if y >= threshold:
            inc *= -1
        y += inc
        print (y)
    

    After y reaches 45, it start counting down. No stop condition when you count down though, it's an infinite cycle here