-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpiralPix.java
85 lines (80 loc) · 1.78 KB
/
SpiralPix.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
/**
* Class SpiralPix
* Pixels that create a spiral pattern
* @author Nic Manoogian <zimmoz3@verizon.net>
* @author Mike Lyons
*/
public class SpiralPix extends DirectedPix
{
/*
* Length of growth
*/
private int length;
private int startinglength;
/**
* Constructs a SpiralPix with a random direction
*/
public SpiralPix()
{
super();
startinglength = 0;
length = startinglength;
}
/**
* Constructs a SpiralPix with a specific direction and color
*/
public SpiralPix(int r, int g, int b, int direction)
{
super(r,g,b,direction);
startinglength = 0;
length = startinglength;
}
public void setLengths(int l, int sl)
{
length = l;
startinglength = sl;
}
/**
* Transitions a Pix from one location to another
* If the Pix is white, the Pix is moved. Otherwise, one Pix interacts with the other
* @param ix inital x location
* @param ix inital y location
* @param x ending x location
* @param y ending y location
*/
public void trans(Pix[][] grid, int ix, int iy, int x, int y)
{
if (length > 0)
{
length--;
// Didn't try to move out of bounds
if (!(x < 0 || x >= grid.length || y < 0 || y >= grid[0].length) && (grid[x][y].isWhite()))
{
Spawner.spawnXY( grid[ix][iy].getClass(), x, y );
grid[x][y].setPix(grid[ix][iy]);
((SpiralPix)grid[x][y]).setDir(direction);
((SpiralPix)grid[x][y]).setLengths(length, startinglength);
grid[ix][iy] = new StaticPix(grid[ix][iy].getRed(),grid[ix][iy].getGreen(),grid[ix][iy].getBlue());
}
// Stop circling if you move out of bounds or touch
else
{
startinglength = 0;
length = -1;
}
}
else if (length != -1)
{
if (direction == 3)
{
direction = 0;
}
else
{
direction++;
}
startinglength += 4;
length = startinglength;
}
}
}