xxxxxxxxxx
int t=0;
float w1=0.01; // TRY different value: 0.1, 0.01, 0.001
float amp1=height/4;
int rad=15;
PVector pos1=new PVector();
PVector pos2=new PVector();
//===========================================================================
// PROCESSING DEFAULT FUNCTIONS:
void settings() {
size(400, 600);
}
void setup() {
textAlign(CENTER, CENTER);
rectMode(CENTER);
fill(255);
strokeWeight(2);
background(0);
}
void draw() {
//background(0); //DISABLE this line to see the accumulated effect
float calcY;
//TOP animation: Continuos sinusoidal
pushMatrix();
translate(0, height/4);
calcY=amp1*sin(w1*millis());
pos1.set(pos1.x+0.5, calcY);
pos2.set(pos1.x, -pos1.y);
fill(255, 0, 0);
ellipse(pos1.x, pos1.y, rad, rad);
ellipse(pos2.x, pos2.y, rad, rad);
popMatrix();
//BOTTOM animation: Steppping in and out aka. center-out
pushMatrix();
translate(0, 3*height/4);
fill(255, 0, 0);
calcY=amp1*sin(w1*millis());
pos1.set(pos1.x+0.5, abs(calcY)>amp1*0.95?amp1:0.0);
pos2.set(pos1.x, -pos1.y);
fill(250, 250, 0);
ellipse(pos1.x, pos1.y, rad, rad);
ellipse(pos2.x, pos2.y, rad, rad);
popMatrix();
if (pos1.x>width) {
pos1.x=0;
background(0);
}
}