-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuickPix.java
88 lines (83 loc) · 1.56 KB
/
QuickPix.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
/**
* Class QuickPix
* Chooses a growth speed and moves a that pace
* @author Nic Manoogian <zimmoz3@verizon.net>
* @author Mike Lyons
*/
public class QuickPix extends AgingPix
{
/*
* Speed of spread
*/
private int growthspeed;
/**
* Default constructor
* Calls Pix()
*/
public QuickPix()
{
super();
growthspeed = (int)(Math.random()*4) + 1;
}
/**
* Constructs with RGB values
* Calls Pix(r, g, b)
* @param r red channel
* @param g green channel
* @param b blue channel
*/
public QuickPix(int r, int g, int b)
{
super(r, g, b);
growthspeed = (int)(Math.random()*4) + 1;
}
/**
* Changes both Pix objects with respect to dominant channel
* @param p Pix interactee
*/
public void interact(Pix p)
{
changeWithChannel(getDomChannel());
p.changeWithChannel(p.getDomChannel());
}
/**
* Moves the direction given (N S E W)
* Moves a jump with speed growthspeed
* @param grid PixGrid object
* @param dirNum direction to move
* @param i x location of pixel
* @param j y location of pixel
*/
public void moveDir(Pix[][] grid, int dirNum, int i, int j)
{
switch(dirNum)
{
case 0:
for (int n = 0; n < growthspeed; n++)
{
trans(grid, i,j,i+n,j);
}
break;
case 1:
for (int n = 0; n < growthspeed; n++)
{
trans(grid, i,j,i,j+n);
}
break;
case 2:
for (int n = 0; n < growthspeed; n++)
{
trans(grid, i,j,i-n,j);
}
break;
case 3:
for (int n = 0; n < growthspeed; n++)
{
trans(grid, i,j,i,j-n);
}
break;
default:
break;
}
}
}