-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodern-art.js
254 lines (237 loc) · 6.63 KB
/
modern-art.js
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import {
Command,
GUI,
Integer,
Float,
Key,
Control,
} from "../libraries/gui/gui.js";
import { getLargeCanvas } from "../libraries/misc.js";
import { textile } from "../libraries/textile.js";
const sketch = (s) => {
let gui;
let dly;
let debug = false;
let largeCanvas;
let hd = 1;
const PI = s.PI;
s.setup = () => {
let { w, h } = getLargeCanvas(s, 1600);
let canvas = s.createCanvas(w, h);
s.pixelDensity(1);
canvas.mousePressed(() => {});
s.frameRate(20);
gui = createGUI();
gui.toggle();
s.noLoop();
};
function setLineDash(scene, list) {
scene.drawingContext.setLineDash(list);
}
function patch(scene, x, y, r, dly) {
scene.push();
const size = (r + r * scene.random()) << 0;
let drawingMask = s.createGraphics(size, size);
let cloth = s.createGraphics(size, size);
cloth.background("red"); // This does nothing in the end except remove transparency
drawingMask.fill("white");
let thing = (scene) => {
scene.circle(0, 0, (size / 2) << 0);
};
drawingMask.push();
drawingMask.translate((size / 2) << 0, (size / 2) << 0);
thing(drawingMask);
drawingMask.pop();
textile(cloth, 0, 0, size, size, 1, 8);
let c = cloth.get();
c.mask(drawingMask);
scene.stroke(s.color(0, 0, 0, 100));
let ctx = scene.drawingContext;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
ctx.shadowBlur = 8;
ctx.shadowColor = "#10101099";
scene.push();
scene.translate(x, y);
scene.image(c, 0, 0);
scene.translate((size / 2) << 0, (size / 2) << 0);
scene.scale(0.99);
setLineDash(scene, [3, 5, 3, 5]);
scene.strokeWeight(1.5);
scene.noFill();
thing(scene);
scene.noStroke();
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
ctx.shadowBlur = 5;
ctx.shadowColor = "black";
scene.circle((x + size / 2) << 0, (y + size / 2) << 0, (size / 2) << 0);
scene.pop();
}
s.draw = () => {
const numPixels = hd * s.width * hd * s.height;
let scene = s.createGraphics(hd * s.width, hd * s.height);
let canvas = s.createGraphics(scene.width, scene.height);
let dly;
if (debug) {
dly = s.createGraphics(scene.width, scene.height);
}
scene.background(200);
scene.strokeWeight(30) & scene.stroke("black");
scene.fill("white");
let ctx = scene.drawingContext;
ctx.shadowOffsetX = 10;
ctx.shadowOffsetY = 10;
ctx.shadowBlur = 1;
ctx.shadowColor = "#00000099";
scene.rect(
0.1 * scene.width - 50,
0.2 * scene.height - 50,
0.6 * scene.width + 100,
0.6 * scene.height + 100,
);
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
ctx.shadowBlur = 0;
ctx.shadowColor = "white";
scene.rect(
0.1 * scene.width - 50,
0.2 * scene.height - 50,
0.6 * scene.width + 100,
0.6 * scene.height + 100,
);
textile(
canvas,
0.1 * scene.width,
0.2 * scene.height,
0.6 * scene.width,
0.6 * scene.height,
1,
8,
dly,
);
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
ctx.shadowBlur = 2;
ctx.shadowColor = "#00000099";
let c = canvas.get();
scene.image(c, 0, 0);
if (debug) {
let c = dly.get();
scene.image(c, 0, 0);
}
const w = scene.width;
const h = scene.height;
let x = 0.1 * w + scene.random(0.1 * w);
let y = 0.2 * h + scene.random(0.1 * h);
let r = 0.1 * h + scene.random(0.1 * h);
patch(scene, x << 0, y << 0, r << 0, dly);
x = 0.3 * w + scene.random(0.1 * w);
y = 0.3 * h + scene.random(0.1 * h);
r = 0.2 * h + scene.random(0.1 * h);
patch(scene, x << 0, y << 0, r << 0, dly);
// Tag
ctx.shadowOffsetX = 1;
ctx.shadowOffsetY = 1;
ctx.shadowBlur = 1;
ctx.shadowColor = "#00000033";
scene.textFont("Helvetica");
scene.noStroke();
const l = 0.77;
const t = 0.75;
scene.rect(l * w, t * h, 0.2 * h, 0.1 * h);
ctx = scene.drawingContext;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
ctx.shadowBlur = 0;
scene.noStroke();
scene.fill("black");
scene.textSize(0.015 * h);
scene.text(
"Ruben Berenguel",
(l + 0.008) * w,
(t + 0.01) * h,
0.2 * h,
0.1 * h,
);
scene.textSize(0.012 * h);
scene.textStyle(s.BOLD);
scene.text("Modern art", (l + 0.008) * w, (t + 0.03) * h, 0.2 * h, 0.1 * h);
scene.textStyle(s.NORMAL);
scene.text("2023", (l + 0.062) * w, (t + 0.03) * h, 0.2 * h, 0.1 * h);
scene.text(
"Algorithm on HTMLCanvas",
(l + 0.008) * w,
(t + 0.05) * h,
0.2 * h,
0.1 * h,
);
scene.textStyle(s.ITALIC);
scene.text(
"Simulated cloth and stitch effects",
(l + 0.008) * w,
(t + 0.07) * h,
0.2 * h,
0.1 * h,
);
largeCanvas = scene;
c = scene.get();
c.resize(s.width, 0);
s.image(c, 0, 0);
};
function createGUI() {
let info =
"Tried to improve on my generative embroidery project, and ended up with a very convincing cloth texture. Enriched it with <a href='https://github.com/rvanwijnen/spectral.js'>spectral.js</a> color mixing and using <a href='http://www.complexification.net/gallery/machines/substrate/'>Jared Tarbell's Substrate</a> colours";
let subinfo =
"When I got a stitched patch on I thought it looked like what I'd find in a modern museum, so went all in on the idea. <em>This is designed for landscape only</em>";
let S = new Key("s", () => {
largeCanvas.save("img.png");
});
let saveCmd = new Command(S, "save the canvas");
let R = new Key("r", () => {
gui.spin(() => {
s.clear();
s.draw();
gui.spin();
});
});
let resetCanvas = new Command(R, "reset");
let incR = new Key(")", () => {});
let decR = new Key("(", () => {});
let rInt = new Integer(() => {});
let rControl = new Control([decR, incR], "+/- something", rInt);
let decH = new Key("(", () => {
if (hd > 0) {
hd -= 0.1;
}
});
let incH = new Key(")", () => {
if (hd < 10) {
hd += 0.1;
}
});
let hdInfo = new Float(() => hd);
let hdControl = new Control(
[decH, incH],
"+/- resolution export factor",
hdInfo,
);
let gui = new GUI(
"Modern art, RB 2023/04 \u{1F1E8}\u{1F1ED}",
info,
subinfo,
[saveCmd, resetCanvas],
[rControl, hdControl],
);
let QM = new Key("?", () => gui.toggle());
let hide = new Command(QM, "hide this");
gui.addCmd(hide);
gui.update();
return gui;
}
s.keyReleased = () => {
gui.dispatch(s.key);
};
};
p5.disableFriendlyErrors = true;
let p5sketch = new p5(sketch);