Created
March 6, 2015 06:22
-
-
Save keijiro/996860f2dda605d6ba6a to your computer and use it in GitHub Desktop.
Interleaved gradient noise test.
This file contains hidden or 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
float frac(float x) | |
{ | |
return x - floor(x); | |
} | |
float gradientNoise(float x, float y) | |
{ | |
float f = 0.06711056f * x + 0.00583715f * y; | |
return frac(52.9829189f * frac(f)); | |
} | |
float nrand(float x, float y) | |
{ | |
float f = 12.9898f * x + 78.233f * y; | |
return frac(sin(f) * 43758.5453f); | |
} | |
void setup() | |
{ | |
size(512 + 8, 256); | |
background(0); | |
} | |
void draw() | |
{ | |
for (int y = 0; y < height; y++) | |
{ | |
for (int x = 0; x < height; x++) | |
{ | |
int nx1 = x / 4; | |
int ny1 = y / 4; | |
float nx2 = nx1 * 4.0f / height; | |
float ny2 = ny1 * 4.0f / height; | |
float ox = sin(0.1f * frameCount) * 0.8f + 0.5f; | |
float oy = sin(0.05f * frameCount) * 0.8f + 0.5f; | |
float nc = 0.2f * sqrt(sq(nx2 - ox) + sq(ny2 - oy)) + 0.4f; | |
float nc1 = nc + nrand(nx2, ny2) / 16; | |
float nc2 = nc + gradientNoise(nx1, ny1) / 16; | |
set(x, y, color(int(nc1 * 255) / 16 * 20)); | |
set(x + height + 8, y, color(int(nc2 * 255) / 16 * 20)); | |
} | |
} | |
// saveFrame(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment