class Draggable { boolean dragging = false; // Is the object being dragged? float x, y, r; // Location and size color c1, c2; float offsetX, offsetY; // Mouseclick offset float timer; boolean is_floating; String s; FFT song; float[] values; float extra; Draggable(float tempX, float tempY, float tempR, color mc1, color mc2, boolean floating, String text, FFT _song) { x = tempX; y = tempY; r = tempR; c1 = mc1; c2 = mc2; offsetX = 0; offsetY = 0; is_floating = floating; timer = int(random(50)); s = text; song = _song; values = new float[song.specSize()]; extra = 0; } // Method to display void display() { stroke(0); if (dragging) { fill(c1); noStroke(); } else { fill(c2); noStroke(); } for (int i = 0; i < song.specSize(); i++) { values[i] = song.getBand(i); } extra = max(values) * 2; if (extra > 100) { extra = 100; } ellipse(x, y, r + extra, r + extra); ellipse(x, y, r, r); if (is_floating == true) { timer += 0.1; y += (sin(timer)); x += (cos(timer)); } fill(0); textFont(champagne, 32); textAlign(CENTER, CENTER); text(s, x, y); textAlign(LEFT, BASELINE); if (x < 0) { x = 0; } if (x > width) { x = width; } if (y < 0) { y = 0; } if (y > height) { y = height; } if (act == 1) { for (int i = 0; i < fireflylist.size(); i++) { Draggable myLight = (Draggable) fireflylist.get(i); if (dist(x, y, myLight.x, myLight.y) < 100 && (dist(x, y, myLight.x, myLight.y) != 0)) { if (x > myLight.x) { x += 1; } else { x -= 1; } if (y > myLight.y) { y += 1; } else { y -= 1; } } else { x += 0; } } } if (act == 2) { for (int i = 0; i < oceanlist.size(); i++) { Draggable myBubble = (Draggable) oceanlist.get(i); if (dist(x, y, myBubble.x, myBubble.y) < 100 && (dist(x, y, myBubble.x, myBubble.y) != 0)) { if (x > myBubble.x) { x += 1; } else { x -= 1; } if (y > myBubble.y) { y += 1; } else { y -= 1; } } else { x += 0; } } } if (act == 3) { for (int i = 0; i < cavelist.size(); i++) { Draggable myMetro = (Draggable) cavelist.get(i); if (dist(x, y, myMetro.x, myMetro.y) < 100 && (dist(x, y, myMetro.x, myMetro.y) != 0)) { if (x > myMetro.x) { x += 1; } else { x -= 1; } if (y > myMetro.y) { y += 1; } else { y -= 1; } } else { x += 0; } } } if (act == 4) { for (int i = 0; i < stormlist.size(); i++) { Draggable myCloud = (Draggable) stormlist.get(i); if (dist(x, y, myCloud.x, myCloud.y) < 100 && (dist(x, y, myCloud.x, myCloud.y) != 0)) { if (x > myCloud.x) { x += 1; } else { x -= 1; } if (y > myCloud.y) { y += 1; } else { y -= 1; } } else { x += 0; } } } if (act == 5) { for (int i = 0; i < nightlist.size(); i++) { Draggable myShadow = (Draggable) nightlist.get(i); if (dist(x, y, myShadow.x, myShadow.y) < 100 && (dist(x, y, myShadow.x, myShadow.y) != 0)) { if (x > myShadow.x) { x += 1; } else { x -= 1; } if (y > myShadow.y) { y += 1; } else { y -= 1; } } else { x += 0; } } } if (act == 6) { for (int i = 0; i < marketlist.size(); i++) { Draggable mySun = (Draggable) marketlist.get(i); if (dist(x, y, mySun.x, mySun.y) < 100 && (dist(x, y, mySun.x, mySun.y) != 0)) { if (x > mySun.x) { x += 1; } else { x -= 1; } if (y > mySun.y) { y += 1; } else { y -= 1; } } else { x += 0; } } } } // Is a point inside the rectangle (for click)? void clicked(int mx, int my) { if (dist(x, y, mx, my)<(r/2)) { dragging = true; // If so, keep track of relative location of click to corner of rectangle offsetX = x-mx; offsetY = y-my; } } // Stop dragging void stopDragging() { dragging = false; } // Drag the rectangle void drag(int mx, int my) { if (dragging) { x = mx + offsetX; y = my + offsetY; } } }