-
Notifications
You must be signed in to change notification settings - Fork 1
/
AgingPix.java
114 lines (107 loc) · 1.58 KB
/
AgingPix.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* Class AgingPix
* @author Nic Manoogian <[email protected]>
* @author Mike Lyons
*/
public class AgingPix extends Pix
{
/*
* Whether or not a color is returning to white
*/
private boolean dying;
/**
* Default constructor
* Calls Pix()
*/
public AgingPix()
{
super();
dying = false;
}
/**
* Constructs with RGB values
* Calls Pix(r, g, b)
* @param r red channel
* @param g green channel
* @param b blue channel
*/
public AgingPix(int r, int g, int b)
{
super(r, g, b);
dying = false;
}
/**
* Changes both Pix objects with respect to dominant channel
* @param p Pix interactee
*/
public void interact(Pix p)
{
changeWithChannel(getDomChannel());
p.changeWithChannel(p.getDomChannel());
}
/**
* Increases dominant channel, but should slowly fade out
* @param channel dominant channel
*/
public void changeWithChannel(int channel)
{
int inc = 1;
if (dying)
{
if (red < 255)
{
red++;
}
if (green < 255)
{
green++;
}
if (blue < 255)
{
blue++;
}
}
switch (channel)
{
case 0:
//Inc dominant
if (red + inc <= 255)
{
red += inc;
}
else
{
//red = 100;
dying = true;
}
break;
case 1:
//Inc dominant
if (blue + inc <= 255)
{
blue += inc;
}
else
{
//blue = 100;
dying = true;
}
break;
case 2:
//Inc dominant
if (green + inc <= 255)
{
green += inc;
}
else
{
//green = 100;
dying = true;
}
break;
case -1:
dying = true;
break;
}
}
}