Pushmatrix() error
in
Programming Questions
•
6 months ago
So basically I'm writing a sketch that has rings "ripple" outwards in beat with the music and then changing colour and number and size at random points everything was going fine until I added in the last "if" function on each of the different rings. Then I started being told "Pushmatrix() can't be called more than 32 times". I'm really confused.
If you can understand my really bad coding then any help you can give would be appreciated.
If you can understand my really bad coding then any help you can give would be appreciated.
- int sizeX;
int sizeY;
int mins;
int bufferSize = 512;
int fftSize = floor(bufferSize*.5f)+1;
int value;
int value2;
int value3;
int value4;
int value5;
int value6;
int value7;
int time;
float r, g, b, a; //red,green,blue,alpha variables
float diam, x, y; //diameter,x&y position
import ddf.minim.*;
import ddf.minim.analysis.*;
AudioPlayer player, player1;
Minim minim;
FFT fft;
void setup(){
smooth(); //smooth shapes
int l = 0;
// translate (500,350);
size(1000,700);
background(188,188,188);
ellipseMode(CENTER);
sizeX = 60;
sizeY = 30;
minim = new Minim(this);
player = minim.loadFile("Psydub.mp3");
player.play();
fft=new FFT(player.bufferSize(), player.sampleRate());
}
void draw(){
fft.forward(player.mix);
mins = millis()/1000;
fill(0,0,0,5);
rect(0,0,width,height);
Rain();
Rain35();
Rain15();
rainMore();
time = millis()/1000;
}
void Rain(){
smooth();
noFill();
value = upDownCounter(255, 2);
value4 = upDownCounter(255, 5);
for (int i = 0; i < fftSize; i++) {
float band = fft.getBand(i);
stroke(value4,0,0,random(255));
strokeWeight(random(8));
pushMatrix();
rotate(radians(15));
if(time > 138){
stroke(value4,value5,value6,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
}else if(time > 82){
stroke(value4,value5,value6,random(100));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
stroke(value4,0,0,random(255));
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
stroke(0,205,205,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else {if(time > 55){
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
stroke(0,205,205,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
}else if(time > 27){
ellipse(825,250, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else {
ellipse(500, 250, i*(band/5),i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
sizeX = 60;
sizeY = 30;
}
}
}
}
void Rain35(){
smooth();
noFill();
value3 = upDownCounter(255, 3);
value5 = upDownCounter(255, 8);
for (int i = 0; i < fftSize; i++) {
float band = fft.getBand(i);
stroke(255,value5,255,random(255));
strokeWeight(random(8));
pushMatrix();
rotate(radians(15));
if(time > 138){
stroke(value3,value4,value5,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
if(time > 82){
stroke(value3,value4,value5,random(100));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
stroke(value4,0,0,random(255));
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
stroke(0,205,205,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else if(time > 55){
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
stroke(0,235,235,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else if(time > 27){
ellipse(100,525, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
}else{ ellipse(500, 250, i*(band/value3),i*(band/value3));
sizeX+=10;
sizeY+=5;
popMatrix();
sizeX = 60;
sizeY = 30;
popMatrix();
}
}
}
}
void Rain15(){
smooth();
noFill();
value2 = upDownCounter(255, 1);
value6 = upDownCounter(225, 13);
for (int i = 0; i < fftSize; i++) {
float band = fft.getBand(i);
stroke(255,255,value6,random(255));
strokeWeight(random(8));
pushMatrix();
rotate(radians(15));
if(time > 138){
stroke(value2,value3,value6,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
if(time > 82){
stroke(value2,value3,value6,random(100));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
stroke(value4,0,0,random(255));
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
stroke(0,205,205,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else if(time > 55){
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
stroke(0,255,255,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else { if(time > 27){
ellipse(700,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
}else { ellipse(500, 250, i*(band/value2),i*(band/value2));
sizeX+=10;
sizeY+=5;
popMatrix();
sizeX = 60;
sizeY = 30;
popMatrix();
}
}
}
}
}
void rainMore() {
//generating random numbers for r,g,b,a
value7 = upDownCounter(255, 2);
// if(millis() >
for (int i=0; i<255; i++) {
r=random(200-i);
g=random(200-i);
b=random(200);
a=random(value7);
//generating randoms for diameter,x&y position
diam = random(20);
x = random(width);
y = random(height);
//drawing ellipses
noStroke();
fill(r,g,b,a);
ellipse(x,y,diam,diam);
}
}
int upDownCounter(int maxValue, int factor) {
int doubleMaxValue = 2*maxValue;
int fcd = (frameCount/factor)%doubleMaxValue;
return (fcd<maxValue)?fcd:doubleMaxValue-fcd; // this line is also important!
}
void stop()
{
player.close();
player1.close();
minim.stop();
super.stop();
}
1