-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStripe.java
More file actions
90 lines (83 loc) · 2.82 KB
/
Stripe.java
File metadata and controls
90 lines (83 loc) · 2.82 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package algorithm.randomimage;
import java.awt.Color;
import java.awt.image.BufferedImage;
class HorizontalStripe extends RandImgGenerator {
public HorizontalStripe(int diff) {
super(Math.abs(diff));
}
@Override
public void make() {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int red = rand.nextInt(256);
int green = rand.nextInt(256);
int blue = rand.nextInt(256);
Color color = new Color(red, green, blue);
image.setRGB(0, 0, color.getRGB());
for (int i = 0; i < height; i++) {
red += rand.nextInt(-diff, diff + 1);
red = (red > 255) ? 255 : (red < 0) ? 0 : red;
green += rand.nextInt(-diff, diff + 1);
green = (green > 255) ? 255 : (green < 0) ? 0 : green;
blue += rand.nextInt(-diff, diff + 1);
blue = (blue > 255) ? 255 : (blue < 0) ? 0 : blue;
color = new Color(red, green, blue);
for (int j = 0; j < width; j++)
image.setRGB(j, i, color.getRGB());
}
save(image, "horizontalstripe" + diff + ".png");
}
}
class VerticalStripe extends RandImgGenerator {
public VerticalStripe(int diff) {
super(Math.abs(diff));
}
@Override
public void make() {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int red = rand.nextInt(256);
int green = rand.nextInt(256);
int blue = rand.nextInt(256);
Color color = new Color(red, green, blue);
image.setRGB(0, 0, color.getRGB());
for (int i = 0; i < width; i++) {
red += rand.nextInt(-diff, diff + 1);
red = (red > 255) ? 255 : (red < 0) ? 0 : red;
green += rand.nextInt(-diff, diff + 1);
green = (green > 255) ? 255 : (green < 0) ? 0 : green;
blue += rand.nextInt(-diff, diff + 1);
blue = (blue > 255) ? 255 : (blue < 0) ? 0 : blue;
color = new Color(red, green, blue);
for (int j = 0; j < height; j++)
image.setRGB(i, j, color.getRGB());
}
save(image, "verticalstripe" + diff + ".png");
}
}
class DiagonalStripe extends RandImgGenerator {
public DiagonalStripe(int diff) {
super(Math.abs(diff));
}
@Override
public void make() {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int red = rand.nextInt(256);
int green = rand.nextInt(256);
int blue = rand.nextInt(256);
Color color = new Color(red, green, blue);
image.setRGB(0, 0, color.getRGB());
for (int i = 1; i < width + height; i++) {
red += rand.nextInt(-diff, diff + 1);
red = (red > 255) ? 255 : (red < 0) ? 0 : red;
green += rand.nextInt(-diff, diff + 1);
green = (green > 255) ? 255 : (green < 0) ? 0 : green;
blue += rand.nextInt(-diff, diff + 1);
blue = (blue > 255) ? 255 : (blue < 0) ? 0 : blue;
color = new Color(red, green, blue);
for (int j = 0; j < height; j++) {
if (i - j < width && i - j >= 0)
image.setRGB(i - j, j, color.getRGB());
}
}
save(image, "diagonalstripe" + diff + ".png");
}
}