-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRgb.java
46 lines (40 loc) · 845 Bytes
/
Rgb.java
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
package rayCast;
import org.eclipse.swt.graphics.*;
public class Rgb {
public double r;
public double g;
public double b;
public Rgb(double x,double y, double z){
r=x;
g=y;
b=z;
}
public RGB getColor(){
int r = (int)Math.round(this.r * 255.0);
if (r > 255)
r=255;
if (r < 0)
r=0;
int g = (int)Math.round(this.g * 255.0);
if (g > 255)
g=255;
if (g < 0)
r=0;
int b = (int)Math.round(this.b * 255.0);
if (b > 255)
b=255;
if (b < 0)
b=0;
RGB color = new RGB(r,g,b);
return color;
}
public Rgb add(Rgb rgb){
return new Rgb(this.r+rgb.r,this.g+rgb.g,this.b+rgb.b);
}
public Rgb DivByDouble(double d){
return new Rgb(this.r/d,this.g/d,this.b/d);
}
public Rgb multByDouble(double d){
return new Rgb(this.r*d,this.g*d,this.b*d);
}
}