Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. # Easing - a collection of static functions to help 1D non-linear interpolations.
  2.  
  3. extends Node
  4.  
  5. class Helper:
  6.     var l
  7.     var target
  8.     var start
  9.     var ease_func
  10.    
  11.     var _t
  12.    
  13.     var progress setget , _get_progress
  14.    
  15.    
  16.     func _init(l, ease_name):
  17.         self.l = l
  18.         self.ease_func = funcref(Easing, ease_name)
  19.         self._t = 0
  20.        
  21.     func is_valid():
  22.         return _t <= l and start != null and target != null
  23.    
  24.     func process(delta):
  25.         self._t += delta
  26.    
  27.     func reset():
  28.         self._t = 0
  29.        
  30.     func _get_progress():
  31.         return ease_func.call_func(_t / l)
  32.    
  33.  
  34. # Utils
  35.  
  36. static func mix(a, b, blend):
  37.     return a + blend * (b - a)
  38.  
  39. # Arch
  40.  
  41. static func arch2(t):
  42.     return t * ( 1 - t)
  43.  
  44. # Smooth Start
  45.  
  46. static func smooth_start2(t):
  47.     return pow(t, 2)
  48.    
  49. static func smooth_start3(t):
  50.     return pow(t, 3)
  51.    
  52. static func smooth_start4(t):
  53.     return pow(t, 4)
  54.    
  55. static func smooth_start5(t):
  56.     return pow(t, 5)
  57.    
  58. # Smooth Stop
  59.    
  60. static func smooth_stop2(t):
  61.     return 1 - pow(1 - t, 2)
  62.  
  63. static func smooth_stop3(t):
  64.     return 1 - pow(1 - t, 3)
  65.  
  66. static func smooth_stop4(t):
  67.     return 1 - pow(1 - t, 4)
  68.  
  69. static func smooth_stop5(t):
  70.     return 1 - pow(1 - t, 5)
  71.  
  72. # Smooth Step
  73.  
  74. static func smooth_step2(t):
  75.     return mix(smooth_start2(t), smooth_stop2(t), t)
  76.  
  77. static func smooth_step3(t):
  78.     return mix(smooth_start3(t), smooth_stop3(t), t)
  79.    
  80. static func smooth_step4(t):
  81.     return mix(smooth_start4(t), smooth_stop4(t), t)
  82.  
  83. static func smooth_step5(t):
  84.     return mix(smooth_start5(t), smooth_stop5(t), t)
  85.    
  86. # Bounce
  87.  
  88. static func bounce_clamp_bottom(t):
  89.     """Bounces off the bottom of the [0,1] range since any negative values are now positive."""
  90.     return abs(t)
  91.  
  92. static func bounce_clamp_top(t):
  93.     """Bounces off the top of the [0,1] range since any values over 1 become inverted below 1."""
  94.     return 1 - abs(1 - t)
  95.    
  96. static func bounce_clamp_bottom_top(t):
  97.     return bounce_clamp_top(bounce_clamp_bottom(t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement