Last active
August 29, 2015 13:57
-
-
Save jaycody/9502284 to your computer and use it in GitHub Desktop.
Perlin Noise: Convert 2D perlin noise into vector field THETA
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
// 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