55import processing .core .PGraphics ;
66import processing .core .PImage ;
77
8- import static processing .core .PApplet .constrain ;
9- import static processing .core .PApplet .map ;
8+ import static processing .core .PApplet .*;
109import static processing .core .PConstants .TWO_PI ;
1110
1211public class Strokes {
1312
1413 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 );
1619 }
1720
1821 public static PImage apply (PImage img , int gridSize , int lineLength ) {
1922 return apply (img , gridSize , lineLength , 4 , 1 , 220 , false , 255 );
2023 }
2124
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+
2229 public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel ) {
2330 return apply (img , gridSize , lineLength , linesPerPixel , 1 , 220 , false , 255 );
2431 }
2532
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+
2637 public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel , int lineWeight , int lineAlpha ) {
2738 return apply (img , gridSize , lineLength , linesPerPixel , lineWeight , lineAlpha , false , 255 );
2839 }
2940
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+
3045 public static PImage apply (PImage img , int gridSize , int lineLength , int linesPerPixel , int lineWeight , int lineAlpha , boolean inColor ) {
3146 return apply (img , gridSize , lineLength , linesPerPixel , lineWeight , lineAlpha , inColor , 255 );
3247 }
3348
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+
3453 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 ) {
3558
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 );
4264
4365 PGraphics canvas = img .parent .createGraphics (img .width , img .height );
4466 canvas .beginDraw ();
@@ -61,7 +83,17 @@ public static PImage apply(PImage img, int gridSize, int lineLength, int linesPe
6183 for (int i = 0 ; i < numberOfStrokes ; i ++) {
6284 canvas .pushMatrix ();
6385 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+
6597 canvas .line (-lineLength , 0 , lineLength , 0 );
6698 canvas .popMatrix ();
6799 }
0 commit comments