constbgCol="#447abd";constgCol="#a2c2e8";constnGrid=20;letgSpace;letN=52;letA=13;letn=10;functionsetup(){w=max(400,min(windowWidth,windowHeight)*0.9);createCanvas(w,w);rectMode(CENTER);describe("a hypergeometric distribution with the bars centered horizontally is reflected over the y center of the page and then the sample changes to stretch the reflections in such a way that the two distributions boop.");angleMode(DEGREES);textSize(16);gSpace=(w/nGrid)*0.95;prevN=10;}functiondraw(){background(bgCol);translate(w/2,w/2);t=frameCount;lettargetN=5+int(5*(0.5+0.5*sin(t)));n=lerp(prevN,targetN,0.1);prevN=n;for(leti=0;i<n;i++){p=hyperG(i);fill(255,255,255,80);stroke(255);rect(-9*gSpace+i*gSpace,0,gSpace,p*gSpace*30);rect(9*gSpace-i*gSpace,0,gSpace,p*gSpace*30);}noStroke();fill(gCol);text("hypergeometric",-w/2+10,w/2-5);drawGrid();}functionhyperG(k){if(k>A||n-k>N-A){return0;}k=int(k);t1=factorial(A)/(factorial(k)*factorial(A-k));t2=factorial(N-A)/(factorial(n-k)*factorial(N-A-(n-k)));t3=factorial(N)/(factorial(n)*factorial(N-n));return(t1*t2)/t3;}functionfactorial(n1){if(n1===0||n1===1){return1;}letresult=1;for(leti=2;i<=n1;i++){result*=i;}returnresult;}functionfillRect(x,y,s){push();translate(x,y);stroke(gCol);strokeWeight(2);if(s===1){scale(1,1);}else{scale(1,-1);}for(leti=0;i<=6;i++){line(-gSpace/2+(gSpace/6)*i,-gSpace/2,-gSpace/2,-gSpace/2+(gSpace/6)*i);line(gSpace/2-(gSpace/6)*i,gSpace/2,gSpace/2,gSpace/2-(gSpace/6)*i);}pop();}functiondrawGrid(){gSpace=(w/nGrid)*0.95;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();}