Created
March 12, 2014 07:09
-
-
Save jaycody/9502210 to your computer and use it in GitHub Desktop.
pro.FlowField-Perlin
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
////////////////////////////////////////////////////// | |
// Create a Perlin Noise Field | |
void initPerlinField() { | |
// Reseed Noise | |
noiseSeed((int)random(10000)); | |
//TODO: make the x,y noise offset a PVector | |
float xOffSetNoise = 0; | |
// Iterate through the 2D array of PVectors | |
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