SlavaCat

Equation to LFO

Mar 11th, 2021 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.34 KB | None | 0 0
  1. import numpy
  2. import math as m
  3.  
  4. #!!! CHANGE THESE !!!----------------------------------------------------------
  5. AUTHOR = 'SlavaCat'
  6. NAME = 'MATH LFO >:O'
  7. X_RANGE = [-5,5] #DISTANCE BETWEEN * RESOLUTION MUST BE <= 100 ALSO NO DECIMALS
  8. #Number of subdivisions between points | 1 = none                              
  9. RESOLUTION = 5
  10. #How many decimals to round to
  11. ROUND_RANGE = 3
  12.  
  13. def equation(x_pos):
  14.     #!!! ADD VARIABLES HERE X IS DEFAULT !!!                                  
  15.     x = x_pos
  16.     #!!! INSTER EQUATION HERE | ADD 'm.' BEFORE OPPERATION !!!          
  17.     y = m.tan(x)
  18.     #!!! OK STOP CHANGING THINGS >:( !!!                                    
  19.     return y
  20. #------------------------------------------------------------------------------
  21.  
  22. VITAL_RANGE = [0,1]
  23.  
  24. def scale_toRange(unscaled,range_start,range_end):
  25.     unscaled = numpy.ndarray.tolist(numpy.interp(unscaled, (min(unscaled), max(unscaled)), (range_start,range_end)))
  26.     return unscaled
  27.  
  28. def round_list(unrounded,round_amount):
  29.     for x in range(len(unrounded)):
  30.         unrounded[x] = round(unrounded[x],ROUND_RANGE)
  31.     return unrounded
  32.  
  33. #Set points
  34. POINTS = (abs(X_RANGE[0]-X_RANGE[1])*RESOLUTION)
  35. powers = []
  36. for n in range(POINTS):
  37.     powers.append(0)
  38. if POINTS >= 200:
  39.     print("!!!WARNING!!! THIS MANY POINTS COULD CRASH VITAL !!!WARNING!!!\n")
  40.  
  41. #Creating the x_values
  42. x_values = []
  43. for x in range((X_RANGE[0]*RESOLUTION),(X_RANGE[1]*RESOLUTION)):
  44.     x_values.append(x)
  45.  
  46. #Scaling the values back to range
  47. x_values = scale_toRange(x_values,X_RANGE[0],X_RANGE[1])
  48.  
  49. #Creating y_values from equation
  50. y_values = []
  51. for x_pos in range(POINTS):
  52.     x = x_values[x_pos]
  53.     y_values.append(equation(x))
  54.  
  55. #Scaling x to the Vital range of (0,1)
  56. x_values = scale_toRange(x_values,VITAL_RANGE[0],VITAL_RANGE[1])
  57. x_values = round_list(x_values,ROUND_RANGE)
  58.  
  59. #Again scaling y to Vital range
  60. y_values = scale_toRange(y_values,VITAL_RANGE[0],VITAL_RANGE[1])
  61. y_values = round_list(y_values,ROUND_RANGE)
  62.  
  63. #Combine
  64. LFO_points = []
  65. for x in range(POINTS):
  66.     LFO_points.extend((x_values[x],y_values[x]))
  67. paste = '{' + (f'"author":"{AUTHOR}","name":"{NAME}","num_points":{POINTS},"points":{LFO_points},"powers":{powers},"smooth":false') + '}'
  68. print(paste)
  69. print('\n')
  70. if POINTS > 100:
  71.     print('You have too many points, results might not be as expected :/')
  72.  
  73. #CREATED BY SLAVACAT: https://soundcloud.com/slavacat
Add Comment
Please, Sign In to add comment