Javascript implementation of Sans simulation