Created
February 20, 2016 04:02
-
-
Save arcollector/47b35d9f2e2c9668c0d0 to your computer and use it in GitHub Desktop.
stochastic ray tracing - adapt part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = [ [],[],[],[],[] ]; | |
var flags = [ [],[],[],[],[] ]; | |
var winLength = 4; | |
function arand() { | |
return Math.random()/4 - 1/8; | |
} | |
function adapt(x,y, i,j, step) { | |
// i is for col | |
// j is for row | |
// win = [ 1row, 2row, 3row, 4row, 5row ] | |
// 1row = [ 1col, 2col, 3col, 4col, 5col ] | |
var xi,yj; | |
var coord; | |
console.log( 'step:',step ); | |
// left up corner | |
if( !flags[j][i] ) { | |
xi = x + i/winLength + arand(); | |
yj = y + j/winLength + arand(); | |
coord = '(x,y)'.replace( 'x', xi ).replace( 'y', yj ); | |
console.log( 'left up corner', coord ); | |
win[j][i] = coord | |
flags[j][i] = true; | |
} | |
// right up corner | |
if( !flags[j][i+step] ) { | |
xi = x + (i+step)/winLength + arand(); | |
yj = y + j/winLength + arand(); | |
coord = '(x,y)'.replace( 'x', xi ).replace( 'y', yj ); | |
console.log( 'right up corner', coord ); | |
win[j][i+step] = coord | |
flags[j][i+step] = true; | |
} | |
// left bottom corner | |
if( !flags[j+step][i] ) { | |
xi = x + i/winLength + arand(); | |
yj = y + (j+step)/winLength + arand(); | |
coord = '(x,y)'.replace( 'x', xi ).replace( 'y', yj ); | |
console.log( 'left bottom corner', coord ); | |
win[j+step][i] = coord | |
flags[j+step][i] = true; | |
} | |
// right bottom corner | |
if( !flags[j+step][i+step] ) { | |
xi = x + (i+step)/winLength + arand(); | |
yj = y + (j+step)/winLength + arand(); | |
coord = '(x,y)'.replace( 'x', xi ).replace( 'y', yj ); | |
console.log( 'right bottom corner', coord ); | |
win[j+step][i+step] = coord | |
flags[j+step][i+step] = true; | |
} | |
if( step === 1 ) { | |
return; | |
} | |
step /= 2; | |
step = ~~step; | |
adapt( x,y, i,j, step ); | |
adapt( x,y, i+step,j, step ); | |
adapt( x,y, i,j+step, step ); | |
adapt( x,y, i+step,j+step, step ); | |
} | |
adapt(0,0, 0,0, winLength ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment