@@ -4,6 +4,7 @@ int _numPoints = 450;
4
4
float _angle = 137.5 ;
5
5
float _scale = 10 ;
6
6
float _seedSize = 20 ;
7
+ String _saveName = " fermat_spiral_" ;
7
8
8
9
9
10
void setup () {
@@ -15,21 +16,58 @@ void setup() {
15
16
}
16
17
17
18
void draw () {
18
- for (int n= 0 ; n< _numPoints; n++ ) {
19
- float theta = n * radians (_angle);
20
- float radius = sqrt (n) * _scale;
21
- float translateX = radius * cos (theta) + width / 2 ;
22
- float translateY = radius * sin (theta) + height / 2 ;
23
-
24
- float x = 0 ;
25
- float y = 0 ;
26
-
27
- float size = (n / 42 ) + _seedSize;
28
-
29
- pushMatrix ();
30
- translate (translateX, translateY);
31
- rotate (theta);
32
- quad (x, y+ size/ 4 , x+ size/ 2 , y, x+ size, y+ size/ 4 , x+ size/ 2 , y+ size/ 2 );
33
- popMatrix ();
34
- }
19
+ for (int n= 0 ; n< _numPoints; n++ ) {
20
+ float theta = n * radians (_angle);
21
+ float radius = sqrt (n) * _scale;
22
+ float translateX = radius * cos (theta) + width / 2 ;
23
+ float translateY = radius * sin (theta) + height / 2 ;
24
+
25
+ float x = 0 ;
26
+ float y = 0 ;
27
+
28
+ float size = (n / 42 ) + _seedSize;
29
+
30
+ pushMatrix ();
31
+ translate (translateX, translateY);
32
+ rotate (theta);
33
+ quad (x, y+ size/ 4 , x+ size/ 2 , y, x+ size, y+ size/ 4 , x+ size/ 2 , y+ size/ 2 );
34
+ popMatrix ();
35
+ }
36
+ }
37
+
38
+ void keyPressed () {
39
+ if (key == ' s' || key == ' S' ) {
40
+ exportSVG();
41
+ }
42
+ }
43
+
44
+ void exportSVG () {
45
+ String exportName = _saveName + round (_seedSize) + " .svg" ;
46
+ PGraphics pg = createGraphics (width , height , SVG , exportName);
47
+ pg. beginDraw();
48
+ pg. noFill();
49
+ pg. strokeWeight(1 );
50
+ pg. stroke(0 );
51
+
52
+ for (int n= 0 ; n< _numPoints; n++ ) {
53
+ float theta = n * radians (_angle);
54
+ float radius = sqrt (n) * _scale;
55
+ float translateX = radius * cos (theta) + width / 2 ;
56
+ float translateY = radius * sin (theta) + height / 2 ;
57
+
58
+ float x = 0 ;
59
+ float y = 0 ;
60
+
61
+ float size = (n / 42 ) + _seedSize;
62
+
63
+ pg. pushMatrix();
64
+ pg. translate(translateX, translateY);
65
+ pg. rotate(theta);
66
+ pg. quad(x, y+ size/ 4 , x+ size/ 2 , y, x+ size, y+ size/ 4 , x+ size/ 2 , y+ size/ 2 );
67
+ pg. popMatrix();
68
+ }
69
+
70
+ pg. endDraw();
71
+ pg. dispose();
72
+ println (" saved " + exportName);
35
73
}
0 commit comments