<s> """<STR_LIT>""" <EOL> from __builtin__ import round as _round <EOL> import math <EOL> def conjugate ( x ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( x , complex ) : <EOL> return x . conjugate ( ) <EOL> else : <EOL> return x <EOL> def real ( x ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( x , complex ) : <EOL> return x . real <EOL> else : <EOL> return x <EOL> def imag ( x ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( x , complex ) : <EOL> return x . imag <EOL> else : <EOL> return type ( x ) ( <NUM_LIT:0> ) <EOL> def round ( value , ndigits = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> ndigits = int ( ndigits ) <EOL> if isinstance ( value , complex ) : <EOL> return complex ( _round ( value . real , ndigits ) , _round ( value . imag , ndigits ) ) <EOL> else : <EOL> return _round ( value , ndigits ) <EOL> def gamma ( c , g ) : <EOL> """<STR_LIT>""" <EOL> return c ** g <EOL> def blend ( a , b , weight = <NUM_LIT:0.5> ) : <EOL> """<STR_LIT>""" <EOL> return a * ( <NUM_LIT:1.0> - weight ) + b * weight <EOL> def smoothmap ( min , max , x ) : <EOL> """<STR_LIT>""" <EOL> x = float ( x ) <EOL> x = float ( x - min ) / float ( max - min ) <EOL> return x * x * ( <NUM_LIT> - <NUM_LIT> * x ) <EOL> def smoothstep ( min , max , x ) : <EOL> """<STR_LIT>""" <EOL> if x < min : <EOL> return <NUM_LIT:0.0> <EOL> if x > max : <EOL> return <NUM_LIT:1.0> <EOL> return smoothmap ( min , max , x ) <EOL> def linmap ( min , max , x ) : <EOL> """<STR_LIT>""" <EOL> return ( float ( x ) - min ) / ( max - min ) <EOL> def linstep ( min , max , x ) : <EOL> """<STR_LIT>""" <EOL> if x < min : <EOL> return <NUM_LIT:0.0> <EOL> if x > max : <EOL> return <NUM_LIT:1.0> <EOL> return linmap ( min , max , x ) <EOL> def clamp ( x = <NUM_LIT:0.0> , min = <NUM_LIT:0.0> , max = <NUM_LIT:1.0> ) : <EOL> """<STR_LIT>""" <EOL> if min < max : <EOL> realmin = min <EOL> realmax = max <EOL> else : <EOL> realmin = max <EOL> realmax = min <EOL> if x < realmin : <EOL> result = realmin <EOL> elif x > realmax : <EOL> result = realmax <EOL> else : <EOL> result = x <EOL> return result <EOL> def setRange ( x = <NUM_LIT:0.0> , oldmin = <NUM_LIT:0.0> , oldmax = <NUM_LIT:1.0> , newmin = <NUM_LIT:0.0> , newmax = <NUM_LIT:1.0> ) : <EOL> """<STR_LIT>""" <EOL> if oldmin < oldmax : <EOL> realoldmin = oldmin <EOL> realoldmax = oldmax <EOL> realnewmin = newmin <EOL> realnewmax = newmax <EOL> elif oldmin > oldmax : <EOL> realoldmin = oldmax <EOL> realoldmax = oldmin <EOL> realnewmin = newmax <EOL> realnewmax = newmin <EOL> else : <EOL> return x <EOL> if x < realoldmin : <EOL> result = realnewmin <EOL> elif x > realoldmax : <EOL> result = realnewmax <EOL> else : <EOL> result = ( realnewmin + ( realnewmax - realnewmin ) * ( x - oldmin ) / ( oldmax - oldmin ) ) <EOL> return result <EOL> def hermiteInterp ( x = <NUM_LIT:0.0> , y0 = <NUM_LIT:0.0> , y1 = <NUM_LIT:1.0> , s0 = <NUM_LIT:0.0> , s1 = <NUM_LIT:0.0> ) : <EOL> """<STR_LIT>""" <EOL> c = s0 <EOL> v = y0 - y1 <EOL> w = c + v <EOL> x = w + v + s1 <EOL> b_neg = w + x <EOL> return ( ( ( ( x * x ) - b_neg ) * x + s0 ) * x + y0 ) <EOL> def hermite ( x = <NUM_LIT:0.0> , v0 = <NUM_LIT:0.0> , v1 = <NUM_LIT:0.0> , s0 = <NUM_LIT:0.0> , s1 = <NUM_LIT:0.0> ) : <EOL> """<STR_LIT>""" <EOL> if x < <NUM_LIT:0.0> : <EOL> res = v0 <EOL> elif x > <NUM_LIT:1.0> : <EOL> res = v1 <EOL> else : <EOL> res = hermiteInterp ( x , v0 , v1 , s0 , s1 ) <EOL> return res </s>
