xxxxxxxxxx
/************************************************************************
Sketch forked from User 1075 in Sketch 56800
Modified sketch to use PVector class for added flexibility
Changed parameterization of lissajous functions from rectangular to polar
Created a blending feature that maintains a decent contrast level
************************************************************************/
PVector pA, p1, p2, pB;
PVector ps, c1, c2, l1, l2;
float[] an = new float[2];
float[] sn = new float[2];
float[] ap = new float[2];
float[] sp = new float[2];
float[] lp = new float[2];
float speed;
float radi;
int itersPerDraw = 5;
int drawsPerWipe = 20;
int opac = 0;
int bg0 = 50;
int t;
void setup() {
size(750,450);
background(50);
//smooth();
pA = new PVector(width/2, height/4);
pB = new PVector(width/2, height*3/4);
p1 = new PVector(0, 0);
p2 = new PVector(0, 0);
c1 = new PVector(1*width/4, height/2);
c2 = new PVector(3*width/4, height/2);
l1 = new PVector(0, 0);
l2 = new PVector(0, 0);
for (int i = 0; i < 2; i++) {
an[i] = random(TAU);
sn[i] = random(TAU);
ap[i] = random(-0.01, 0.01);
sp[i] = random(-0.01, 0.01);
lp[i] = random(1.0);
}
radi = 300.0;
t = 0;
}
void draw() {
for (int j = 0; j < itersPerDraw; j++) {
l1 = PVector.fromAngle(an[0]);
l2 = PVector.fromAngle(an[1]);
float lerpval1 = lerp(sin(sn[0]),1,lp[0]);
float lerpval2 = lerp(sin(sn[1]),1,lp[1]);
l1.mult(radi*lerpval1);
l2.mult(radi*lerpval2);
p1.set(c1);
p2.set(c2);
p1.add(l1);
p2.add(l2);
// paint a bezier curve
//noFill();
//stroke(255,50);
PBezier(pA,p1,p2,pB);
// increment what is needed
for (int i = 0; i < 5; i++) {
an[i] += ap[i];
sn[i] += sp[i];
if (an[i] < -TAU) an[i] += TAU;
else if (an[i] > TAU) an[i] -= TAU;
if (sn[i] < -TAU) sn[i] += TAU;
else if (sn[i] > TAU) sn[i] -= TAU;
}
}
// blank out screen a little bit for fade effect
t = (t+1)%drawsPerWipe;
if (t == 0) {
noStroke();
fill(0,opac);
//blendMode(MULTIPLY);/*doesn't work*/
rect(0,0,width,height);
//blendMode(BLEND);/*doesn't work*/
}
}
PVector random2DV(float f) {
return PVector.random2D().mult(sqrt(random(sq(f))));
}
void PBezier(PVector pA, PVector p1, PVector p2, PVector pB) {
bezier(pA.x, pA.y, p1.y, p1.x, p2.x, p2.y, pB.x, pB.y);
}
void keyPressed() {
background(bg0);
switch(key) {
case('1'):
for (int i = 0; i < 2; i++) {
an[i] = 0.0;
sn[i] = 0.0;
ap[i] = 0.01;
sp[i] = 0.0;
lp[i] = 1;
}
break;
case('2'):
for (int i = 0; i < 2; i++) {
an[i] = 0.0;
sn[i] = random(TAU);
ap[i] = 0.01;
sp[i] = random(-0.05, 0.05);
lp[i] = 0.5;
}
break;
default:
for (int i = 0; i < 2; i++) {
an[i] = random(TAU);
sn[i] = random(TAU);
ap[i] = random(-0.01, 0.01);
sp[i] = random(-0.01, 0.01);
lp[i] = random(1.0);
}
break;
}
}