Skip to content

Commit 8ea09e8

Browse files
committed
adjust gui and rotate matrix
1 parent 9e8ae10 commit 8ea09e8

6 files changed

Lines changed: 93 additions & 66 deletions

File tree

GUI.pde

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,64 @@ public class ControlFrame extends PApplet {
3131
background(0);
3232
List l = java.util.Arrays.asList(photoSets);
3333
cp5 = new ControlP5(this);
34-
35-
cp5.addBang("reload")
36-
.setLabel("REload").setPosition(20, 60).setSize(40, 20);
37-
34+
35+
int y=0;
36+
y+=20;
37+
3838
cp5.addToggle("PLAY")
3939
.plugTo(parent, "play")
40-
.setPosition(20, 20).setSize(w-40, 20);
40+
.setPosition(20, y).setSize(w/2 -25, 20);
41+
42+
cp5.addBang("reload")
43+
.setLabel("REload").setPosition(w/2, y).setSize(w/2-25, 20);
44+
45+
46+
y+=50;
4147

48+
cp5.addToggle("PauseFlip")
49+
.plugTo(parent, "pauseFlip")
50+
.setLabel("No Flip")
51+
.setPosition(20, y).setSize(40, 20);
52+
cp5.addBang("nextImage")
53+
.setLabel("next image")
54+
.setPosition(w/2, y)
55+
.setSize(w/2-25, 20);
56+
57+
58+
59+
y+=50;
60+
4261
cp5.addToggle("Wrap")
4362
.plugTo(parent, "wrap")
4463
.setState(true)
45-
.setPosition(w/2, 60).setSize(40, 20);
64+
.setPosition(w/2, y).setSize(w/3, 20);
65+
cp5.addToggle("Sort Flip")
66+
.plugTo(parent, "logic")
67+
.setPosition(20, y).setSize(w/3, 20)
68+
.setMode(ControlP5.SWITCH);
69+
70+
71+
72+
y+=60;
73+
text("Mode", 20, y);
74+
y+=10;
75+
cp5.addRadioButton("changeMode")
76+
.setPosition(20, y).setSize(30, 20)
77+
.setColorLabel(color(255))
78+
.setItemsPerRow(3)
79+
.setSpacingColumn(30)
4680

47-
text("Sort Matrix", 20, 120);
81+
.addItem("A", 0).addItem("B", 1).addItem("C", 2)
82+
.addItem("D", 3).addItem("E", 4).addItem("F", 5)
83+
.activate(2)
84+
;
85+
y+=60;
86+
87+
text("Sort Matrix", 20, y);
88+
y+=10;
4889
cp5.addCheckBox("sortMatrix")
4990
.setLabel("mode")
50-
.setPosition(20, 130).setSize(40, 20)
91+
.setPosition(20, y).setSize(40, 20)
5192
.setColorLabel(color(255))
5293
.setItemsPerRow(3)
5394
.setSpacingColumn(10)
@@ -56,66 +97,44 @@ public class ControlFrame extends PApplet {
5697
.addItem("4", 0).addItem("5", 0).addItem("6", 0)
5798
.addItem("7", 0).addItem("8", 0).addItem("9", 0)
5899
;
59-
60-
text("Mode", 20, 220);
61-
cp5.addRadioButton("changeMode")
62-
.setPosition(20, 230).setSize(15, 15)
63-
.setColorLabel(color(255))
64-
.setItemsPerRow(6)
65-
.setSpacingColumn(15)
66-
67-
.addItem("A", 0).addItem("B", 1).addItem("C", 2)
68-
.addItem("D", 3).addItem("E", 4).addItem("F", 5)
69-
.activate(2)
70-
;
71-
100+
y+=90;
101+
72102
cp5.addRange("range")
73103
.setBroadcast(false)
74-
.setPosition(20, 270)
104+
.setPosition(20, y)
75105
.setSize(w-60, 20)
76106
.setHandleSize(10)
77107
.setRange(0, 255)
78-
.setRangeValues(50, 100)
108+
.setRangeValues(20, 150)
79109
.setBroadcast(true)
80110
;
81-
82-
cp5.addToggle("Sort Flip")
83-
.plugTo(parent, "logic")
84-
.setPosition(20, 300).setSize(60, 20)
85-
.setMode(ControlP5.SWITCH);
86-
111+
112+
113+
y+=50;
87114
cp5.addSlider("FRate")
88115
.plugTo(parent, "frameRate")
89116
.setRange(0.5, 40)
90117
.setValue(25)
91-
.setPosition(20, 360)
118+
.setPosition(20, y)
92119
.setSize(w-60, 20)
93120
;
94121

95-
cp5.addBang("nextImage")
96-
.setLabel("next image")
97-
.setPosition(w/2, 410)
98-
.setSize(w/3, 20);
99-
100-
cp5.addToggle("PauseFlip")
101-
.plugTo(parent, "pauseFlip")
102-
.setLabel("No Flip")
103-
.setPosition(20, 410).setSize(w/3, 20);
104-
105-
122+
y+=30;
106123
cp5.addSlider("flipTime")
107124
.plugTo(parent, "flipSpeed")
108125
.setRange(2, 200)
109126
.setValue(30)
110-
.setPosition(20, 460)
111-
.setSize(w-100, 20)
112-
;
113-
127+
.setPosition(20, y)
128+
.setSize(w/2, 20)
129+
;
130+
131+
114132

133+
y+=60;
115134
Group g3 = cp5.addGroup("g3")
116135
.setLabel("Albums")
117-
.setPosition(20, 520)
118-
.setSize(160, 100)
136+
.setPosition(20, y)
137+
.setSize(w-40, 100)
119138
.setBackgroundColor(color(50))
120139
;
121140

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ Let's go through what the control window let's you do:
3737

3838
* Play = starts and stops the pixel sorting
3939
* Reload = restart the sorting on the current image
40-
* Wrap = toggle wrapping pixels on image edges on/off (default: on)
4140

41+
* No Flip = toggle flipping image in the photoset (default: on)
42+
* Next Image = load next image in the photoset
4243

43-
* Sort Matrix = the direction in which the sorting is to be done
44-
* Mode = choose between 6 sorting algorithims
45-
4644

47-
* Range = lower and upper brightness thersholds of which pixels to be sorted
4845
* Sort Flip = flip the sorting thersholds
46+
* Wrap = toggle wrapping pixels on image edges on/off (default: on)
4947

48+
* Mode = choose between 6 sorting algorithims
49+
* Sort Matrix = the direction in which the sorting is to be done
5050

51-
* Frate = speed control, it really changes the sketch's framerate
51+
52+
* Range = lower and upper brightness thersholds of which pixels to be sorted
5253

5354

54-
* No Flip = toggle flipping image in the photoset (default: on)
55-
* Next Image = load next image in the photoset
55+
* Frate = speed control, it really changes the sketch's framerate
5656
* Flip Time = set how long it takes between image flips, the higher the value the slower the flip
5757

5858
* Albums = load another album

cellSort.pde

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22

3+
34
// using Phillip Davis Stearns' cell sort sketch at
45

56
// https://github.com/phillipdavidstearns/aYearInCode/blob/master/Processing%202.2.1/cellSort/cellSort.pde
@@ -13,6 +14,7 @@ int[] swapPixels(int[] _pixelArray, int _index1, int _index2) {
1314
}
1415

1516
PImage cellSort(PImage _image) {
17+
_image.loadPixels();
1618
int swap_x = 0;
1719
int swap_y = 0;
1820
int neighbor_x = 0;
@@ -24,7 +26,7 @@ PImage cellSort(PImage _image) {
2426
swap_y = y;
2527
for (int ny = 0; ny < 3; ny++ ) {
2628
for (int nx = 0; nx < 3; nx++) {
27-
if (rules[nx][ny] /*&& (nx != 1 && ny != 1)*/) {
29+
if (rules[ny][nx] /*&& (nx != 1 && ny != 1)*/) {
2830
if (!wrap) {
2931
neighbor_x = x + (nx-1);
3032
neighbor_y = y + (ny-1);
@@ -82,6 +84,7 @@ PImage cellSort(PImage _image) {
8284
}
8385
}
8486
}
87+
_image.updatePixels();
8588
return _image;
8689
}
8790

@@ -107,3 +110,4 @@ boolean coordinateInBounds(PImage _image, int x, int y) {
107110
boolean pixelWithinWindow(PImage _image, int x, int y, int lower, int higher) {
108111
return _image.pixels[y*_image.width+x] < color(lower) && _image.pixels[y*_image.width+x] > color(higher);
109112
}
113+

pixelSortLive.pde

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
/**
24
* Pixel sorting for photo sets
35
* + a GUI extra window
@@ -14,18 +16,19 @@
1416
* by Youssef Faltas, 2017
1517
* https://github.com/faltastic/pixelSortLive
1618
*
17-
*/
19+
**/
1820

1921
////////////////////////////////////////////////////////////////
2022
//
2123
// To add your own photo sets, place them in
2224
// the data folder and add their names here
2325

2426
String[] photoSets = {
25-
"cosmos", "desert" // more albums here
27+
"cosmos",
28+
"desert"
29+
// more albums here
2630
};
2731

28-
2932
// Each photo set may contain jpg photos of any size but they are
3033
// to be named "poly0.jpg", "poly1.jpg", "poly2.jpg", and so on.
3134

@@ -51,7 +54,7 @@ int type = 1;
5154
int offset_x = 0;
5255
int offset_y = 0;
5356
int eval_mode = 0;
54-
int mode = 0; //sets the threshold evaluation mode
57+
int mode = 2; //sets the threshold evaluation mode
5558
boolean[][] rules;
5659
int logic = 0;
5760
int printFNum =0;
@@ -73,8 +76,6 @@ boolean pauseFlip = false;
7376
void setup() {
7477

7578
size(1080, 720);
76-
// alternative setup
77-
// size(source.width, source.height);
7879

7980
cf = addControlFrame("Sort Control", 200, 650);
8081
setRules();
@@ -94,15 +95,16 @@ void draw() {
9495
loadSource();
9596
}
9697

97-
source.loadPixels();
98+
9899
output = cellSort(source);
99-
output.updatePixels();
100+
100101
background(0);
101102
image(output, width/2,height/2);
102103

103104
if (printFrame) {
104105
println("printing");
105-
saveFrame("Prints/s"+printFNum +".tif");
106+
saveFrame("frame-######.tif");
107+
//saveFrame("Prints/s"+printFNum +".tif");
106108
printFNum++;
107109
}
108110
}
@@ -124,9 +126,11 @@ void selectSet(int nSet) {
124126
void loadSrcs() {
125127
loaded=false;
126128
polySrc = new PImage[totalImg];
129+
/* unneccesary and changing album is must faster now
127130
for (int i=0; i<totalImg; i++) {
128-
polySrc[i] = loadImage(photoSets[nSet]+"/poly"+i+".jpg");
131+
polySrc[i] = loadImage(photoSets[nSet]+"/poly"+i+".jpg");
129132
}
133+
*/
130134
}
131135

132136
void loadSource() {

screenshots/gui.jpg

-728 Bytes
Loading

screenshots/main.jpg

218 KB
Loading

0 commit comments

Comments
 (0)