-
Notifications
You must be signed in to change notification settings - Fork 28
/
Weaver.pde
100 lines (76 loc) · 1.81 KB
/
Weaver.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
// how many lines to be drawn in every iteration?
int fps = 100;
// pause after every iteration?
boolean stepByStep = false;
boolean paused = true;
boolean done = false;
Frame frame;
Layer layer;
int block_size;
void setup() {
size(1200, 600);
block_size = height;
try {
Example example;
// if you want a black/white output
// example = example01();
// if you want colored output, but have colors separated out yourself
// example = example02();
// if you want colored output, and rely on Weaver's algorithm to separate out colors for you
example = example03();
frame = example.frame;
layer = example.layer;
} catch(Exception e) {
println(e);
exit();
}
}
void drawAll() {
background(255);
if (frame == null || layer == null) {
return;
}
translate(0, 0);
shape(frame.getFrameShape(), 0, 0, block_size, block_size);
translate(block_size, 0);
image(layer.getOriginalImage(), 0, 0, block_size, block_size);
translate(-block_size, 0);
PShape[] lines = frame.getLineShapes(layer.getLines());
for (PShape line : lines) {
shape(line, 0, 0, block_size, block_size);
}
}
void mouseReleased() {
// toggle pause
paused = !paused;
}
void draw() {
if (done) return;
if (!paused) {
for (int i = 0; i < fps; ++i) {
boolean layerDone = layer.drawNextLine();
if (layerDone) {
done = true;
}
}
}
drawAll();
if (done) {
selectOutput("Select a file to write to:", "writeToFile");
}
if (stepByStep) {
paused = true;
}
}
void writeToFile(File selection) {
if (selection == null) {
return;
}
PrintWriter file;
file = createWriter(selection.getAbsolutePath());
for (Line line : layer.getLines()) {
file.println(line.index + " ; Color: #" + hex(line.c));
}
file.flush();
file.close();
}