int n = 5; // NO. OF STRANDS
float[] translate;//OFFSET OF INDIVIDUAL STRAND
float[] amp;// AMPLITUDE OF INDIVIDUAL STRAND
float[] period;// PERIOD OF INDIVIDUAL STRAND RELATIVE TO STANDARD PERIOD
float frequency;
float per;//STANDARD PERIOD
float angle;
float startWave;
float endWave;
void setup() {
size(800, 800);
smooth();
stroke(255);
strokeWeight(0.7);
noFill();
frequency = 4;
per = height/frequency;
amp = new float[n];
translate = new float[n];
period = new float[n];
void draw() {
background(0);
translate(width/2, 0);
//line(0, 0, 0, height);
calcamptransperiod();
drawWave(1);
drawWave(-1);
}
void calcamptransperiod() {
for (int i=0; i<n; i++) {
float maxamp = 105.0;
amp[i] = maxamp-(i*(maxamp/6.6));
float offset = 15.0;
translate[i] = i*offset;
}
for (int i=0; i<n; i++) {
period[i] =(per-translate[i]) + translate[(n-1)-i];
//println("amp"+i+"="+amp[i]);
//println("translate"+i+"="+translate[i]);
//println("period"+i+"="+period[i]);
//println(" ");
}
}
void drawWave(int direction) {
for (int f=0; f<frequency; f++) {
//line(-width/2, height/frequency*f, width, height/frequency*f);
for (int i=0; i<n; i++) {
startWave = per*f;
endWave = per*f+period[i];
angle=0.0;
for (float y=startWave; y<endWave; y++) {
pushMatrix();
translate(0, translate[i]);
float x = sin(angle)*amp[i]*direction;
point(x, y);
popMatrix();
angle+=PI/period[i];
}
}
direction = - direction;
}
}
I am trying to create overlapping sine waves . I have achieved some result but its not symmetric.
It doesn’t start & end at same spot. I want to achieve symmetricity along x-axis & y-axis both.
I don’t know if I am missing something that is awfully simple.
If you reduce the number of strands to 1 your sketch is symmetric. It seems you haven’t taken the extra strands in account with your formula. A quick fix would be to move your sketch up a bit with translate, but I guess you want all strands to start at y = 0 instead?