Advertisement
Guest User

Processing Winnie

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1.  
  2. //PRE-SETUP//
  3.  
  4. //mic_minim//
  5. import ddf.minim.*;
  6. Minim minim;
  7. AudioInput in;
  8.  
  9. float volumeIn; //Input value × 1000
  10. float d; //diameter
  11. float sa; //The difference between the input value × 1000 and the current diameter
  12. float easing = 0.1; //The easing coefficient, large numerical value changes greatly
  13. PImage head;
  14. //array//
  15. ArrayList p;
  16. int move = 0;
  17. float speed = 0.2;
  18. float accel = 1.01;
  19.  
  20. //VOID SETUP//
  21. void setup()
  22. {
  23.  
  24. //mic_setup//
  25.   size(1280, 800);
  26.   minim = new Minim(this);
  27.   in = minim.getLineIn(Minim.MONO, 512);
  28.   fill(200,0,20,100);
  29.  
  30.   //img_setup1//
  31.   PImage head;
  32.   head = loadImage("doge.png");
  33.  
  34. //array_setup//
  35. int x, y;
  36.  color a;
  37.   frameRate(60);
  38.   background(0); // !!!! Do i have to state the backround here? !!!!
  39.  
  40.   //img_setup_for_array//
  41.   image(head,width/2,height/2); // /!!!Do i have to state the position here? !!!!
  42.   imageMode(CENTER);
  43.  
  44.  
  45.  a=color(0);
  46.   p = new ArrayList();
  47.   for (x=0; x<width; x=x+1) {
  48.     for (y=0; y<height; y=y+1) {
  49.       if (get(x, y)!=a) {
  50.         p.add(new pxl (x, y, random(-speed, speed), random(-speed, speed), get(x, y)));
  51.       }
  52.     }
  53.   }
  54. }  
  55.  
  56. /// VOID_DRAW///
  57.  
  58. void draw() {
  59.  
  60.   //mic_draw//
  61.    volumeIn = map(in.left.level(), 0, 0.5, 0, width*2); /// Convert input value to 0 to 500
  62.   sa = volumeIn - d; //difference between the input value and the current diameter
  63.   if(abs(sa) > 1) { //change the diameter only when the absolute value of the difference is greater than 1
  64.     d = d + sa * easing; //0.1 min change in difference
  65.   }
  66.   image (head,width/2,height/2,d,d); // image size depends on the diameter
  67.  
  68.   int i;
  69.   pxl a;
  70.   background(0); // !!! Do i have to state the backround here again --not sure !!!
  71.   for (i=0; i<p.size(); i=i+1) {
  72.     a = (pxl) p.get(i);
  73.     a.update(move);
  74.   }
  75. }
  76.  
  77. /// CLASS_PIXEL///
  78. class pxl {
  79.   float xspeed, yspeed;
  80.   float x, y;
  81.   color p;
  82.  
  83.   pxl (int a, int b, float c, float d, color e) {  
  84.     x = float(a);
  85.     y = float(b);
  86.     xspeed = c;
  87.     yspeed = d;
  88.     p = e;
  89.   }
  90.  
  91. /// VOID_UPDATE///
  92.   void update(int move) {   // how its exploded
  93.     if (move==1) {
  94.       xspeed=xspeed*accel;
  95.       yspeed=yspeed*accel;
  96.       x = x + xspeed;  
  97.       y = y + yspeed;
  98.     }
  99.     set(int(x), int(y), p);
  100.   }
  101. }
  102.  
  103. void explode() { // !!! I want to a statement that the picture should be exploded, if the picture radius/pixel   more than 500 x 500 px
  104.   if (head = 500,500) {
  105.     move = 1;
  106.   }
  107. }
  108.  
  109. void mousePressed() {
  110.   redraw();
  111. }
  112.  
  113. void stop() {
  114.   in.close();
  115.   minim.stop();
  116.   super.stop();
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement