Functions affect each other?
in
Programming Questions
•
1 year ago
So I did two functions in my code, one is the thing moving in circular motion, another one is moving in a wave form. I don't want the alien1 function to redraw the background, but I do want the alien2 function does. But looks like they are always affecting each other. Any solutions? Thanks!!!!
float x1;
float y1;
float x2;
float y2;
float r1 = 100;
float rc = 20;
float rc1 = 10;
float theta = 0;
float[] rs = new float[5];
float[] gs = new float[5];
float[] bs = new float[5];
int i = 10;
int j = 0;
int k = 100;
void setup(){
smooth();
size(400,400);
background(33,33,200);
for (int i = 0; i <rs.length; i ++){
rs[i] = random(0,255);
}
for (int j = 0; j <gs.length; j ++){
gs[j] = random(0,255);
}
for(int k = 0; k <bs.length; k ++){
bs[k] = random(0,255);
}
}
void draw(){
alien1();
alien2();
}
void alien1(){
translate(width/2,height/2);
background(33,33,150);
float x1 = r1 * cos(theta);
float y1 = r1 * sin(theta);
stroke(0);
fill(255);
triangle(x1,y1-1.5*rc1,x1-1.5*rc1,y1+0.75*rc1,x1+1.5*rc1,y1+0.75*rc1);
stroke(0);
fill(255,20,20);
ellipse(x1,y1,rc1*2,rc1*2);
stroke(0);
point(x1,y1);
theta += 0.05;
}
void alien2(){
translate(-width/2,0);
x2+=2;
float y2 = cos(theta)*height/2;
stroke(i,j,k);
fill(255);
triangle(x2,y2-1.5*rc,x2-1.5*rc,y2+0.75*rc,x2+1.5*rc,y2+0.75*rc);
stroke(i*20,j*2,k*40);
fill(i*20,j*2,k*40);
ellipse(x2,y2,rc*2,rc*2);
stroke(0);
point(x2,y2);
theta +=0.01;
if(x2 > width){
i = (i+6) % rs.length ;
j = (j+6) % gs.length;
k = (k+6) % bs.length;
x2 = 0;
alien2();
}
}
1