-
Notifications
You must be signed in to change notification settings - Fork 3
/
creation.js
170 lines (151 loc) · 4.49 KB
/
creation.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
import {
createBaseGUI,
Command,
GUI,
Integer,
Float,
Key,
Control,
Seeder,
} from "../libraries/gui/gui.js";
import { getLargeCanvas, signature, smoothStep } from "../libraries/misc.js";
import { solarizedDark } from "../libraries/palettes.js";
const sketch = (s) => {
let gui, R;
let debug = true;
let dly; // Base debug layer, if used
// Globals needed in controls, commands or deep arguments
let cfg = {
hd: 1,
seeder: undefined,
largeCanvas: undefined,
};
let W, H; // Helpful globals to avoid typing scene.width so much
const PI = s.PI;
s.preload = () => {
cfg.font = s.loadFont("../libraries/fonts/Monoid-Retina.ttf");
};
s.setup = () => {
let { w, h } = getLargeCanvas(s, 1600);
let canvas = s.createCanvas(w, h);
s.pixelDensity(1);
canvas.mousePressed(() => {});
s.frameRate(20);
s.noLoop();
cfg.seeder = new Seeder();
gui = createGUI();
gui.toggle();
R.action();
};
function plot() {
let scene = s.createGraphics(
(cfg.hd * s.width) << 0,
(cfg.hd * s.height) << 0,
);
(W = scene.width), (H = scene.height);
let dly = s.createGraphics(W, H);
scene.randomSeed(cfg.seeder.get());
scene.noiseSeed(cfg.seeder.get());
dly.randomSeed(cfg.seeder.get());
dly.noiseSeed(cfg.seeder.get());
// Here your code against scene and possibly dly
if (debug && dly) {
let c = dly.get();
scene.image(dly, 0, 0);
}
const Ra = H / 4;
const cx = W / 2;
const cy = H / 2;
scene.background(solarizedDark.base01);
scene.colorMode(s.HSB);
scene.noStroke();
//scene.strokeWeight(cfg.hd)
scene.noFill();
const steps = 15000 * Math.sqrt(Math.sqrt(cfg.hd));
const shift = 360 * scene.random();
for (let i = 0; i < steps; i++) {
const th1 = (i / steps) * 2 * PI;
const _h = shift + (90 * i) / steps;
const h = _h > 360 ? _h - 360 : _h;
const s = scene.random(50, 100);
const b = scene.random(50, 100);
const alpha = 0.05 + 0.3 * scene.noise(th1);
let color = scene.color(h, s, b, alpha);
scene.fill(color);
const th2 = scene.random(0, 2 * PI);
const th3 = scene.random(0, 2 * PI);
const th4 = th1 + PI; //scene.random(0, 2*PI)
const f1 = scene.random(0.4, 1.6);
const f = scene.random(0.2, 1.8);
const f2 = scene.random(0.4, 1.6);
const rs = [f1 * Ra, f * Ra, f * Ra, f2 * Ra];
const ths = [th1, th2, th3, th4];
let curvex = [];
let curvey = [];
for (let j = 0; j < rs.length; j++) {
const th = ths[j];
const r = rs[j];
const x = cx + r * Math.cos(th);
const y = cy + r * Math.sin(th);
curvex.push(x);
curvey.push(y);
}
const dots = 100 * Math.sqrt(Math.sqrt(cfg.hd));
const size = (5 * cfg.hd * scene.noise(i)) << 0;
for (let k = 0; k < dots; k++) {
const dt = k / dots;
const ns = ((1 - smoothStep(0, dots, k)) * size) << 0;
color.setAlpha(0.05 + (1 - smoothStep(0, dots, k)) * alpha);
scene.fill(color);
const x = scene.curvePoint(...curvex, dt);
const y = scene.curvePoint(...curvey, dt);
scene.circle(x, y, 1 + ns);
}
}
const identifier = `${cfg.seeder.hex()}@${cfg.hd.toPrecision(2)}`;
const sigCfg = {
s: s,
scene: scene,
color: "#101020",
shadow: "darkgrey",
fontsize: 9,
right: scene.width,
bottom: scene.height,
identifier: identifier,
sig: "rb'23",
hd: cfg.hd,
font: cfg.font,
};
signature(sigCfg);
cfg.largeCanvas = scene;
let c = scene.get();
c.resize(s.width, 0);
s.image(c, 0, 0);
}
const createGUI = (gui) => {
cfg.title = "Creation, RB 2023/05 \u{1F1E8}\u{1F1ED}";
cfg.info = "A quick 'what if'";
cfg.subinfo =
"Just many dots over curves trapped in random circles. It is very slightly not resolution independent, but it almost is.<br/>Very high resolutions can fail depending on the browser";
cfg.s = s;
R = new Key("r", () => {
gui.spin(() => {
cfg.s.clear();
gui.spin();
plot();
gui.unmark();
gui.update();
});
});
let resetCanvas = new Command(R, "reset");
cfg.commands = [resetCanvas, cfg.seeder.command];
cfg.controls = [cfg.seeder.control];
gui = createBaseGUI(cfg);
return gui;
};
s.keyReleased = () => {
gui.dispatch(s.key);
};
};
p5.disableFriendlyErrors = true;
let p5sketch = new p5(sketch);