Skip to content

Instantly share code, notes, and snippets.

@jaycody
Last active August 29, 2015 13:57
Show Gist options
  • Save jaycody/9502284 to your computer and use it in GitHub Desktop.
Save jaycody/9502284 to your computer and use it in GitHub Desktop.
Perlin Noise: Convert 2D perlin noise into vector field THETA
// Incrementing Noise to THETA
for (int i = 0; i < flowFieldCols; ++i) {
float yOffSetNoise = 0;
for (int j = 0; j < flowFieldRows; ++j) {
float theta = map(noise(xOffSetNoise, yOffSetNoise), 0 ,1 ,0 ,TWO_PI);
// Convert from Polar to Cartesian
// according to SOHCAHTOA, cos(theta)=1 and sin(theta) = 0 when theta = 0 (aka (1,0))
vectorField[i][j] = new PVector(cos(theta), sin(theta));
// increment the Perlin Noise
yOffSetNoise += 0.1;
}
xOffSetNoise += 0.1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment