-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRainbowPix.java
92 lines (89 loc) · 1.65 KB
/
RainbowPix.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
/**
* Class RainbowPix
* @author Nic Manoogian <zimmoz3@verizon.net>
* @author Mike Lyons
*/
public class RainbowPix extends NonconformingPix
{
/**
* Default constructor
* Calls Pix()
*/
public RainbowPix()
{
int choosecolor = (int) (Math.random() * 3);
switch (choosecolor)
{
case 0:
red = 255;
green = 0;
blue = 0;
break;
case 1:
red = 0;
green = 255;
blue = 0;
break;
case 2:
red = 0;
green = 0;
blue = 255;
break;
}
}
/**
* Constructs with RGB values
* Calls Pix(r, g, b)
* @param r red channel
* @param g green channel
* @param b blue channel
*/
public RainbowPix(int r, int g, int b)
{
this();
}
/**
* Moves a Pix
* @param ix inital x location
* @param ix inital y location
* @param x ending x location
* @param y ending y location
*/
public void movePixel(Pix[][] grid, int ix, int iy, int x, int y)
{
Spawner.spawnXY( grid[ix][iy].getClass(), x, y );
int newr = red;
int newg = green;
int newb = blue;
int growth = 5;
if (newr == 255 && newg + growth <= 255 && newb == 0)
{
newg += growth;
}
else if (newr >= growth && newg == 255 && newb == 0)
{
newr -= growth;
}
else if (newr == 0 && newg == 255 && newb + growth <= 255)
{
newb += growth;
}
else if (newr == 0 && newg >= growth && newb == 255)
{
newg -= growth;
}
else if (newr + growth <= 255 && newg == 0 && newb == 255)
{
newr += growth;
}
else if (newr == 255 && newg == 0 && newb >= growth)
{
newb -= growth;
}
// Possible Inversion
// newr = 255-newr;
// newg = 255-newg;
// newb = 255-newb;
grid[x][y].setPix(newr, newg, newb);
}
}