Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build

on:
push:
branches: [main, Dev]
branches: [main, dev]
pull_request:
workflow_dispatch:

Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Exported plots
GenerativeLineArt/exports/*.svg
# Exported plots (SVG, G-code, HPGL, batch folders)
GenerativeLineArt/exports/*
!GenerativeLineArt/exports/.gitkeep

# Downloads (web addresses, streets, terrain, weather) cached by the sketch
GenerativeLineArt/cache/
Expand Down
2 changes: 1 addition & 1 deletion GenerativeLineArt/Cli.pde
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ JSONArray paramsJSON(ArrayList<Param> ps) {
// its layer settings, then the page settings. Choices take the option name
// (or its number), toggles on/off/true/false/1/0.
void cliSet(String spec) {
int eq = spec.indexOf('=');
int eq = spec.lastIndexOf('='); // names may contain '=' ("Spacing (0=off)"), values don't
if (eq <= 0) cliError("--set needs <name>=<value>, e.g. --set \"Lines=80\"");
String name = spec.substring(0, eq).trim(), v = spec.substring(eq + 1).trim();
Layer L = layers[curLayer];
Expand Down
29 changes: 22 additions & 7 deletions GenerativeLineArt/GenerativeLineArt.pde
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,21 @@ void setup() {

void draw() {
background(C_CANVAS);
if (pendingExport != null) { File f = pendingExport; pendingExport = null; writeExport(f); }
if (pendingPresetSave != null) { File f = pendingPresetSave; pendingPresetSave = null; savePreset(f); }
if (pendingPresetLoad != null) { File f = pendingPresetLoad; pendingPresetLoad = null; loadPreset(f); }
if (pendingPhoto != null) { File f = pendingPhoto; pendingPhoto = null; loadPhoto(f); }
if (pendingMask != null) { File f = pendingMask; pendingMask = null; loadMaskImage(f); }
if (pendingShare != null) { File f = pendingShare; pendingShare = null; writeShareImage(f); }
runMainQueue();
pollWatchFolder();

updatePage();
if (pendingBatch) { pendingBatch = false; batchExport(); }
if (exploreOn && layers[exploreLayer].dirty) newExploreBatch(); // the layer changed: start over
regenerate();
// exports run after the page and the layers are up to date, so a change made
// just before pressing S (or a preset loaded in the same frame) is included
if (pendingExport != null) { File f = pendingExport; pendingExport = null; writeExport(f); }
if (pendingShare != null) { File f = pendingShare; pendingShare = null; writeShareImage(f); }
if (pendingAutoExport != null) { File f = pendingAutoExport; pendingAutoExport = null; writeExport(f); }
if (cliStep()) return;
buildPanel();
Expand Down Expand Up @@ -402,7 +404,7 @@ ArrayList<Param> makeParams(Layer L, int mode) {
l.add(P(L, "b", -3, 3, 1.6, false));
l.add(P(L, "c", -3, 3, 1.0, false));
l.add(P(L, "d", -3, 3, 0.7, false));
l.add(P(L, "Iterations", 200, 100000, 2500, true));
l.add(P(L, "Iterations", 200, 100000, 6000, true));
l.add(P(L, "Strands", 1, 40, 1, true));
break;
case 9: // Superformula
Expand Down Expand Up @@ -748,6 +750,12 @@ void keyPressed() {
if (focusText != null) { typeText(focusText); return; }
if (exploreKey()) return;
if (simKey()) return;
if (key == ESC) { // Esc closes the dropdown or the zoom, never the app
key = 0;
if (ddOpen) ddOpen = false;
else if (viewZoom > 1) resetView();
return;
}
Layer L = layers[curLayer];
boolean ctrl = keyEvent != null && (keyEvent.isControlDown() || keyEvent.isMetaDown());
if (ctrl) {
Expand Down Expand Up @@ -2359,18 +2367,25 @@ void genAttractor(ArrayList<ArrayList<PVector>> out) {
float sc = min(w / sw, h / sh) * 0.98;
float cx = (xmin + xmax) / 2 - (x0 + x1) / 2 * sc, cy = (ymin + ymax) / 2 - (y0 + y1) / 2 * sc;

int per = max(2, iters / strands);
// Successive iterates of these maps jump all over the attractor, so joining
// them with lines only gives a tangle. Each iterate is drawn as a tiny dash
// (a pen dot) instead; the dots build up the attractor's shape. 'Strands' =
// number of orbits started from different random points.
int per = max(1, iters / strands);
float dl = 0.35; // dash length (mm): a dot at plotter pen widths
for (int sIdx = 0; sIdx < strands; sIdx++) {
x = random(-1, 1); y = random(-1, 1);
ArrayList<PVector> pts = new ArrayList<PVector>(per);
for (int i = 0; i < per + 50; i++) {
float nx, ny;
if (type == 0) { nx = sin(a * y) + c * cos(a * x); ny = sin(b * x) + d * cos(b * y); }
else { nx = sin(a * y) - cos(b * x); ny = sin(c * x) - cos(d * y); }
x = nx; y = ny;
if (i >= 50) pts.add(new PVector(cx + x * sc, cy + y * sc));
if (i < 50) continue; // let the orbit settle onto the attractor
float px = cx + x * sc, py = cy + y * sc;
ArrayList<PVector> dot = new ArrayList<PVector>(2);
dot.add(new PVector(px - dl / 2, py)); dot.add(new PVector(px + dl / 2, py));
emit(out, dot);
}
emit(out, pts);
}
}

Expand Down
11 changes: 11 additions & 0 deletions GenerativeLineArt/NumberEntry.pde
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
Param numParam = null;
TextVal tvNum = new TextVal("", 24);
float sliderPressVal = 0; // value before the press (a double-click restores it)
boolean numFresh = false; // the field still shows the old value: typing replaces it

void startNumEdit(Param p) {
numParam = p;
tvNum.s = fmtParam(p);
numFresh = true;
focusText = tvNum;
}

Expand Down Expand Up @@ -55,9 +57,17 @@ boolean numKey() {
if (keyEvent != null && keyEvent.isShiftDown()) step *= 10;
p.set(p.val + (keyCode == UP ? step : -step));
tvNum.s = fmtParam(p);
numFresh = true;
return true;
}
if (key >= 32 && key != DELETE && "0123456789.,-+*/x eE".indexOf(key) < 0) return true; // ignore letters
// the first key replaces the old value (so "1500", "*2" or "+10" work as typed)
boolean paste = keyEvent != null && (keyEvent.isControlDown() || keyEvent.isMetaDown()) && keyCode == 'V';
if (numFresh && (paste || key == BACKSPACE || (key >= 32 && key != DELETE && key != CODED))) {
tvNum.s = "";
numFresh = false;
return key == BACKSPACE;
}
return false;
}

Expand All @@ -78,6 +88,7 @@ void drawNumField(SliderW w) {
float fw = max(56, textWidth(t) + 16);
stroke(C_ACCENT); strokeWeight(1); fill(C_FIELD);
rect(w.x + w.w - fw, w.y - 3, fw, 19, 3);
if (numFresh) { noStroke(); fill(C_ACCENT, 90); rect(w.x + w.w - 7 - textWidth(t) - 2, w.y - 1, textWidth(t) + 4, 15, 2); } // selected
noStroke(); fill(C_TEXT); textAlign(RIGHT, TOP);
text(t, w.x + w.w - 7, w.y);
if ((millis() / 500) % 2 == 0) { stroke(C_ACCENT); line(w.x + w.w - 5, w.y - 1, w.x + w.w - 5, w.y + 14); }
Expand Down
13 changes: 9 additions & 4 deletions GenerativeLineArt/ShareImage.pde
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ PGraphics shareImage(int longSide) {
float ts = longSide * 0.026, ty = pad + ph + foot * 0.42;
g.textFont(uiFont);
g.textAlign(LEFT, CENTER);
g.fill(0xFF2A2A2A); g.textSize(ts);
g.text(pats.isEmpty() ? "Empty design" : join(pats.toArray(new String[0]), " + "), pad, ty);
g.fill(0xFF77736C); g.textSize(ts * 0.62);
// the caption shrinks to stay clear of the pen swatches on the right
float r = ts * 0.55, room = pw - pens * r * 2.8 - r;
String title = pats.isEmpty() ? "Empty design" : join(pats.toArray(new String[0]), " + ");
String info = PAPER_NAMES[pPaper.i()] + (pLandscape.on() ? " landscape" : "") + " · " + round(genW) + " × " + round(genH) + " mm · "
+ pens + (pens == 1 ? " pen" : " pens") + " · " + String.format(Locale.US, "%.1f m of line", len / 1000) + " · plot time " + fmtTime(secs).replace("~", "about ");
g.fill(0xFF2A2A2A); g.textSize(ts);
if (g.textWidth(title) > room) g.textSize(max(ts * 0.4, ts * room / g.textWidth(title)));
g.text(title, pad, ty);
g.fill(0xFF77736C); g.textSize(ts * 0.62);
if (g.textWidth(info) > room) g.textSize(max(ts * 0.3, ts * 0.62 * room / g.textWidth(info)));
g.text(info, pad, ty + ts * 1.15);
// pen swatches, right-aligned
float r = ts * 0.55, x = pad + pw - r;
float x = pad + pw - r;
for (int i = NUM_LAYERS - 1; i >= 0; i--) {
Layer L = layers[i];
if (!L.pEnabled.on()) continue;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Generative line art with a live-adjustable GUI, built as a single [Processing](h
## Features

- **35 patterns** — flow field, wave lines, spirograph, noise rings, Lissajous, contour map, Truchet tiles, hatch shading, strange attractor, superformula, nested polygons, spiral, moire circles, circle packing, harmonograph, Hilbert curve, sunburst, maze, L-system, guilloche, Maurer rose, phyllotaxis, subdivision, warped grid, fractal tree, Voronoi, image, hex Truchet, Penrose, hex maze, route, data lines, SVG import, audio, text.
- **Strange attractor** — Clifford and De Jong attractors, each point of the orbit drawn as a pen dot (stipple), so the attractor's shape builds up from thousands of dots.
- **Maze** — recursive-backtracker maze drawn as walls or as its centre-line path (same seed on two layers = walls + solution-style path in a second pen). Wall segments are merged into long strokes to minimise pen lifts.
- **L-system** — Koch snowflake, dragon curve, Gosper curve, Sierpinski arrowhead and a branching plant, with angle tweak, jitter and smoothing.
- **Guilloche** — banknote-style rosettes: interleaved lines oscillating between two lobed envelopes.
Expand Down
Loading