@@ -2,61 +2,63 @@ import java.util.Random;
2
2
3
3
PImage img;
4
4
int y;
5
- int p;
5
+ int randomFactor;
6
6
7
7
void setup () {
8
8
size (640 , 360 );
9
9
frameRate (120 );
10
+
10
11
img = loadImage (" moonwalk.jpg" );
12
+ randomFactor = 10 ; // vary this to get different results
11
13
y = 0 ;
12
- p = 1 ;
13
14
}
14
15
15
16
void draw () {
16
17
background (255 );
17
18
PImage buf = createImage (img. width , img. height , RGB );
18
- buf = img. copy();
19
-
19
+ // randomize sampling window
20
+ int p = int (max (random (1 , randomFactor), 1 ));
21
+
20
22
for (int x= 0 ; x < img. width ; x += p) {
21
23
for (int y= 0 ; y < img. height ; y++ ) {
22
24
color [] colors = new color [p];
23
25
for (int i= 0 ; i < p; i++ ) {
24
26
int index = x+ i;
25
- colors[i] = img. get(index, y);
26
- if (index >= img. width - 1 ) {
27
- break ;
27
+ // wrap over if we reached the boundaries
28
+ if (index >= img. width - 1 ) {
29
+ colors[i] = img. get(i, y);
30
+ } else {
31
+ colors[i] = img. get(index, y);
28
32
}
29
33
}
30
-
34
+
31
35
shuffleColors(colors);
32
-
36
+
33
37
for (int i= 0 ; i < p; i++ ) {
34
38
int index = x+ i;
35
39
color c = colors[i];
36
- buf. set(index, y, c);
37
- if (index >= img. width - 1 ) {
38
- break ;
40
+ if (index >= img. width - 1 ) {
41
+ buf. set(i, y, c);
42
+ } else {
43
+ buf. set(index, y, c);
39
44
}
40
45
}
41
46
}
42
47
}
43
-
48
+
44
49
img = buf;
45
50
image (img, 0 , 0 );
46
- p++ ;
47
51
}
48
52
49
53
void shuffleColors (color [] array ) {
50
- int index;
51
- Random random = new Random ();
52
- for (int i = array. length - 1 ; i > 0 ; i-- )
53
- {
54
- index = random. nextInt(i + 1 );
55
- if (index != i)
56
- {
57
- array[index] ^= array[i];
58
- array[i] ^= array[index];
59
- array[index] ^= array[i];
60
- }
54
+ int index;
55
+ Random random = new Random ();
56
+ for (int i = array. length - 1 ; i > 0 ; i-- ) {
57
+ index = random. nextInt(i + 1 );
58
+ if (index != i) {
59
+ array[index] ^= array[i];
60
+ array[i] ^= array[index];
61
+ array[index] ^= array[i];
61
62
}
63
+ }
62
64
}
0 commit comments