5
5
import processing .core .PGraphics ;
6
6
import processing .core .PImage ;
7
7
8
- import static processing .core .PApplet .constrain ;
9
- import static processing .core .PApplet .map ;
8
+ import static processing .core .PApplet .*;
10
9
import static processing .core .PConstants .TWO_PI ;
11
10
12
11
public class Strokes {
13
12
14
13
public static PImage apply (PImage img , int gridSize ) {
15
- return apply (img , gridSize , 4 , 4 , 1 , 220 , false , 255 );
14
+ return apply (img , gridSize , null , 4 , 1 , 220 , null , false , 255 );
15
+ }
16
+
17
+ public static PImage apply (PImage img , int gridSize , float degree ) {
18
+ return apply (img , gridSize , null , 4 , 1 , 220 , degree , false , 255 );
16
19
}
17
20
18
21
public static PImage apply (PImage img , int gridSize , int lineLength ) {
19
22
return apply (img , gridSize , lineLength , 4 , 1 , 220 , false , 255 );
20
23
}
21
24
25
+ public static PImage apply (PImage img , int gridSize , int lineLength , float degree ) {
26
+ return apply (img , gridSize , lineLength , 4 , 1 , 220 , degree , false , 255 );
27
+ }
28
+
22
29
public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel ) {
23
30
return apply (img , gridSize , lineLength , linesPerPixel , 1 , 220 , false , 255 );
24
31
}
25
32
33
+ public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel , float degree ) {
34
+ return apply (img , gridSize , lineLength , linesPerPixel , 1 , 220 , degree , false , 255 );
35
+ }
36
+
26
37
public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel , int lineWeight , int lineAlpha ) {
27
38
return apply (img , gridSize , lineLength , linesPerPixel , lineWeight , lineAlpha , false , 255 );
28
39
}
29
40
41
+ public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel , int lineWeight , int lineAlpha , float degree ) {
42
+ return apply (img , gridSize , lineLength , linesPerPixel , lineWeight , lineAlpha , degree , false , 255 );
43
+ }
44
+
30
45
public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel , int lineWeight , int lineAlpha , boolean inColor ) {
31
46
return apply (img , gridSize , lineLength , linesPerPixel , lineWeight , lineAlpha , inColor , 255 );
32
47
}
33
48
49
+ public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel , int lineWeight , int lineAlpha , float degree , boolean inColor ) {
50
+ return apply (img , gridSize , lineLength , linesPerPixel , lineWeight , lineAlpha , degree , inColor , 255 );
51
+ }
52
+
34
53
public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel , int lineWeight , int lineAlpha , boolean inColor , int backgroundColor ) {
54
+ return apply (img , gridSize , lineLength , linesPerPixel , lineWeight , lineAlpha , null , inColor , backgroundColor );
55
+ }
56
+
57
+ public static PImage apply (PImage img , int gridSize , Integer lineLength , int linesPerPixel , int lineWeight , int lineAlpha , Float degree , boolean inColor , int backgroundColor ) {
35
58
36
- gridSize = constrain (gridSize , 1 , Integer .MAX_VALUE );
37
- lineLength = constrain (lineLength , 0 , Integer .MAX_VALUE );
38
- linesPerPixel = constrain (linesPerPixel , 0 , Integer .MAX_VALUE );
39
- lineWeight = constrain (lineWeight , 0 , Integer .MAX_VALUE );
40
- lineAlpha = constrain (lineAlpha , 0 , 255 );
41
- backgroundColor = constrain (backgroundColor , 0 , 255 );
59
+ gridSize = constrain (gridSize , 1 , Integer .MAX_VALUE );
60
+ linesPerPixel = constrain (linesPerPixel , 0 , Integer .MAX_VALUE );
61
+ lineWeight = constrain (lineWeight , 0 , Integer .MAX_VALUE );
62
+ lineAlpha = constrain (lineAlpha , 0 , 255 );
63
+ backgroundColor = constrain (backgroundColor , 0 , 255 );
42
64
43
65
PGraphics canvas = img .parent .createGraphics (img .width , img .height );
44
66
canvas .beginDraw ();
@@ -61,7 +83,17 @@ public static PImage apply(PImage img, int gridSize, int lineLength, int linesPe
61
83
for (int i = 0 ; i < numberOfStrokes ; i ++) {
62
84
canvas .pushMatrix ();
63
85
canvas .translate (x + img .parent .random (-gridSize / 2 ), y + img .parent .random (gridSize / 2 ));
64
- canvas .rotate (img .parent .random (0 , TWO_PI ));
86
+
87
+ if (degree == null ) {
88
+ canvas .rotate (img .parent .random (0 , TWO_PI ));
89
+ } else {
90
+ canvas .rotate (radians (degree ));
91
+ }
92
+
93
+ if (lineLength == null ) {
94
+ lineLength = (int ) map (pixel , 0 , 255 , 0 , gridSize );
95
+ }
96
+
65
97
canvas .line (-lineLength , 0 , lineLength , 0 );
66
98
canvas .popMatrix ();
67
99
}
0 commit comments