xxxxxxxxxx
47
function setup() {
createCanvas(512, 300);
background(0);
let c=color(255,255,0);
let r=new Float32Array(65536);
for(let i=0;i<65536;i++){
r[i]=random(-1,1);
}
for(let i=0;i<65536;i+=2){
x=r[i]*127+128;
y=r[i+1]*127+128;
set(x,y,c);
}
wht(r);// Uniform distribution to Gaussian Distribution
for(let i=0;i<65536;i+=2){
x=r[i]*0.2+128+256;
y=r[i+1]*0.2+128;
set(x,y,c);
}
updatePixels();
fill(255);
text("Uniform to Gaussian random distribution via the Walsh Hadamard Transform.",2,270);
text("Due to the central limit theorem applying to sum and or differences.",2,285);
}
// Fast Walsh Hadamard Transform
function wht(vec) {
const n = vec.length;
let hs = 1;
while (hs < n) {
let i = 0;
while (i < n) {
const j = i + hs;
while (i < j) {
var a = vec[i];
var b = vec[i + hs];
vec[i] = a + b;
vec[i + hs] = a - b;
i += 1;
}
i += hs;
}
hs += hs;
}
}