>>> ARTWORKS >>> WAVE >>> R0.1SX1.0SY3.0T0.3A15.0F0.05P0.5 >>> WAVE3 SOURCE CODE

 

>>> Processing code:

                boolean save=true;
                
                String fname;
                String[] parameters;
                
                // Parameters for vertical offset
                float radius=0.1;
                float x=-radius;
                float stepX=5;
                float base=0.0;
                FloatList wave;
                FloatList newWave;
                int counter=0;
                
                // Parameters for the wave
                float ampl=15.0;
                float freq=0.05;
                float phase=0.5;
                
                // Parameters for the wave evolution
                float stepY=3;
                float tolY=0.3;
                
                float sine(float A,float F,float P,float x){
                    return A*sin(F*x+P);
                }
                
                float setBase(){
                    float base=ampl+radius;
                    return base;
                }
                
                // return a new wave generated from perturbation of input wave W with tolerance T,
                // smoothed with a runnig average of window 5.
                FloatList generateWave(FloatList W, float T){
                    FloatList nW;
                    nW = new FloatList();
                    nW = W;
                    float dY;
                    float y=0.0;
                    int N=W.size();
                    // generate
                    for (int j=0; j<N; j++) {
                        y=W.get(j)*(1+random(-T,T));
                        nW.set(j,y);
                    }
                    // smooth
                    for (int j=0; j<N; j++) {
                        if (j==1) {
                            nW.set(j,(nW.get(0)+nW.get(1)+nW.get(2))/3.0);
                        } else if (j==N-2) {
                            nW.set(j,(nW.get(j-1)+nW.get(j)+nW.get(j+1))/3.0);
                        } else if ((j!=0) && (j!=N-1)) {
                            float mean=0.0;
                            for (int i=-2; i<=2; i++) {
                                mean+=nW.get(j+i);
                            }
                            nW.set(j,mean/5.0);
                        }
                    }
                    return nW;
                }
                    
                FloatList baseWave(float A,float F,float P,float dX) {
                    float x=0.0;
                    FloatList W;
                    W = new FloatList();
                    while (x<=width) {
                        W.append(sine(A,F,P,x));
                        x+=dX;
                    }
                    return W;
                }
                    
                void setup(){
                    fname="wave3-R"+radius+"SX"+stepX+"SY"+stepY+"T"+tolY+"A"+ampl+"F"+freq+"P"+phase;
                    parameters = new String[8];
                    parameters[0]="Filename: "+fname+".jpg";
                    parameters[1]="Radius: "+radius;
                    parameters[2]="Step X: "+stepX;
                    parameters[3]="Step Y: "+stepY;
                    parameters[4]="Tolerance Y :"+tolY;
                    parameters[5]="Wave amplitude: "+ampl;
                    parameters[6]="wave frequency: "+freq;
                    parameters[7]="wave phase: "+phase;
                    noFill();
                    background(255);
                    stroke(0);
                    strokeWeight(0.5);
                    strokeJoin(ROUND);
                    size(600,800);
                    smooth();
                    frameRate(300);
                    base=setBase();
                    wave = new FloatList();
                    newWave = new FloatList();
                    wave=baseWave(ampl,freq,phase,stepX);
                }
                    
                void draw(){
                    curveTightness(5.0);
                    int N=wave.size();
                    while (base<height-ampl) {
                        println("Creating wave ♯"+counter+" with base="+base);
                        if (counter==0) {
                            beginShape();
                            for (int i=0; i<N; i++) {
                                curveVertex(i*stepX,base+wave.get(i));
                            }
                        endShape();
                        } else {
                            base+=stepY;
                            newWave=generateWave(wave,tolY);
                            beginShape();
                            for (int i=0; i<N; i++) {
                                curveVertex(i*stepX,base+newWave.get(i));
                            }
                            endShape();
                            wave=newWave;
                        }
                        counter++;
                    }
                    if (base>=height-ampl) {
                        if (save) {
                            saveFrame(fname+".jpg");
                            saveStrings(fname+".txt",parameters);
                        }
                        noLoop();
                    }
                }
            

>>> X | © 2017 Thibaud Latour