A SIMPLE IMPLEMENTATION OF NOISE ================================ ( From Watt: 3D Graphics) procedure initialise_noise; var x,y,z,xx,yy,zz: nrange; begin {set up the noise lattice} for x:=0 to max_noise do for y:=0 to max_noise do for z:=0 to max_noise do begin noise_table[x,y,z]:=round(random(1)*10000); if x=max_noise then xx:=0 else xx:=x; if y=max_noise then yy:=0 else yy:=y; if z=max_noise then zz:=0 else zz:=z; noise_table[x,y,z]:=noise_table[xx,yy,zz] end; end {initialise_noise}; function frac(r:real):real; begin frac:=r-trunc(r); end {frac}; function noise(x,y,z:real):real; var ix,iy,iz:integer; ox,oy,oz:real; n:integer; n00,n01,n10,n11:real; n0,n1:real; begin {offset x,y,z to ensure they are positive} x:=x+15000; y:=y+15000; z:=z+15000; {find lattice coordinates and real offsets} ix:=trunc(x) mod max_noise; iy:=trunc(y) mod max_noise; iz:=trunc(z) mod max_noise; ox:=frac(x); oy:=frac(y); oz:=frac(z); {interpolate to get noise value at (ix+ox,iy+oy,iz++oz)} n:=noise_table[ix,iy,iz]; n00:=n+ox*(noise_table[ix+1,iy,iz]-n); n:=noise_table[ix,iy,iz+1]; n01:=n+ox*(noise_table[ix+1,iy,iz+1]-n); n:=noise_table[ix,iy+1,iz]; n10:=n+ox*(noise_table[ix+1,iy+1,iz]-n); n:=noise_table[ix,iy+1,iz+1]; n11:=n+ox*(noise_table[ix+1,iy+1,iz+1]-n); no:=n00+oy*(n10-n00); n1:=n01+oy*(n11-n01); noise:=(n0+oz*(n1-n0))*0.0001; end {noise};