-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiffusion.pde
More file actions
106 lines (100 loc) · 2.49 KB
/
Copy pathdiffusion.pde
File metadata and controls
106 lines (100 loc) · 2.49 KB
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
/*
Keyboard controls:
m : switch between monochrome and colour drawing
space : pause growth
n : new drawing, but keep old background
r : new drawing but erase background
s : save in project folder
*/
PGraphics bg;
PGraphics newLayer;
int mx;
int my;
boolean test = false;
boolean pause = false;
boolean monochrome = false;
void setup() {
size(800, 800);
bg = createGraphics(width, height);
newLayer = createGraphics(width, height);
background(128);
bg.beginDraw();
//bg.background(255);
bg.stroke(0);
bg.strokeWeight(3);
bg.strokeCap(ROUND);
bg.endDraw();
newLayer.beginDraw();
newLayer.stroke(0);
newLayer.strokeWeight(6);
newLayer.strokeCap(ROUND);
newLayer.endDraw();
}
void draw() {
if (mousePressed) {
bg.beginDraw();
if (monochrome) {
bg.stroke(random(255));
} else {
bg.stroke(random(255), random(255), random(255));
}
bg.line(mouseX, mouseY, mx, my);
bg.endDraw();
image(bg, 0, 0);
mx = mouseX;
my = mouseY;
} else if (pause == false) {
bg.loadPixels();
newLayer.beginDraw();
for (int x = 1; x < width-1; x++) {
for (int y = 1; y < height-1; y++) {
test = false;
if (alpha(bg.pixels[x+y*width]) > 0) {
for (int i = -1; i < 2; i++) {
for (int j = -1; j < 2; j++) {
if (alpha(bg.pixels[x+i+(y+j)*width]) == 0) {
test = true;
}
}
}
}
if (test) {
// newLayer.stroke(255-brightness(bg.pixels[x+y*width]));
newLayer.stroke(255-red(bg.pixels[x+y*width]), 255-green(bg.pixels[x+y*width]), 255-blue(bg.pixels[x+y*width]));
newLayer.point(x, y);
}
}
}
newLayer.endDraw();
newLayer.loadPixels();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (alpha(bg.pixels[x+y*width]) == 0) {
bg.pixels[x+y*width] = newLayer.pixels[x+y*width];
}
}
}
bg.updatePixels();
image(bg, 0, 0);
}
}
void mousePressed() {
mx = mouseX;
my = mouseY;
}
void keyPressed() {
if (key == ' ') {
pause = !pause;
} else if (key == 'm') {
monochrome = !monochrome;
} else if (key == 'r') {
bg.clear();
newLayer.clear();
background(128);
} else if (key == 'n') {
bg.clear();
newLayer.clear();
} else if (key == 's') {
save(nf(random(10000))+".png");
}
}