-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyColor.java
More file actions
97 lines (84 loc) · 2.16 KB
/
MyColor.java
File metadata and controls
97 lines (84 loc) · 2.16 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
92
93
94
95
96
97
/* Name: Clara Fee, Julia Rieger
* File: MyColor.java
* Desc:
*
* Class to store one pixel with its RGB value and index within the image
*
*/
public class MyColor implements Comparable<MyColor> {
private int red;
private int green;
private int blue;
private int i; //HEIGHT idx
private int j; //WIDTH idx
public MyColor(int red, int green, int blue) {
this.red = red;
this.green = green;
this.blue = blue;
this.i = -1;
this.j = -1;
}
public MyColor(int red, int green, int blue, int i, int j) {
this.red = red;
this.green = green;
this.blue = blue;
this.i = i;
this.j = j;
}
public int getR() {
return this.red;
}
public int getG() {
return this.green;
}
public int getB() {
return this.blue;
}
public int getI() {
return this.i;
}
public int getJ() {
return this.j;
}
public void setColor(int red, int green, int blue) {
this.red = red;
this.green = green;
this.blue = blue;
}
public void setRed(int red) {
this.red = red;
}
public void setGreen(int green) {
this.green = green;
}
public void setBlue(int blue) {
this.blue = blue;
}
public void shade(double shadeFactor) {
this.red = (int) (this.red * shadeFactor);
this.green = (int) (this.green * shadeFactor);
this.blue = (int) (this.blue * shadeFactor);
}
public void negative() {
this.red = 255 - this.red;
this.green = 255 - this.green;
this.blue = 255 - this.blue;
}
public void greyScale() {
int c = (int) (this.red * 0.3 + this.green * 0.59 + this.blue * 0.11);
this.red = c;
this.green = c;
this.blue = c;
}
public String toString() {
return this.red + "/" + this.green + "/" + this.blue;
}
public int compareTo(MyColor c) {
if ((this.i == c.i) && (this.j == c.j)) {
return 0;
}
else {
return -1;
}
}
}