void LLPerlinNoise::init(void) { int i, j, k; for (i = 0 ; i < B ; i++) { p[i] = i; g1[i] = (F32)((rand() % (B + B)) - B) / B; for (j = 0 ; j < 2 ; j++) g2[i][j] = (F32)((rand() % (B + B)) - B) / B; normalize2(g2[i]); for (j = 0 ; j < 3 ; j++) g3[i][j] = (F32)((rand() % (B + B)) - B) / B; normalize3(g3[i]); } while (--i) { k = p[i]; p[i] = p[j = rand() % B]; p[j] = k; } for (i = 0 ; i < B + 2 ; i++) { p[B + i] = p[i]; g1[B + i] = g1[i]; for (j = 0 ; j < 2 ; j++) g2[B + i][j] = g2[i][j]; for (j = 0 ; j < 3 ; j++) g3[B + i][j] = g3[i][j]; } sInitialized = true; }
Noise::Noise(long seed) { /* Use Blender RNG for repeatable results across platforms. */ RNG *rng = BLI_rng_new(seed); int i, j, k; for (i = 0; i < _NOISE_B; i++) { p[i] = i; g1[i] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; for (j = 0; j < 2; j++) g2[i][j] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; normalize2(g2[i]); for (j = 0; j < 3; j++) g3[i][j] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; normalize3(g3[i]); } while (--i) { k = p[i]; p[i] = p[j = BLI_rng_get_int(rng) % _NOISE_B]; p[j] = k; } for (i = 0; i < _NOISE_B + 2; i++) { p[_NOISE_B + i] = p[i]; g1[_NOISE_B + i] = g1[i]; for (j = 0; j < 2; j++) g2[_NOISE_B + i][j] = g2[i][j]; for (j = 0; j < 3; j++) g3[_NOISE_B + i][j] = g3[i][j]; } BLI_rng_free(rng); }
void initNoise() { int i, j, k; srand(30757); for (i = 0; i < B; i++) { p[i] = i; g1[i] = (double)((rand() % (B + B)) - B) / B; for (j = 0; j < 2; j++) g2[i][j] = (double)((rand() % (B + B)) - B) / B; normalize2(g2[i]); for (j = 0; j < 3; j++) g3[i][j] = (double)((rand() % (B + B)) - B) / B; normalize3(g3[i]); } while (--i) { k = p[i]; p[i] = p[j = rand() % B]; p[j] = k; } for (i = 0; i < B + 2; i++) { p[B + i] = p[i]; g1[B + i] = g1[i]; for (j = 0; j < 2; j++) g2[B + i][j] = g2[i][j]; for (j = 0; j < 3; j++) g3[B + i][j] = g3[i][j]; } }
static void init(void) { int i, j, k; // set the SEED srand(1234); for (i = 0 ; i < B ; i++) { p[i] = i; g1[i] = (double)((myRandomLI() % (B + B)) - B) / B; for (j = 0 ; j < 2 ; j++) g2[i][j] = (double)((myRandomLI() % (B + B)) - B) / B; normalize2(g2[i]); for (j = 0 ; j < 3 ; j++) g3[i][j] = (double)((myRandomLI() % (B + B)) - B) / B; normalize3(g3[i]); } while (--i) { k = p[i]; p[i] = p[j = myRandomLI() % B]; p[j] = k; } for (i = 0 ; i < B + 2 ; i++) { p[B + i] = p[i]; g1[B + i] = g1[i]; for (j = 0 ; j < 2 ; j++) g2[B + i][j] = g2[i][j]; for (j = 0 ; j < 3 ; j++) g3[B + i][j] = g3[i][j]; } }