-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpixelSortLive.pde
199 lines (161 loc) · 4.14 KB
/
pixelSortLive.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* Pixel sorting for photo sets
* + a GUI extra window
* v 1.1
*
* This sketch performs pixel sorting on a collection of
* photo sets. It was built to be used in live performances.
*
* for the GUI, I use controlP5 which works ok on Processing 2 but not 3.
* http://www.sojamo.de/libraries/controlP5/
*
* the sorting algorithim is from Phillip Davis Stearns' sketch at
* https://github.com/phillipdavidstearns/aYearInCode/blob/master/Processing%202.2.1/cellSort/cellSort.pde
*
* by Youssef Faltas, 2018
* https://github.com/faltastic/pixelSortLive
*
**/
////////////////////////////////////////////////////////////////
//
// To add your own photo sets, place them in
// the data folder and add their names here
String[] photoSets = {
"cosmos",
"desert"
// more albums here
};
// Each photo set may contain jpg photos of any size but they are
// to be named "poly0.jpg", "poly1.jpg", "poly2.jpg", and so on.
// That's it!
////////////////////////////////////////////////////////////////
import java.io.FilenameFilter;
import java.awt.Frame;
import java.awt.BorderLayout;
import controlP5.*;
import java.util.*;
private ControlP5 cp5;
ControlFrame cf;
PImage[] polySrc;
PImage source;
PImage output;
int higher=110;
int lower=190;
int type = 1;
int offset_x = 0;
int offset_y = 0;
int eval_mode = 0;
int mode = 2; //sets the threshold evaluation mode
boolean[][] rules;
int logic = 0;
int printFNum =0;
int nImg =0;
int totalImg =3;
int nSet=0;
int flipSpeed = 30;
int sortSpeed =1;
boolean randomMode = false;
boolean randomMatrix = false;
boolean loaded = false;
float hueOverlay = 0;
color overlayHue = 100;
float overlayAlpha =0;
// Control States
boolean play = false;
boolean wrap = true;
boolean printFrame = false; // P turns on/off print function
boolean pauseFlip = false;
void setup() {
size(1080, 720);
cf = addControlFrame("Sort Control", 200, 720);
rules = new boolean[3][3];
setRules();
selectSet(0);
loadSource();
imageMode(CENTER);
background(0);
image(source, width/2, height/2);
colorMode(HSB, 255);
}
void draw() {
if (play && loaded) {
if (frameCount%flipSpeed ==0 && !pauseFlip ) {
if (randomMode) {
mode=floor(random(6));
}
if (randomMatrix) {
setRandomMatrix();
}
nImg = (nImg+1)%totalImg;
loadSource();
}
output = cellSort(source);
background(0);
if (overlayHue!=0) {
tint(overlayHue, 150, 255, overlayAlpha);
}
image(output, width/2, height/2);
noTint();
if (printFrame) {
printFrame =false;
println("printing");
saveFrame("frame-######.tif");
}
}
}
// Loading images and image sets
void selectSet(int nSet) {
loaded=false;
File f = dataFile(photoSets[nSet]);
String[] names = f.list(FILTER);
println(names.length);
totalImg = names.length;
nImg=0;
//loadSrcs();
loadSource();
}
void loadSource() {
loaded=false;
source = loadImage(photoSets[nSet]+"/poly"+nImg+".jpg");
if (source.width>0) { //making sure source loaded
if (source.height > source.width) {
source.resize(0, height); // portrait
} else {
source.resize(width, 0); // landscape
}
source.resize(0, height);
output = source;
imageMode(CENTER);
background(0);
image(source, width/2, height/2);
loaded = true;
}
}
static final FilenameFilter FILTER = new FilenameFilter() {
static final String NAME = "poly", EXT = ".jpg";
@ Override boolean accept(File path, String name) {
return name.startsWith(NAME) && name.endsWith(EXT);
}
};
void setRules() {
rules[0][0]=false;
rules[0][1]=false;
rules[0][2]=false;
rules[1][0]=false;
rules[1][1]=false;
rules[1][2]=false;
rules[2][0]=false;
rules[2][1]=false;
rules[2][2]=false;
}
void setRandomMatrix() {
rules[0][0]=boolean(floor(random(1.5)));
rules[0][1]=boolean(floor(random(1.5)));
rules[0][2]=boolean(floor(random(1.5)));
rules[1][0]=boolean(floor(random(1.5)));
rules[1][1]=false;
rules[1][2]=boolean(floor(random(1.5)));
rules[2][0]=boolean(floor(random(1.5)));
rules[2][1]=boolean(floor(random(1.5)));
rules[2][2]=boolean(floor(random(1.5)));
}