constbgCol="#447abd";constgCol="#a2c2e8";constnGrid=20;letw;letgSpace;functionsetup(){w=max(500,500);gSpace=(w/nGrid)*0.95;describe("a point on a wavy curve riding the wave from left to right with its tangent line as the curve changes. On a blueprint design.");createCanvas(w,w);rectMode(CENTER);d=w;angleMode(DEGREES);textSize(16);r=4*gSpace;}functiondraw(){background(bgCol);translate(w/2,w/2);drawGrid();t=frameCount/3;t1=-w/2+gSpace+(t%(w-2*gSpace));strokeWeight(1);noStroke();fill(255);a=5*gSpace;b=2+2*sin(t);c=4*gSpace;d=1/6;functionf(x){returna*cos(x*b)*sin(x)-c*tan(x*d);}functionfPrime(x){return(a*(-b*sin(b*x)*sin(x)+cos(b*x)*cos(x))-(c*d)/pow(cos(d*x),2));}noFill();stroke(gCol);beginShape();for(leti=-w/2+gSpace;i<w/2-gSpace;i++){circle(i,f(i),2);vertex(i,f(i));}endShape();x=t1;m=-fPrime(x);d1=gSpace*2;letscaleFactor=2/a;letscaledM=m*scaleFactor;letdx=d1/sqrt(1+scaledM*scaledM);letdy=(d1*scaledM)/sqrt(1+scaledM*scaledM);dy=-dy;letx4=x+dx;lety4=f(x)+dy;letx5=x-dx;lety5=f(x)-dy;stroke(255);strokeWeight(2);circle(x,f(x),10);line(x5,y5,x4,y4);noStroke();fill(bgCol);rect(-width/2+gSpace/2,0,gSpace,height);rect(width/2-gSpace/2,0,gSpace,height);rect(0,-width/2+gSpace/2,height,gSpace);rect(0,width/2-gSpace/2,height,gSpace);fill(gCol);text("critical",-w/2+10,w/2-5);}functiondrawGrid(){stroke(gCol);strokeWeight(0.3);for(leti=1;i<=nGrid;i++){for(letj=1;j<=nGrid;j++){line(-w/2+gSpace*i,-w/2+gSpace,-w/2+gSpace*i,w/2-gSpace);line(-w/2+gSpace,-w/2+gSpace*i,w/2-gSpace,-w/2+gSpace*i);}}noFill();strokeWeight(3);rect(0,0,w-2*gSpace);}functionmousePressed(){setup();draw();}functionwindowResized(){setup();draw();}