Two rectangles messing with each other.
in
Programming Questions
•
6 months ago
Hey guys, I'm currently working on a sketch that has "ripples" beating in time with the music.
This bit works fine but I want to add something else funky into the sketch but when I do so it starts messing around with my "background rectangle" that's just black.
Here's the working sketch...
Here's the bit I want to add...
This bit works fine but I want to add something else funky into the sketch but when I do so it starts messing around with my "background rectangle" that's just black.
Here's the working sketch...
- 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;
int startTime;
int elapsedTime;
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();
startTime = millis()/1000;
elapsedTime = millis()/1000 - startTime;
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 > 219000){
stroke(225, 225, 225, random(225));
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 205500){
stroke(225, 225, 225, 0);
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 192000){
stroke(225, 225, 225, 0);
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 138){
stroke(value4,value5,value6,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
// stroke(value, value5, value3, 20);
// rect(random(1000), random(1000), i*(band*value), i*(band*value));
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;
// popMatrix();
}
}
}}
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 > 205500){
stroke(225, 225, 225, random(225));
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 192000){
stroke(225, 225, 225, 0);
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else { if(elapsedTime > 138){
stroke(value3,value4,value5,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
// stroke(value6, 225, 225, 20);
// rect(random(1000), random(1000), i*(band*value), i*(band*value));
popMatrix();
} else{ 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 > 192000){
stroke(225, 225, 225, random(225));
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 138){
stroke(value,225,0,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
//stroke(value2, value3, value6, 20);
// rect(random(1000), random(1000), i*(band*value), i*(band*value));
popMatrix();
} else { 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);
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);
if(time > 138){
stroke(value2, value3, value6, a);
rect(x, y, diam, diam);
} else{
//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();
}
Here's the bit I want to add...
- int value;
int value2;
int value3;
void setup() {
size(300, 300);
rectMode(CENTER);
smooth();
stroke(30, 40);
fill(255, 100, 50);
}
void draw () {
value = upDownCounter(300, 1);
value2 = upDownCounter(225, 3);
value3 = upDownCounter(225, 5);
background(255);
translate(width / 2, height / 2);
for (int s = 200; s > 0; s = s - 10) {
fill(value, value2 - s, 255 - s);
rotate((value + value) / 300.0);
rect(0, 0, s, s);
}
}
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!
}
I've added another bit for void draw to draw called flower(); and put the relevant parts of the new code into there but when I run it, it makes my background rectangle smaller and things just go a bit odd.
Any ideas guys?
xx
Any ideas guys?
xx
1