Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. local function make_beat_wave(params)
  2. -- triangle wave - n results in the section above zero having width 1-n
  3. -- so triangle - (1-w) will give us width w
  4. -- time_wave_input is doubled and offset to put a peak on every beat.
  5. local triangle= {'triangle', {'+', .5, {'*', 2, params.time}}}
  6. local above_zero_is_width= {'-', triangle, {'-', 1, params.width}}
  7. -- height above zero needs to be 1, but is currently w.
  8. -- <result> / w will make the height 1
  9. local height_is_one= {'/', above_zero_is_width, params.width}
  10. -- then max is used to clip off the parts of the wave that are below
  11. -- zero, and we have a wave that is flat between peaks.
  12. local beat_wave= {'max', 0, height_is_one}
  13. local curved_wave= {'^', beat_wave, 2}
  14. return curved_wave
  15. end
  16.  
  17. local function asymmetric_scaler(scale, time)
  18. return {'+', scale-1, {'*', scale, {'square', time}}}
  19. end
  20.  
  21. local function shift_and_scale(thing, old_low, old_high, low, high)
  22. local old_size= old_high - old_low
  23. local new_size= high - low
  24. local scale_factor= new_size / old_size;
  25. return {'+', low, {'*', scale_factor, {'-', thing, old_low}}}
  26. end
  27.  
  28. local custom_mods= {
  29. pound= {
  30. target= 'note_pos_x',
  31. equation= function(params, ops)
  32. local curved_wave= make_beat_wave{
  33. time= params.time,
  34. width= {'-', 1, make_beat_wave{time= params.time, width= .5}},
  35. }
  36. local inverter= {'square', {'+', .5, params.time}}
  37. local time_beat_factor= {'*', curved_wave, 20, inverter}
  38. -- On even beats, period will be 1 at the start of the animation,
  39. -- then go to 0 as the animation peaks.
  40. -- On odd beats, period will be 1 at the start, then go to 16 as the
  41. -- animation peaks.
  42. local period= {
  43. '-', 1,
  44. {'*', -1, asymmetric_scaler(17, {'+', .5, params.time}),
  45. make_beat_wave{time= params.time, width= .5},
  46. }
  47. }
  48. local note_beat_factor= check_op{
  49. ops.wave,
  50. {'+', params.wave_offset,
  51. pi_div{'/',
  52. params.note_input,
  53. {'*', period, params.period},
  54. },
  55. },
  56. }
  57. local time_and_beat= check_op{ops.factor, time_beat_factor, note_beat_factor}
  58. local equation= check_op{ops.level, params.level, time_and_beat}
  59. return equation
  60. end,
  61. params= {
  62. level= 1, note_input= 'y_offset', wave_offset= .5, period= 15,
  63. time= 'music_beat', width= .5,
  64. },
  65. ops= {
  66. level= '*', factor= '*', wave= 'sin',
  67. },
  68. },
  69. }
  70.  
  71. local pound_params= {
  72. level= 4,
  73. -- slowing down time makes the animation visible.
  74. -- Applying a beat wave to the time slowdown makes it crazy.
  75. time= {mult= shift_and_scale(make_beat_wave{time= {'*', 'music_beat', .0625}, width= .5}, 0, 1, .25, 1)},
  76. note_input= {'^', 'y_offset', .75},
  77. wave_offset= {
  78. m= {'triangle', 'music_beat'},
  79. a= shift_and_scale(make_beat_wave{time= {'*', 'music_beat', .125}, width= .5}, 0, 1, -.5, 1.5)},
  80. }
  81.  
  82. local mods= {
  83. columns= 4,
  84. {column= "all", start= 0, length= 256, 'pound', pound_params},
  85. }
  86.  
  87. return mods, custom_mods
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement