-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_func.pde
62 lines (50 loc) · 1.61 KB
/
main_func.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
int findMatch(color c) {
float r = red(c);
float g = green(c);
float b = blue(c);
float smallest = 255*3;
int winner = -1;
for (int i=0;i<pics.length;i++) {
float rDiff = abs(pics[i].avgRed-r);
float gDiff = abs(pics[i].avgGreen-g);
float bDiff = abs(pics[i].avgBlue-b);
float total = rDiff+gDiff+bDiff;
if (total<smallest) {
winner = i;
smallest = total;
}
}
return winner;
}
////////////////////////////////////////////
////////////////////////////////////////////
////////////////////////////////////////////
void createFaces() {
int counter = 0;
master.loadPixels();
for (int xStep=0;xStep<xDim;xStep++) {
for (int yStep=0;yStep<yDim;yStep++) {
if (counter<faces.length) {
faces[counter] = createImage(master.width/xDim, master.height/yDim, ARGB);
faces[counter].loadPixels();
for (int xAdd=0;xAdd<=master.width/xDim;xAdd++) {
for (int yAdd=0;yAdd<=master.height/yDim;yAdd++) {
int x = xAdd+(xStep*(master.width/xDim));
int y = yAdd+(yStep*(master.height/yDim));
int mIndex = x + (y*master.width);
int fIndex = xAdd + (yAdd*(master.width/xDim));
if (fIndex<faces[counter].pixels.length && mIndex<master.pixels.length) {
faces[counter].pixels[fIndex] = master.pixels[mIndex];
}
}
}
pics[counter] = new Pic(faces[counter]);
counter++;
}
}
}
master.updatePixels();
}
////////////////////////////////////////////
////////////////////////////////////////////
////////////////////////////////////////////