-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsvg_simpleFlowField.pde
65 lines (54 loc) · 1.56 KB
/
svg_simpleFlowField.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
61
62
63
64
65
// VERY IMPORTANT NOTE:
// The output SVG will still need to be processed by vpype
// in order to trim the points that go beyond the paper bounds!
// Otherwise you will mess up the plotter!!!
//-----------------------
import processing.svg.*;
void setup() {
size(1056, 816); // Letter: 11"x8.5" at 96 DPI.
}
//-----------------------
void draw() {
background(255);
beginRecord(SVG, "simpleFlowField_from_processing.svg");
// Loosely adapted from "Flow Fields" by Tyler Hobbs
// https://tylerxhobbs.com/essays/2020/flow-fields
float margin = width/6;
float L = -margin;
float R = width+margin;
float T = -margin;
float B = height+margin;
int nCurves = 1000;
int nSteps = 100;
float step_length = width * 0.002;
noFill();
stroke(0,0,0);
strokeWeight(1.0);
noiseSeed(millis());
// For each curve, pick a random starting location
for (int c=0; c<nCurves; c++){
float x = random(L, R);
float y = random(T, B);
// Move that point by an increment
// whose orientation is based on noise()
beginShape();
for (int s=0; s<nSteps; s++){
float scaled_x = x * 0.005;
float scaled_y = y * 0.005;
float noise_val = noise(scaled_x, scaled_y);
float angle = map(noise_val, 0.0, 1.0, 0.0, TWO_PI);
float x_step = step_length * cos(angle);
float y_step = step_length * sin(angle);
x += x_step;
y += y_step;
vertex(x, y);
}
endShape();
}
endRecord();
noLoop();
}
//-----------------------
void mousePressed(){
loop() ;
}