Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. import ddf.minim.*;
  2. import ddf.minim.analysis.*;
  3.  
  4. Minim minim;
  5. AudioPlayer song;
  6. BeatDetect beat;
  7.  
  8. float bottomSpeed = random(1.0);
  9. float topSpeed = random(1.0);
  10.  
  11. int t = 0;
  12.  
  13. color[] COLORS = {
  14. color(255, 0, 0),
  15. color(255, 255, 0),
  16. color(0, 255, 0),
  17. color(0, 255, 255),
  18. color(0, 0, 255),
  19. color(255, 0, 255)
  20. };
  21.  
  22. boolean leftShape = true;
  23.  
  24. int leftOpacity = 0;
  25. int leftTopPos = 0;
  26. int leftBottomPos = 0;
  27. color leftCurrentColor = COLORS[(int) random(COLORS.length)];
  28.  
  29. int rightOpacity = 0;
  30. int rightTopPos = 0;
  31. int rightBottomPos = 0;
  32. color rightCurrentColor = COLORS[(int) random(COLORS.length)];
  33.  
  34.  
  35. void setup() {
  36. fullScreen();
  37. minim = new Minim(this);
  38. song = minim.loadFile("/Users/timco/Music/The Necks - Body/The Necks - Body - 01 Body.mp3", 2048);
  39. song.play();
  40. beat = new BeatDetect();
  41.  
  42. }
  43.  
  44. void draw() {
  45.  
  46. beat.detect(song.mix);
  47. if(beat.isOnset()) {
  48. if(leftShape) {
  49. leftBottomPos = floor(width /2 + sin(bottomSpeed*t) * width / 2);
  50. leftTopPos = floor(width / 2 + sin(topSpeed*t) * width / 2);
  51. leftCurrentColor = COLORS[(int) random(COLORS.length)];
  52. leftOpacity = 255;
  53. } else {
  54. rightBottomPos = floor(width /2 + cos(bottomSpeed*t) * width / 2);
  55. rightTopPos = floor(width / 2 + cos(topSpeed*t) * width / 2);
  56. rightCurrentColor = COLORS[(int) random(COLORS.length)];
  57. rightOpacity = 255;
  58. }
  59.  
  60. leftShape = !leftShape;
  61.  
  62. }
  63. background(0);
  64. fill(leftCurrentColor, leftOpacity);
  65. beginShape();
  66. vertex(0, 0);
  67. vertex(leftTopPos, 0);
  68. vertex(leftBottomPos, height);
  69. vertex(0, height);
  70. endShape(CLOSE);
  71. fill(rightCurrentColor, rightOpacity);
  72. beginShape();
  73. vertex(rightTopPos, 0);
  74. vertex(width, 0);
  75. vertex(width, height);
  76. vertex(rightBottomPos, height);
  77. endShape(CLOSE);
  78. t++;
  79. leftOpacity *= 0.95;
  80. rightOpacity *= 0.95;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement