-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeorgesFilter.pde
130 lines (100 loc) · 2.93 KB
/
georgesFilter.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
import sojamo.drop.*;
SDrop drop;
import java.util.Calendar;
PImage logoGeorges;
PImage backgroundImage;
int tileCountX = 20;
int tileCountY = 20;
int tileCount = tileCountX*tileCountY;
PImage[] imageTiles = new PImage[tileCount];
int tileWidth, tileHeight;
int cropX = 0;
int cropY = 0;
boolean selectMode = true;
boolean randomMode = true;
boolean logoColor = true; // true = white, false = black
float randomfactor = 1.6;
void setup() {
size(1000, 1000);
noCursor();
tileWidth = width/tileCountY;
tileHeight = height/tileCountX;
backgroundImage = loadImage("background.png");
printLogo(true);
drop = new SDrop(this);
}
void draw() {
if (selectMode == true) {
// in selection mode, a white selection rectangle is drawn over the image
cropX = constrain(mouseX, 0, width-tileWidth);
cropY = constrain(mouseY, 0, height-tileHeight);
image(backgroundImage, 0, 0);
noFill();
stroke(255);
rect(cropX, cropY, tileWidth, tileHeight);
} else {
// reassemble image
int i = 0;
for (int gridY = 0; gridY < tileCountY; gridY++) {
for (int gridX = 0; gridX < tileCountX; gridX++) {
image(imageTiles[i], gridX*tileWidth, gridY*tileHeight);
i++;
}
}
}
image(logoGeorges, 0, 0);
}
void cropTiles() {
tileWidth = width/tileCountY;
tileHeight = height/tileCountX;
tileCount = tileCountX * tileCountY;
imageTiles = new PImage[tileCount];
int i = 0;
for (int gridY = 0; gridY < tileCountY; gridY++) {
for (int gridX = 0; gridX < tileCountX; gridX++) {
if (randomMode) {
cropX = (int) random(mouseX-tileWidth/randomfactor, mouseX+tileWidth/randomfactor);
cropY = (int) random(mouseY-tileHeight/randomfactor, mouseY+tileHeight/randomfactor);
}
cropX = constrain(cropX, 0, width-tileWidth);
cropY = constrain(cropY, 0, height-tileHeight);
imageTiles[i++] = backgroundImage.get(cropX, cropY, tileWidth, tileHeight);
}
}
}
void printLogo(boolean logoColor) {
if (logoColor) {
logoGeorges = loadImage("logo-white.png");
} else {
logoGeorges = loadImage("logo-black.png");
}
}
void dropEvent(DropEvent theDropEvent) {
println("");
println("isFile()\t"+theDropEvent.isFile());
println("isImage()\t"+theDropEvent.isImage());
println("isURL()\t"+theDropEvent.isURL());
// if the dropped object is an image, then
// load the image into our PImage.
if (theDropEvent.isImage()) {
println("### loading image ...");
backgroundImage = theDropEvent.loadImage();
}
}
void mouseMoved() {
selectMode = true;
}
void mouseReleased() {
selectMode = false;
cropTiles();
}
void keyReleased() {
if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png");
if (key == 'b' || key == 'B') printLogo(true);
if (key == 'n' || key == 'N') printLogo(false);
}
// timestamp
String timestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}