class BBox {
int x;
int y;
color c;
float GRAVITY;
BBox (int xx,int yy, int cc ) {
x = xx;
y = yy;
c = cc;
GRAVITY= random(0.9);
}
}
int Lbox;
int boxnum = 100 ;
int next =0 ;
import ddf.minim.*;
int o=0;
float v=0;
float[] x_1 = new float[50];
float[] y_1 = new float[50];
float segLength = 10;
AudioPlayer player;
Minim minim;
BBox BB[][]=new BBox[boxnum][boxnum];
void mousePressed() {
for (int xx = 0; xx < boxnum; xx++)
{
for (int yy = 0; yy < boxnum;yy++)
{
if (next==0) {
BB[xx][yy].c = color(random(256), random(256), random(256));
}
else {
BB[xx][yy].c = color(random(256));
}
}
}
if (next==0)
{
next=1;
}
else {
next=0;
}
}
void setup()
{
minim = new Minim(this);
player = minim.loadFile("Sleep Away.mp3", 2048);
player.loop();
for (int xx = 0; xx < boxnum; xx++)
{
for (int yy = 0; yy < boxnum;yy++)
{
BB[xx][yy]=new BBox(yy*22, xx*22, color(random(256)));
}
}
size(560, 760);
smooth();
stroke(0, 100);
}
void draw() {
background(250);
stroke(0);
for (int i = 0; i < player.left.size()-1; i++)
{
line(i, 50 + player.left.get(i)*100, i+1, 50 + player.left.get(i+1)*50);
line(i, 150 + player.right.get(i)*100, i+1, 150 + player.right.get(i+1)*50);
line(i, 250 + player.right.get(i)*100, i+1, 250 + player.right.get(i+1)*50);
}
if (next== 0) {
o++;
}
else {
o=0;
}
for (int xx = 0; xx < boxnum; xx++)
{
for (int yy = 0; yy < boxnum;yy++)
{
boolean P=true;
for (int a=0; a<x_1.length-1; a++) {
if ( abs(x_1[a]-BB[xx][yy].x)<10&&abs(y_1[a]-BB[xx][yy].y)<10)
{
P=false;
}
}
if (next==0) {
fill (BB[xx][yy].c);
v=BB[xx][yy].GRAVITY*o*o/2;
if (P) {
rect (BB[xx][yy].x, BB[xx][yy].y+v, 10, 10);
}
}
else
{
float x =random( -player.left.get(0)*5, player.left.get(0)*5);
float y = random( -player.left.get(0)*5, player.left.get(0)*5);
fill (BB[xx][yy].c);
if (P) {
rect (BB[xx][yy].x+x, BB[xx][yy].y+y, 10, 10);
}
}
}
}
strokeWeight(5);
dragSegment(0, mouseX, mouseY);
for (int i=0; i<x_1.length-1; i++) {
dragSegment(i+1, x_1[i], y_1[i]);
}
strokeWeight(1);
}
void dragSegment(int i, float xin, float yin) {
float dx = xin - x_1[i];
float dy = yin - y_1[i];
float angle = atan2(dy, dx);
x_1[i] = xin - cos(angle) * segLength;
y_1[i] = yin - sin(angle) * segLength;
segment(x_1[i], y_1[i], angle);
}
void segment(float x, float y, float a) {
pushMatrix();
translate(x, y);
rotate(a);
line(0, 0, segLength, 0);
popMatrix();
}