forked from mtchllbrrn/glitch_art
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.txt
102 lines (82 loc) · 1.76 KB
/
example.txt
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
PImage img;
String imgFileName = "PIA15635";
String fileType = "png";
int loops = 1;
int blackValue = -16000000;
int brigthnessValue = 60;
int whiteValue = -13000000;
int row = 0;
int column = 0;
boolean saved = false;
void setup() {
img = loadImage(imgFileName+"."+fileType);
size(img.width, img.height);
image(img, 0, 0);
}
void draw() {
while(column < width-1) {
img.loadPixels();
sortColumn();
column++;
img.updatePixels();
}
while(row < height-1) {
img.loadPixels();
sortRow();
row++;
img.updatePixels();
}
image(img,0,0);
if(!saved && frameCount >= loops) {
saveFrame(imgFileName+"_"+mode+".png");
saved = true;
println("DONE"+frameCount);
System.exit(0);
}
}
void sortColumn() {
int x = column;
int y = 0;
int yend = 0;
while(yend < height-1) {
y = getFirstNotBlackY(x, y);
yend = getNextBlackY(x, y);
if(y < 0) break;
int sortLength = yend-y;
color[] unsorted = new color[sortLength];
color[] sorted = new color[sortLength];
for(int i=0; i<sortLength; i++) {
unsorted[i] = img.pixels[x + (y+i) * img.width];
}
sorted = sort(unsorted);
for(int i=0; i<sortLength; i++) {
img.pixels[x + (y+i) * img.width] = sorted[i];
}
y = yend+1;
}
}
//BLACK
int getFirstNotBlackY(int _x, int _y) {
int x = _x;
int y = _y;
color c;
if(y < height) {
while((c = img.pixels[x + y * img.width]) < blackValue) {
y++;
if(y >= height) return -1;
}
}
return y;
}
int getNextBlackY(int _x, int _y) {
int x = _x;
int y = _y+1;
color c;
if(y < height) {
while((c = img.pixels[x + y * img.width]) > blackValue) {
y++;
if(y >= height) return height-1;
}
}
return y-1;
}