Skip to content

Instantly share code, notes, and snippets.

@garettbass
Last active February 4, 2019 18:38
Show Gist options
  • Save garettbass/bde1e0eeac4f389455113ff962dbcaba to your computer and use it in GitHub Desktop.
Save garettbass/bde1e0eeac4f389455113ff962dbcaba to your computer and use it in GitHub Desktop.
A cheeky C implementation of "A simple method to construct isotropic quasirandom blue noise point sequences"
// based on C++ implementation by syoyo https://gist.github.com/syoyo/831c4b1926aa88c0da9221211723da2d
// http://extremelearning.com.au/a-simple-method-to-construct-isotropic-quasirandom-blue-noise-point-sequences/
#if __cplusplus
extern "C" {
#endif
static inline void sample_point_2d(
double p[2],
int i, // 1, 2, 3, ...
double jitter, // > 0
double random0, // [0..1)
double random1 // [0..1)
) {
static const double sqrtkPI = 1.772453850905516;
static const double varphi = 1.324717957244746;
static const double alpha0 = 1.0 / varphi;
static const double alpha1 = 1.0 / (varphi * varphi);
static const double delta0 = 0.76;
static const double delta0_sqrtkPI = delta0 * sqrtkPI;
static const double i0 = 0.700;
extern double floor(double);
extern double sqrt(double);
const double iDouble = (double)i;
const double iDelta = iDouble - i0;
const double jitter_scaled = jitter * delta0_sqrtkPI / (4.0 * sqrt(iDelta));
const double x0 = alpha0 * iDouble + jitter_scaled * random0;
const double x1 = alpha1 * iDouble + jitter_scaled * random1;
p[0] = x0 - floor(x0);
p[1] = x1 - floor(x1);
}
#if __cplusplus
} // extern "C"
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment