Skip to content

Commit 38ab62a

Browse files
committed
Fixes #41
1 parent 89723d6 commit 38ab62a

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ PImage processedImage = Sabattier.applyBlue(image, intensity);
281281
```
282282

283283
#### Strokes image
284-
![alt strokes](https://github.com/Milchreis/processing-imageprocessing/blob/master/img/strokes.png?raw=true)
284+
random angles | fixed angles
285+
:-------------------------:|:-------------------------:
286+
![alt strokes](https://github.com/Milchreis/processing-imageprocessing/blob/master/img/strokes.png?raw=true) | ![alt strokes](https://github.com/Milchreis/processing-imageprocessing/blob/master/img/strokes2.png?raw=true)
287+
285288
```java
286289
PImage processedImage = Strokes.apply(image, gridSize, lineLength);
287290
PImage processedImage = Strokes.apply(image,
@@ -290,6 +293,7 @@ PImage processedImage = Strokes.apply(image,
290293
lineWeight, // is positive and the weight of each line in pixel
291294
linesPerGrid, // the number of lines per grid
292295
lineIntensity, // alpha value for each line between 0 and 255
296+
degree, // if set the rotation is fixed in degree, otherwise random
293297
inColor, // true for colors else black and white
294298
backgroundColor); // color for the background
295299
```
@@ -344,7 +348,7 @@ PImage processedImage = SineWave.apply(image, rowHeight, weight, backgroundColor
344348
#### Knitting image
345349
![alt knitting](https://github.com/Milchreis/processing-imageprocessing/blob/master/img/knitting.png?raw=true)
346350
```java
347-
// keeps the colors
351+
// keeps the original colors
348352
PImage processedImage = Knitting.apply(image, size);
349353
// Sets foreground and background color and uses a threshold
350354
PImage processedImage = Knitting.apply(image, size, threshold, 240, #EE0000);

img/strokes2.png

441 KB
Loading

src/milchreis/imageprocessing/Strokes.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,62 @@
55
import processing.core.PGraphics;
66
import processing.core.PImage;
77

8-
import static processing.core.PApplet.constrain;
9-
import static processing.core.PApplet.map;
8+
import static processing.core.PApplet.*;
109
import static processing.core.PConstants.TWO_PI;
1110

1211
public 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

Comments
 (0)