mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
i think i really got it this time, nature of code in
This commit is contained in:
+33
@@ -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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user