Skip to content

Instantly share code, notes, and snippets.

@jaycody
Created March 12, 2014 07:09
Show Gist options
  • Save jaycody/9502210 to your computer and use it in GitHub Desktop.
Save jaycody/9502210 to your computer and use it in GitHub Desktop.
pro.FlowField-Perlin
//////////////////////////////////////////////////////
// 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