Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Created May 20, 2017 11:21
Show Gist options
  • Select an option

  • Save paulhayes/0cf276aa08aaca215e129ade7d9d7e10 to your computer and use it in GitHub Desktop.

Select an option

Save paulhayes/0cf276aa08aaca215e129ade7d9d7e10 to your computer and use it in GitHub Desktop.
Fractal Noise using fluid dynamics equations
// Using Lorenz equations
// http://www.stsci.edu/~lbradley/seminar/attractors.html
// https://arxiv.org/ftp/math/papers/0305/0305212.pdf
x = 1.0;
y = -1.0;
z = 10.0;
P = 10.0;
R = 28.0;
B = 8.0/3;
scale = 0.014;
mix= function(x,y,z){ return x };
min = 0;
max = 0;
vol = 0.2;
val = 0;
scriptNode.onaudioprocess = function(e){
var outputData = e.outputBuffer.getChannelData(0);
for(var i=0;i<outputData.length;i++){
if(playing){
var dx = P*(y-x);
var dy = R*x - y - x*z;
var dz = x*y - B*z;
x+=scale*dx;
y+=scale*dy;
z+=scale*dz;
if( isNaN(x) || isNaN(y) || isNaN(z) ){
console.log("step "+i+" isNaN "+x+" "+y+" "+z);
playing = false;
}
val = mix(x,y,z);
if( val < min ) min = val;
if( val > max ) max = val;
val = 2*( (val-min) / (max-min ) ) -1;
if(min!=max)
outputData[i] = vol* val;
} else {
outputData[i] = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment