Hello,
i want to learn python so i thought begin with remaoing numbers cause when iam using it in gh i need mostly the remap,bounds and create domain so i tought it would be possible doing it in one python component. i found some code and it gets me no error message but neither an solution.
Maybe someone is willed to help me?
the code i put is:
def remap( x, oMin, oMax, nMin, nMax ):
#range check
if oMin == oMax:
print "Warning: Zero input range"
return None
if nMin == nMax:
print "Warning: Zero output range"
return None
#check reversed input range
reverseInput = False
oldMin = min( oMin, oMax )
oldMax = max( oMin, oMax )
if not oldMin == oMin:
reverseInput = True
#check reversed output range
reverseOutput = False
newMin = min( nMin, nMax )
newMax = max( nMin, nMax )
if not newMin == nMin :
reverseOutput = True
portion = (x-oldMin)*(newMax-newMin)/(oldMax-oldMin)
if reverseInput:
portion = (oldMax-x)*(newMax-newMin)/(oldMax-oldMin)
result = portion + newMin
if reverseOutput:
result = newMax - portion
return result
print result
a = result
thanks in advance!
Chapulin Colorado
i have another question,
if i want to do it like the gh component, to access the min and max values, i input the domain, how can i acces these values? is it like a list?would it be the first and second item? how would be the procedure?
thanks in advance!
Oct 7, 2016
Daniel González Abalde
You have to set the type of object that collects all parameter.
Set Type Hint to Interval.
Oct 7, 2016
Anders Holden Deleuran
Here's the function I usually use to generate color gradients, it demonstrates a similar method for remapping values. Might help as well :)
Oct 8, 2016