Advertisement
leeloptimist

lopti-slider v0.6

Feb 26th, 2018
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. autowatch = 1;
  2. outlets = 1;
  3. mgraphics.init();
  4. mgraphics.relative_coords = 0;
  5. mgraphics.autofill = 0;
  6. mgraphics.redraw();
  7.  
  8. var m = mgraphics;
  9. var jsui_width = box.rect[2] - box.rect[0];
  10. var jsui_height = box.rect[3] - box.rect[1];
  11. var display_ratio = jsui_width / jsui_height;
  12. var hidden_voice = 1000;
  13. var voice = 8;
  14. var drag_zone = 100;
  15. var space = 0;
  16. var note_height = jsui_height / voice;
  17. var each_y = [];
  18. var each_start = [];
  19. var each_end = [];
  20. var each_width = [];
  21. var R = [];
  22. var G = [];
  23. var B = [];
  24.  
  25. for (i = 0; i < hidden_voice; i++){ //init.
  26. each_y[i] = (jsui_height - note_height) - (note_height * i);
  27. each_start[i] = 0;
  28. each_end[i] = jsui_width;
  29. each_width[i] = each_end[i] - each_start[i];
  30. R[i] = Math.random();
  31. G[i] = Math.random();
  32. B[i] = Math.random();
  33. }
  34.  
  35. function voice_number(n){ //voice change
  36. each_y = [];
  37. voice = n;
  38. note_height = jsui_height / voice;
  39. for (i = 0; i < voice; i++){
  40. each_y[i] = (jsui_height - note_height) - (note_height * i);
  41. }
  42. outlet_maker();
  43. m.redraw();
  44. }
  45.  
  46. function outlet_maker(){ // make new array for outlet
  47. for (i = 0; i < voice; i++){
  48. var start = each_start[i] / jsui_width;
  49. var end = each_end[i] / jsui_width;
  50. var length = each_width[i] / jsui_width;
  51. outlet(0, i, start, end, length);
  52. }
  53. }
  54.  
  55.  
  56. function ondrag(x, y){ //drag
  57. if ( x >= 0 && x <= jsui_width && y >= 0 && y <= jsui_height){
  58. for (i = 0; i < voice; i++){
  59. if (y > each_y[i] && y < each_y[i] + note_height && x > each_start[i] - drag_zone && x < each_start[i] + drag_zone && x < each_end[i] - drag_zone){
  60. each_start[i] = x;
  61. each_width[i] = each_end[i] - each_start[i];
  62. }
  63. }
  64. }
  65. if ( x >= 0 && x <= jsui_width && y >= 0 && y <= jsui_height){
  66. for (i = 0; i < voice; i++){
  67. if (y > each_y[i] && y < each_y[i] + note_height && x > each_end[i] - drag_zone && x < each_end[i] + drag_zone && x > each_start[i] + drag_zone){
  68. each_end[i] = x;
  69. each_width[i] = each_end[i] - each_start[i];
  70. }
  71. }
  72. }
  73. outlet_maker();
  74. m.redraw();
  75. }
  76.  
  77. function random_note(){ // note randomizer
  78. for (i = 0; i < voice; i++){
  79. each_start[i] = Math.floor(Math.random() * jsui_width);
  80. each_end[i] = Math.floor(Math.random() * (jsui_width - each_start[i])) + each_start[i];
  81. each_width[i] = each_end[i] - each_start[i];
  82. }
  83. outlet_maker();
  84. m.redraw();
  85. }
  86.  
  87. function random_start(){ //note start randomizer
  88. for (i = 0; i < voice; i++){
  89. each_start[i] = Math.floor(Math.random() * each_end[i]);
  90. each_width[i] = each_end[i] - each_start[i];
  91. each_end[i] = each_start[i] + each_width[i];
  92. }
  93. outlet_maker();
  94. m.redraw();
  95. }
  96.  
  97. function random_end(){ //end randomizer
  98. for (i = 0; i < voice; i++){
  99. each_width[i] = Math.floor((Math.random() * (jsui_width - each_start[i])))
  100. each_end[i] = each_start[i] + each_width[i];
  101. }
  102. outlet_maker();
  103. m.redraw();
  104. }
  105.  
  106. function clear_note(){ //clear note
  107. for (i = 0; i < hidden_voice; i++){
  108. each_start[i] = 0;
  109. each_end[i] = jsui_width;
  110. each_width[i] = each_end[i] - each_start[i];
  111.  
  112. }
  113. outlet_maker();
  114. m.redraw();
  115. }
  116.  
  117. function space_value(n){
  118. if (n >= 0 && n <= 10){
  119. space = n;
  120. }
  121. m.redraw();
  122. }
  123.  
  124. function paint(){ //draw
  125. for (i = 0; i < voice; i++){
  126. m.set_source_rgba(R[i], G[i], B[i], 0.8);
  127. m.rectangle(each_start[i], each_y[i] + space, each_width[i], note_height - space);
  128. m.fill();
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement