-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoise.pde
75 lines (61 loc) · 1.91 KB
/
noise.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
class Noise {
int pixelWidth = 10;
int cropSize = 20;
ArrayList<PImage> base = new ArrayList<PImage>();
ArrayList<PImage> pics = new ArrayList<PImage>();
Noise() {
loadBaseImages();
}
void loadBaseImages() {
ArrayList<File> filesList = new ArrayList<File>();
File file = new File(dataPath("imgs"));
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
String path = files[i].getAbsolutePath();
if (!path.endsWith(".jpg") &&
!path.endsWith(".gif") &&
!path.endsWith(".png")) {
continue;
}
base.add(loadImage(path));
}
}
void setup() {
int i = 100;
int imgAmount = base.size();
setupPics(imgAmount);
while (i > 0) {
int rand = int(random(0, imgAmount));
PImage img = base.get(rand);
int x = int(random(width));
x = max(0, x);
x = min(x, width - cropSize);
int y = int(random(height));
y = max(0, y);
y = min(y, height - cropSize);
pics.add(img.get(y, x, cropSize, cropSize));
i -= 1;
}
}
void setupPics(int amount) {
for (int i = 0; i < amount; i += 1) {
base.get(i).resize(width, height);
}
}
void draw() {
for (int i = 0; i < width; i += pixelWidth) {
for (int o = 0; o < height; o += pixelWidth) {
int rand = int(random(0, pics.size()));
image(pics.get(rand), i, o, pixelWidth, pixelWidth);
}
}
}
PImage pic() {
int rand = int(random(pics.size()));
return pics.get(rand);
}
void drawUnit(float x, float y, float unitSize) {
int rand = int(random(0, pics.size()));
image(pics.get(rand), x, y, unitSize, unitSize);
}
}