i think i really got it this time, nature of code in

This commit is contained in:
shiffman
2012-09-04 01:47:20 +00:00
parent b5b67a12b5
commit 1d86e1f5bf
541 changed files with 35009 additions and 0 deletions
@@ -0,0 +1,33 @@
// Daniel Shiffman
// The Nature of Code
// Testing Distribution of Perlin Noise generated #'s vs. Randoms
float[] vals;
float[] norms;
float xoff = 0.0f;
void setup() {
size(300,200);
vals = new float[width];
norms = new float[width];
}
void draw() {
background(100);
float n = noise(xoff);
int index = int(n*width);
vals[index]++;
xoff += 0.01;
stroke(255);
boolean normalization = false;
float maxy = 0.0;
for (int x = 0; x < vals.length; x++) {
line(x,height,x,height-norms[x]);
if (vals[x] > height) normalization = true;
if(vals[x] > maxy) maxy = vals[x];
}
for (int x = 0; x < vals.length; x++) {
if (normalization) norms[x] = (vals[x] / maxy) * (height);
else norms[x] = vals[x];
}
}