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
|
void setup() {
size(768, 256);
PImage img = loadImage("monkey.jpg");
img.resize(256, 256);
img.filter(GRAY);
image(img, 0, 0);
PImage revimg = rev(img);
image(revimg, 256, 0);
int random_number = (int)random(5, 15); // [5, 15)
image(mass(revimg, random_number), 512, 0);
}
PImage rev(PImage I) {
PImage out = I.copy();
int t;
for (int row = 0; row < out.width; ++row) {
for (int i = 0, j = out.width-1; i < out.width/2; ++i, --j) {
t = out.get(i, row);
out.set(i, row, out.get(j, row));
out.set(j, row, t);
}
}
// yellow pixels
for (int i = 0; i < out.width; ++i)
out.set(i, i, color(#EFFC38));
return out;
}
PImage mass(PImage I, int n) {
PImage out = createImage(I.width, I.height, RGB);
// image and array aux
PImage tmp;
float[] tarr = new float[n*n];
int off = n/2;
for(int i = 0; i < out.width; ++i) {
for(int j = 0; j < out.height; ++j) {
tmp = I.get(i-off, j-off, n, n);
tmp.loadPixels();
for(int k = 0; k < tmp.pixels.length; ++k) {
tarr[k] = red(tmp.pixels[k]);
}
out.set(i, j, color(max(tarr)));
}
}
return out;
}
|