-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractise.java
More file actions
91 lines (78 loc) · 2.37 KB
/
Copy pathPractise.java
File metadata and controls
91 lines (78 loc) · 2.37 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
91
package Src;
import ASimulatorSystem.Practice.1;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.swing.SwingUtilities;
public final class Practice {
boolean negative;
public Practice() {
this(false);
}
public Practice(boolean negative) {
this.negative = negative;
}
public String convert(BufferedImage image) {
StringBuilder sb = new StringBuilder((image.getWidth() + 1) * image.getHeight());
for(int y = 0; y < image.getHeight(); ++y) {
if (sb.length() != 0) {
sb.append("\n");
}
for(int x = 0; x < image.getWidth(); ++x) {
Color pixelColor = new Color(image.getRGB(x, y));
double gValue = (double)pixelColor.getRed() * 0.2989D + (double)pixelColor.getBlue() * 0.587D + (double)pixelColor.getGreen() * 0.114D;
char s = this.negative ? this.returnStrNeg(gValue) : this.returnStrPos(gValue);
sb.append(s);
}
}
return sb.toString();
}
private char returnStrPos(double g) {
char str;
if (g >= 230.0D) {
str = ' ';
} else if (g >= 200.0D) {
str = '.';
} else if (g >= 180.0D) {
str = '*';
} else if (g >= 160.0D) {
str = ':';
} else if (g >= 130.0D) {
str = 'o';
} else if (g >= 100.0D) {
str = '&';
} else if (g >= 70.0D) {
str = '8';
} else if (g >= 50.0D) {
str = '#';
} else {
str = '@';
}
return str;
}
private char returnStrNeg(double g) {
char str;
if (g >= 230.0D) {
str = '@';
} else if (g >= 200.0D) {
str = '#';
} else if (g >= 180.0D) {
str = '8';
} else if (g >= 160.0D) {
str = '&';
} else if (g >= 130.0D) {
str = 'o';
} else if (g >= 100.0D) {
str = ':';
} else if (g >= 70.0D) {
str = '*';
} else if (g >= 50.0D) {
str = '.';
} else {
str = ' ';
}
return str;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new 1());
}
}