forked from johhnry/codecember
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_3.pde
60 lines (45 loc) · 1.59 KB
/
day_3.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
float margin = 50;
int nLines = 30;
float xResolution = 5;
float bandSize = 50;
float noiseAmplitude = 8;
float noiseAngle = 0;
float noiseRadius = 1;
void setup() {
size(500, 500);
}
// Normal distribution formulae for smooth fallof
// https://en.wikipedia.org/wiki/Normal_distribution
float normalDistribution(float x, float mean, float deviation) {
return (1 / deviation * sqrt(2 * PI)) * exp(-0.5 * pow((x - mean) / deviation, 2));
}
void draw() {
background(255);
strokeWeight(2);
float ySize = (height - 2 * margin);
float gap = ySize / nLines;
// Go through each line
for (int i = 0; i < nLines; i++) {
float y = margin + i * gap;
float xSize = width - 2 * margin;
float xOffset = y;
float yOffset = y / ySize;
noFill();
// Go through each points on the line
beginShape();
for (float x = margin; x < width - margin; x += xResolution) {
// Compute the distance from the center of the line
float dist = map(x, margin + bandSize, margin + xSize - bandSize, -1, 1);
// Compute smooth falloff with cosine offset based on the line number
float smooth = normalDistribution(dist, cos(noiseAngle + TWO_PI * i / nLines) / 2, 0.3);
// Compute seamless perlin noise
float noise = noise(cos(noiseAngle + xOffset) * noiseRadius, sin(noiseAngle + xOffset) * noiseRadius + yOffset);
curveVertex(x, y - noise * smooth * noiseAmplitude);
// Every five curve, inverse the direction
if (i % 5 == 0) xOffset += 0.1;
else xOffset -= 0.1;
}
endShape();
}
noiseAngle += 0.01;
}