-
Notifications
You must be signed in to change notification settings - Fork 3
/
TransitionState.pde
99 lines (79 loc) · 2.09 KB
/
TransitionState.pde
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
class TransitionState
{
Bubble[] bubbles;
BlackBlobAnalyzer blob;
PVector blobCenter;
TransitionState(String imageFileName)
{
bubbles = new Bubble[NUM_BUBBLES];
blob = new BlackBlobAnalyzer(imageFileName);
blobCenter = blob.getBlobCentroid();
}
PVector getTangent(int bubbeNum, float scale)
{
return bubbles[bubbeNum].getTangentPoint(scale);
}
}
class RandomPositionState extends TransitionState
{
RandomPositionState(String imageFileName)
{
super(imageFileName);
int bubblesInBlob = 0;
while (bubblesInBlob < NUM_BUBBLES)
{
int x = (int) random(0, width);
int y = (int) random(0, height);
if (blob.isInBlob(x, y))
{
bubbles[bubblesInBlob] = new Bubble(x, y, blobCenter, blob.getGrayAt(x, y));
bubblesInBlob++;
}
}
}
}
class RectMoirePositionState extends TransitionState
{
boolean[] usedIndices;
RectMoirePositionState(String imageFileName)
{
super(imageFileName);
PVector topLeft = blob.getTopLeft();
PVector bottomRight = blob.getBottomRight();
int bubblesInBlob = 0;
int upperBound = ceil (sqrt (NUM_BUBBLES));
initUsedIndices();
for (int ix = 0; ix < upperBound ; ix ++)
{
for (int iy = 0; iy < upperBound; iy ++)
{
int x = (int)map(ix, 0, upperBound, topLeft.x, bottomRight.x);
int y = (int)map(iy, 0, upperBound, topLeft.y, bottomRight.y);
bubbles[getRandomUnusedIndex()] = new Bubble(x, y, blobCenter, blob.getGrayAt(x, y));
bubblesInBlob++;
if (bubblesInBlob >= NUM_BUBBLES)
break;
}
if (bubblesInBlob >= NUM_BUBBLES)
break;
}
}
void initUsedIndices()
{
usedIndices = new boolean[NUM_BUBBLES];
for (int i = 0; i<NUM_BUBBLES; i++)
{
usedIndices[i] = false;
}
}
int getRandomUnusedIndex()
{
int index = (int)random(0,NUM_BUBBLES);
while(usedIndices[index])
{
index = (int)random(0,NUM_BUBBLES);
}
usedIndices[index] = true;
return index;
}
}