azulejeria 2.5.1 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +211 -23
- package/package.json +7 -4
- package/src/azulejeria.css +43 -0
- package/src/azulejeria.js +103 -16
- package/src/draw.js +448 -0
- package/src/loom.js +175 -0
- package/src/shadow.js +83 -0
- package/test/draw.mjs +53 -0
- package/test/loom.mjs +52 -0
package/README.md
CHANGED
|
@@ -10,21 +10,59 @@ a polyline with a slow wobble along its normal, the way a loaded brush
|
|
|
10
10
|
drifts. Washes are laid thin twice so the glaze pools. Each tile gets its
|
|
11
11
|
own mottled glaze, a slight turn, a slight shift, and a few of them craze.
|
|
12
12
|
|
|
13
|
-
This package is the engine.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
This package is the engine. It started as that one wall and is now a
|
|
14
|
+
small kit for pattern made by rule and painted to look like a material.
|
|
15
|
+
You bring the motifs, the palettes and the presets, and, if the tile is
|
|
16
|
+
not glazed, a material.
|
|
17
|
+
|
|
18
|
+
## What is in it
|
|
19
|
+
|
|
20
|
+
| Import | What it is | Section |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `azulejeria` | The tile wall, the viewer it is built on, the panel and page chrome, the brush and its geometry, corner tiles for borders, one tile at print size | A wall in forty lines, The parts, Print |
|
|
23
|
+
| `azulejeria/pieces` | The cutter: a polygon inset, shifted, turned and bevelled, and a Voronoi for things that are broken | Pieces |
|
|
24
|
+
| `azulejeria/groups` | The seventeen wallpaper groups as a way to lay any tile | Groups |
|
|
25
|
+
| `azulejeria/knots` | Interlace on a grid: over and under by parity, breaks, cuts and beasts | Knots |
|
|
26
|
+
| `azulejeria/draw` | A tile drawn by hand, one eighth of it, carried in a string | Draw |
|
|
27
|
+
| `azulejeria/shadow` | A sun that goes round and the shadows it casts | Shadow |
|
|
28
|
+
| `azulejeria/loom` | Weaving drafts, setts and the cloth they make | Loom |
|
|
29
|
+
| `azulejeria/azulejeria.css` | The styles for the panel, the cards, the title and the pad | The parts |
|
|
30
|
+
|
|
31
|
+
Each module stands alone except `draw`, which paints with the wall's
|
|
32
|
+
brush. `knots`, `groups`, `pieces`, `shadow` and `loom` draw on any 2D
|
|
33
|
+
context.
|
|
34
|
+
|
|
35
|
+
## Built on it
|
|
36
|
+
|
|
37
|
+
Tile walls (`createWall`):
|
|
38
|
+
[Azulejería](https://stepinto.dev/art/azulejeria.html) (Talavera rosettes and Mudéjar strapwork),
|
|
39
|
+
[Jerez](https://stepinto.dev/art/jerez.html) (vines, horses and sherry),
|
|
40
|
+
[Hidráulico](https://stepinto.dev/art/hidraulico.html) (pigmented cement, pressed and not painted),
|
|
41
|
+
[Delft](https://stepinto.dev/art/delft.html) (a figure in the middle of every tile),
|
|
42
|
+
[Fajalauza](https://stepinto.dev/art/fajalauza.html) (Granada's green and blue on cream),
|
|
43
|
+
[Rosa y Granada](https://stepinto.dev/art/rosaygranada.html) and
|
|
44
|
+
[Encaustic](https://stepinto.dev/art/encaustic.html) (clay inlaid in clay, medieval and Victorian),
|
|
45
|
+
[Papel Pintado](https://stepinto.dev/art/papelpintado.html) (block-printed paper laid by any of the seventeen groups) and
|
|
46
|
+
[Octavo](https://stepinto.dev/art/octavo.html) (you draw one eighth of the tile and the wall paints the rest).
|
|
47
|
+
|
|
48
|
+
Other worlds on the viewer (`createViewer`):
|
|
49
|
+
[Alicatado](https://stepinto.dev/art/alicatado.html) (cut tile set in lime, with the cutter),
|
|
50
|
+
[Trencadís](https://stepinto.dev/art/trencadis.html) (Azulejería's tiles broken and relaid),
|
|
51
|
+
[Sutton Hoo](https://stepinto.dev/art/suttonhoo.html) (garnet cells through the cutter, a buckle in knots),
|
|
52
|
+
[Knotwork](https://stepinto.dev/art/knotwork.html) (insular interlace on vellum),
|
|
53
|
+
[Sebka](https://stepinto.dev/art/sebka.html) (a brick lattice under a sun you can move),
|
|
54
|
+
[Rejería](https://stepinto.dev/art/rejeria.html) (wrought iron and its shadow on whitewash),
|
|
55
|
+
[Jali](https://stepinto.dev/art/jali.html) (a pierced stone screen and the light it lets onto the floor),
|
|
56
|
+
[Tartan](https://stepinto.dev/art/tartan.html) (type a sett, get the cloth),
|
|
57
|
+
[Hitomezashi](https://stepinto.dev/art/hitomezashi.html) (two words stitched as rows and columns),
|
|
58
|
+
[Azulejos de letras](https://stepinto.dev/art/letras.html) (a street-sign typeface, with borders that turn the corner),
|
|
59
|
+
[Mantón de Manila](https://stepinto.dev/art/manton.html) (embroidered silk),
|
|
60
|
+
[Hispania](https://stepinto.dev/art/hispania.html) (Roman pavements) and
|
|
61
|
+
[Leonor](https://stepinto.dev/art/leonor.html) (heraldry from a blazon).
|
|
62
|
+
|
|
63
|
+
The designs are written up in the
|
|
64
|
+
[Patterns by Rule](https://stepinto.dev/patterns/) posts, starting
|
|
65
|
+
[here](https://stepinto.dev/posts/tiles-painted-by-rule/) and
|
|
28
66
|
[here](https://stepinto.dev/posts/cut-tile-and-poured-cement/).
|
|
29
67
|
|
|
30
68
|
```
|
|
@@ -96,7 +134,8 @@ tile), `panX`, `panY`, `bands`, `grout` and `age`. After changing any of
|
|
|
96
134
|
them call `wall.rebuild(true)` to repaint the tiles, or `wall.rebuild(false)`
|
|
97
135
|
for things the wall draws itself (pan, grout, age). `wall.applyPreset(name)`,
|
|
98
136
|
`wall.newDesign()` and `wall.zoomAt(x, y, factor)` do what they say. Set
|
|
99
|
-
`wall.onChange(kind)` to be told about them
|
|
137
|
+
`wall.onChange(kind)` to be told about them (`'preset'`, `'design'`,
|
|
138
|
+
`'zoom'`). **`REPEATS`** lists the five classic repeats by name.
|
|
100
139
|
|
|
101
140
|
**A material** changes what the tile is made of without touching what is
|
|
102
141
|
drawn on it. It is an object of optional hooks, and without one the tile
|
|
@@ -116,19 +155,22 @@ centre `cx`, `cy`, so wear can follow the line people walk. `finish(ctx,
|
|
|
116
155
|
W, H, state, pal)` is drawn over the whole wall last. None of the hooks
|
|
117
156
|
read the design's rng, so a material never moves a design.
|
|
118
157
|
|
|
119
|
-
**`mountPanel(wall, { fileName, defaultPreset })`** wires the standard
|
|
158
|
+
**`mountPanel(wall, { fileName, defaultPreset, print, document })`** wires the standard
|
|
120
159
|
panel for a wall. It is `mountChrome` (below) with the wall's controls,
|
|
121
160
|
which are a handful of elements found by id: selects `repeat`,
|
|
122
161
|
`motif` and `palette`; ranges `density`, `hand`, `brush` and `zoom` with
|
|
123
162
|
`densityVal`, `handVal`, `brushVal` and `zoomVal` spans beside them;
|
|
124
|
-
checkboxes `bands`, `grout` and `age`; buttons `newDesign` and
|
|
163
|
+
checkboxes `bands`, `grout` and `age`; buttons `newDesign`, `save` and
|
|
164
|
+
`order` (one tile at print size, see Print; `print` is passed to it);
|
|
125
165
|
a `mood` line for the seed; `.card[data-preset]` cards each holding a
|
|
126
166
|
canvas for a thumbnail; `.tab[data-tab]` buttons switching `presetsBody`
|
|
127
167
|
and `panelBody`; `panel` with `panelHead` and `panelToggle`; and a `title`
|
|
128
168
|
overlay that fades on first touch. Anything missing is skipped. It also
|
|
129
169
|
reads the query string, so `?preset=talavera` or
|
|
130
170
|
`?seed=4242&repeat=rotate&pal=talavera&motif=rosette&density=5&age=1` is a
|
|
131
|
-
shareable wall.
|
|
171
|
+
shareable wall. `document` is where to look for the elements, for a
|
|
172
|
+
panel that lives somewhere other than the page. Copy the markup from
|
|
173
|
+
any of the wall pages above.
|
|
132
174
|
|
|
133
175
|
**`createViewer(canvas, { paint, scale, minZoom, maxZoom, margin })`**
|
|
134
176
|
is what a wall is built on, and what any other world can be. `paint(g,
|
|
@@ -139,7 +181,12 @@ the window, pans on drag, zooms on pinch or wheel, and calls
|
|
|
139
181
|
that much larger than the window and only blits while you drag, which is
|
|
140
182
|
what a slow paint wants. `viewer.state` has `scale`, `panX` and `panY`;
|
|
141
183
|
add your own fields to it. Call `viewer.repaint()` when the world
|
|
142
|
-
changes and `viewer.moved()` when only the pan did.
|
|
184
|
+
changes and `viewer.moved()` when only the pan did. `viewer.zoomAt(x,
|
|
185
|
+
y, factor)` zooms about a point and `viewer.resize()` refits the
|
|
186
|
+
window. Set `onChange(kind)` to hear `'zoom'`, `onInteract()` for the
|
|
187
|
+
first touch and `onZoom()` for the end of a zoom. `viewer.margin` can
|
|
188
|
+
be changed while it runs: a page that animates sets it to 0 so each
|
|
189
|
+
frame paints the window alone.
|
|
143
190
|
|
|
144
191
|
**`mountChrome(viewer, spec)`** wires the same chrome around any viewer:
|
|
145
192
|
the panel, the tabs, the preset cards, the title that fades, the save
|
|
@@ -152,8 +199,13 @@ id by default), `q` its name in the query string (the key by default),
|
|
|
152
199
|
when the query string sets it, and `change(value)` is what to do after.
|
|
153
200
|
Then `newId` and `onNew` for the button that starts over, `mood(state)`
|
|
154
201
|
for the line under it, `query(q)` for anything else in the query string,
|
|
155
|
-
`fileName` and `suffix(state)` for the saved png,
|
|
156
|
-
|
|
202
|
+
`fileName` and `suffix(state)` for the saved png, `order(state)` (a
|
|
203
|
+
promise of a blob) for an `#order` button, `document` for where the
|
|
204
|
+
elements are, and `ready()` once everything is applied. It returns
|
|
205
|
+
`{ sync, dismissTitle, markPreset }`: call `sync()` after changing the
|
|
206
|
+
state yourself, and `markPreset('')` when something the chrome doesn't
|
|
207
|
+
know about (a text box, say) has left the preset behind. Alicatado is
|
|
208
|
+
the worked example; Tartan and Hitomezashi show a text input beside it.
|
|
157
209
|
|
|
158
210
|
**`azulejeria.css`** styles that markup. Colour it with the custom
|
|
159
211
|
properties at the top of the file: `--az-bg`, `--az-title`,
|
|
@@ -196,8 +248,17 @@ uses it for the frame of a street plaque. `mitreCorner(strip)` is the
|
|
|
196
248
|
square alternative: the strip cut on the diagonal and laid both ways,
|
|
197
249
|
as a run of border tiles is mitred at forty-five degrees.
|
|
198
250
|
|
|
251
|
+
**The small things** every page ends up wanting: `mulberry32(seed)`,
|
|
252
|
+
the seeded rng everything here draws from; `hash2(i, j)`, an integer
|
|
253
|
+
from a grid position, for seeding a tile or a stitch by where it is;
|
|
254
|
+
`wobble(rng)`, the brush's slow drift as a function of 0 to 1;
|
|
255
|
+
`hexA(hex, alpha)`, a hex colour as an rgba string; `colourOf(el, pal)`,
|
|
256
|
+
an element's role as a colour; and `ageTile(ctx, rng, s, pal)`, what
|
|
257
|
+
age does to one glazed tile, for a material that wants the default
|
|
258
|
+
under its own.
|
|
259
|
+
|
|
199
260
|
**The lower level** is there if you want it: `makeDesign(seed, density,
|
|
200
|
-
bands, bold, motif)`, `paintDesign(g, els, pal, hand, lw, seed, painters, material, brush)`,
|
|
261
|
+
bands, bold, motif, state)`, `paintDesign(g, els, pal, hand, lw, seed, painters, material, brush)`,
|
|
201
262
|
`makeTile(opts, size, pixelRatio, seed)`, `tileOpts(cfg, state)` and
|
|
202
263
|
`paintThumb(cfg, preset, g, size, pixelRatio)`.
|
|
203
264
|
|
|
@@ -329,6 +390,133 @@ A beast's head is traced from a drawing of an Insular hound's head
|
|
|
329
390
|
hooks round under it and into its jaws. `eye` colours its eye.
|
|
330
391
|
`strandPath` and `ribbon` are exported for drawing a strand yourself.
|
|
331
392
|
|
|
393
|
+
## Draw
|
|
394
|
+
|
|
395
|
+
```js
|
|
396
|
+
import { drawnMotif, DRAW_PAINTERS, mountPad, encodeDrawing, decodeDrawing } from 'azulejeria/draw';
|
|
397
|
+
|
|
398
|
+
const wall = createWall(canvas, {
|
|
399
|
+
palettes, presets,
|
|
400
|
+
motifs: { drawn: drawnMotif() },
|
|
401
|
+
painters: { ...PAINTERS, ...DRAW_PAINTERS },
|
|
402
|
+
});
|
|
403
|
+
mountPanel(wall, { fileName: 'mine' });
|
|
404
|
+
mountPad(wall, { onEdit: d => history.replaceState(null, '', '?d=' + d) });
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
A tile painted by hand, one eighth of it. Every design is symmetric
|
|
408
|
+
across the diagonal of its square, so a hand only has to draw the
|
|
409
|
+
triangle under that diagonal, from the main corner to the far one. The
|
|
410
|
+
wall is an ordinary wall: the drawing is its motif, so the repeats, the
|
|
411
|
+
groups, the palettes, the brush and any material apply to it.
|
|
412
|
+
[Octavo](https://stepinto.dev/art/octavo.html) is this and nothing else.
|
|
413
|
+
|
|
414
|
+
A drawing is a list of strokes `{ k, c, w, pts }`: the kind (`line`,
|
|
415
|
+
`shape` or `dot`), the colour (0 the wash, 1 to 3 an accent, 4 the ink),
|
|
416
|
+
the weight (1 to 8) and the points in design coordinates.
|
|
417
|
+
**`encodeDrawing(strokes)`** packs it into a short string, two bytes a
|
|
418
|
+
point, base64url; **`decodeDrawing(string)`** reads it back and gives an
|
|
419
|
+
empty drawing for anything it cannot read. The string lives in the
|
|
420
|
+
wall's state (`state.d` unless you name another key), so a preset can
|
|
421
|
+
carry a drawing and so can a query string or a stored value.
|
|
422
|
+
|
|
423
|
+
**`drawnMotif(key)`** is the motif that paints `state[key]`. A motif's
|
|
424
|
+
context now carries `state` for this. **`DRAW_PAINTERS`** has the one
|
|
425
|
+
painter it needs, `stroke`, which paints each stroke on its own side of
|
|
426
|
+
the diagonal and again reflected, with the same drift and the same
|
|
427
|
+
brush, so a petal drawn across the diagonal comes out whole. A shape is
|
|
428
|
+
washed and inked, an ink line is a line, a coloured line is a ribbon. A
|
|
429
|
+
material's `shape`, `line` and `dot` are used when it has them.
|
|
430
|
+
|
|
431
|
+
**`mountPad(wall, { key, onEdit })`** wires the pad. The page provides
|
|
432
|
+
`#pad` holding a canvas `#padCanvas`, buttons `.tool[data-tool]`
|
|
433
|
+
(`line`, `shape`, `dot`), an empty `#swatches`, a range `#weight` with
|
|
434
|
+
`#weightVal`, buttons `#undo` and `#clear`, and `#padHead` with
|
|
435
|
+
`#padToggle`; `azulejeria.css` styles them. The pad shows the square in
|
|
436
|
+
the wall's palette and material with the reflected half dimmed. A
|
|
437
|
+
stroke drawn on the dimmed side is reflected over. The wall repaints
|
|
438
|
+
while the pen moves. Cmd or Ctrl Z undoes. **`settle(stroke)`**,
|
|
439
|
+
**`simplify(pts, eps)`** and **`smooth(pts, closed, times)`** are what
|
|
440
|
+
the pad does to a raw stroke, exported for a page with its own input.
|
|
441
|
+
`KINDS` and `MAX_POINTS` (96, the most points a stroke keeps) are the
|
|
442
|
+
encoding's limits.
|
|
443
|
+
|
|
444
|
+
## Print
|
|
445
|
+
|
|
446
|
+
**`exportTile(wall, { cm, dpi, bleed })`** paints the wall's tile once
|
|
447
|
+
at print size and resolves to a PNG blob: 15 cm at 300 dpi with a 3 mm
|
|
448
|
+
bleed unless told otherwise (1842 pixels square). The bleed is the tile
|
|
449
|
+
mirrored out past each edge. The file carries its dpi (a `pHYs` chunk;
|
|
450
|
+
**`pngWithDpi(bytes, dpi)`** does that to any PNG), so it opens at the
|
|
451
|
+
right size. `mountPanel` wires it to a `#order` button when the page has
|
|
452
|
+
one (`opts.print` is passed on); with `mountChrome`, pass
|
|
453
|
+
`order: () => exportTile(wall)` in the spec.
|
|
454
|
+
|
|
455
|
+
## Shadow
|
|
456
|
+
|
|
457
|
+
`azulejeria/shadow` is a sun that goes round and the shadows it casts.
|
|
458
|
+
Nothing is drawn in shadow: a caster's shadow is its own outline, moved
|
|
459
|
+
along the sun's slant by how far it stands off the surface, with what
|
|
460
|
+
must stay lit cut back out, softened and multiplied on in the colour of
|
|
461
|
+
the sky.
|
|
462
|
+
|
|
463
|
+
```js
|
|
464
|
+
import { sunOf, castShadow, shadowLayer } from 'azulejeria/shadow';
|
|
465
|
+
|
|
466
|
+
const sun = sunOf(9.5); // 6 to 20; the wall faces south
|
|
467
|
+
castShadow(g, {
|
|
468
|
+
w, h, dpr, shade: sun.shade, alpha: 0.8, blur: 2,
|
|
469
|
+
cast: lg => { lg.setTransform(...); drawGrille(lg, sun.slant[0] * d, sun.slant[1] * d); },
|
|
470
|
+
cut: lg => drawGrille(lg, 0, 0),
|
|
471
|
+
});
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
**`sunOf(hour, { reach })`** gives `slant` (how far along the wall a
|
|
475
|
+
point one unit proud throws its shadow, x right and y down, never
|
|
476
|
+
longer than `reach`), `dir` (the unit vector toward the sun), `light`
|
|
477
|
+
(how squarely it strikes the face), `warm` (1 at the horizon, 0 at the
|
|
478
|
+
top of the day), `sunCol` and `shade` as `[r, g, b]`, and `az` and `e`
|
|
479
|
+
for a page with its own projection. **`castShadow(g, o)`** clears a
|
|
480
|
+
kept layer the size of the window, lets `o.cast(lg)` draw the caster
|
|
481
|
+
where its shadow falls (fill and stroke are already `o.shade`), draws
|
|
482
|
+
`o.cut(lg)` with destination-out if there is one, and multiplies the
|
|
483
|
+
layer onto `g` at `o.alpha`, blurred by `o.blur` device pixels.
|
|
484
|
+
`o.layer` picks which kept layer, for a page that casts more than once.
|
|
485
|
+
**`shadowLayer(n, pw, ph)`** is one of those layers, for a page's own
|
|
486
|
+
compositing.
|
|
487
|
+
|
|
488
|
+
## Loom
|
|
489
|
+
|
|
490
|
+
`azulejeria/loom` is cloth by rule. A draft is three lists: the shaft
|
|
491
|
+
each warp end is threaded through, the shafts each treadle lifts, and
|
|
492
|
+
the treadle pressed for each pick. Where an end's shaft is lifted the
|
|
493
|
+
warp is on top. A sett is a string of colours and thread counts, and
|
|
494
|
+
the cloth shows a thread's colour wherever that thread is on top.
|
|
495
|
+
|
|
496
|
+
```js
|
|
497
|
+
import { DRAFTS, parseSett, threadsOf, dyeOf, clothCanvas, threadTile } from 'azulejeria/loom';
|
|
498
|
+
|
|
499
|
+
const threads = threadsOf(parseSett('K4 R24 K24 Y4')).map(c => dyeOf(c, 'modern'));
|
|
500
|
+
const cloth = clothCanvas(400, 300, 0, 0, threads, threads, DRAFTS.twill); // one pixel a crossing
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
**`DRAFTS`** has `plain`, `twill` (2/2), `drill` (3/1), `herringbone`,
|
|
504
|
+
`diamond` and `basket`; a draft is `{ threading, tieup, treadling }`,
|
|
505
|
+
so write your own. **`lifted(draft, i, j)`** is the rule and
|
|
506
|
+
**`drawdown(draft)`** one repeat of it. **`parseSett(text)`** reads
|
|
507
|
+
colour codes (K R G B Y W N P O T A M C, with L or D in front for light
|
|
508
|
+
and dark, or `#rrggbb`) and counts, slashes at the pivots allowed; the
|
|
509
|
+
sett turns back at both ends unless it has `...` in it.
|
|
510
|
+
**`DRAFT_NAMES`** lists the drafts. **`threadsOf(sett)`** is one repeat, a code per thread, and
|
|
511
|
+
**`writeSett(sett)`** writes it back as a threadcount.
|
|
512
|
+
**`dyeOf(code, dye)`** is the colour in a dye lot (**`DYES`**: `modern`,
|
|
513
|
+
`ancient`, `weathered`, or your own map). **`weavePixels(data, w, h,
|
|
514
|
+
i0, j0, warp, weft, draft, under)`** fills RGBA pixels, one a crossing,
|
|
515
|
+
from end `i0` and pick `j0`, and needs no document;
|
|
516
|
+
**`clothCanvas(...)`** is the same as a canvas to draw scaled up, and
|
|
517
|
+
**`threadTile(draft, t)`** is the threads' own shading, one repeat at
|
|
518
|
+
`t` pixels a thread, to lay over it.
|
|
519
|
+
|
|
332
520
|
## Licence
|
|
333
521
|
|
|
334
522
|
MIT.
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "azulejeria",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
5
|
-
"keywords": ["canvas", "generative", "wallpaper-groups", "symmetry", "tiles", "azulejo", "mudejar", "sevilla", "pattern", "procedural", "art", "wallpaper", "interlace", "knotwork", "celtic", "mosaic", "voronoi", "trencadis"],
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "Pattern by rule, painted to look like a material. A seeded canvas engine that began with Spanish azulejo walls: tiles with a drifting brush, the seventeen wallpaper groups, a tile cutter, interlace, a hand-drawn tile, cast shadows and a loom.",
|
|
5
|
+
"keywords": ["canvas", "generative", "wallpaper-groups", "symmetry", "tiles", "azulejo", "mudejar", "sevilla", "pattern", "procedural", "art", "wallpaper", "interlace", "knotwork", "celtic", "mosaic", "voronoi", "trencadis", "drawing", "print", "shadow", "weaving", "tartan", "loom"],
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Andy Cross",
|
|
8
8
|
"homepage": "https://stepinto.dev/art/azulejeria.html",
|
|
@@ -15,11 +15,14 @@
|
|
|
15
15
|
"./knots": "./src/knots.js",
|
|
16
16
|
"./pieces": "./src/pieces.js",
|
|
17
17
|
"./groups": "./src/groups.js",
|
|
18
|
+
"./draw": "./src/draw.js",
|
|
19
|
+
"./shadow": "./src/shadow.js",
|
|
20
|
+
"./loom": "./src/loom.js",
|
|
18
21
|
"./azulejeria.css": "./src/azulejeria.css"
|
|
19
22
|
},
|
|
20
23
|
"files": ["src", "test", "README.md", "LICENSE"],
|
|
21
24
|
"sideEffects": false,
|
|
22
25
|
"scripts": {
|
|
23
|
-
"test": "node --check src/azulejeria.js && node --check src/knots.js && node --check src/head.js && node --check src/pieces.js && node --check src/groups.js && node test/groups.mjs"
|
|
26
|
+
"test": "node --check src/azulejeria.js && node --check src/knots.js && node --check src/head.js && node --check src/pieces.js && node --check src/groups.js && node --check src/draw.js && node --check src/shadow.js && node --check src/loom.js && node test/groups.mjs && node test/draw.mjs && node test/loom.mjs"
|
|
24
27
|
}
|
|
25
28
|
}
|
package/src/azulejeria.css
CHANGED
|
@@ -136,3 +136,46 @@ input[type="checkbox"] { accent-color: var(--az-accent); }
|
|
|
136
136
|
}
|
|
137
137
|
.btn:active { background: var(--az-card-on); }
|
|
138
138
|
#mood { font-size: 0.62rem; opacity: 0.5; margin-top: 0.45rem; letter-spacing: 0.15em; text-align: center; }
|
|
139
|
+
|
|
140
|
+
/* the drawing pad (azulejeria/draw): bottom left, the square of the
|
|
141
|
+
design with the tools under it */
|
|
142
|
+
#pad {
|
|
143
|
+
position: fixed; left: 1rem; bottom: 1rem; z-index: 20;
|
|
144
|
+
width: 246px;
|
|
145
|
+
font-family: "Courier New", monospace; font-size: 0.72rem;
|
|
146
|
+
color: rgba(242, 234, 214, 0.85);
|
|
147
|
+
background: var(--az-panel);
|
|
148
|
+
border: 1px solid rgba(242, 234, 214, 0.15);
|
|
149
|
+
border-radius: 10px;
|
|
150
|
+
backdrop-filter: blur(8px);
|
|
151
|
+
user-select: none;
|
|
152
|
+
}
|
|
153
|
+
#padHead {
|
|
154
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
155
|
+
padding: 0.55rem 0.8rem; cursor: pointer;
|
|
156
|
+
letter-spacing: 0.18em; text-transform: uppercase; font-size: 0.66rem;
|
|
157
|
+
}
|
|
158
|
+
#padBody { padding: 0 0.8rem 0.8rem; }
|
|
159
|
+
#pad.closed #padBody { display: none; }
|
|
160
|
+
#pad canvas { width: 100%; height: auto; aspect-ratio: 1; border-radius: 6px; cursor: crosshair; }
|
|
161
|
+
#pad canvas:active { cursor: crosshair; }
|
|
162
|
+
.tools { display: flex; gap: 5px; margin-top: 0.55rem; }
|
|
163
|
+
.tools button {
|
|
164
|
+
flex: 1; padding: 0.35rem 0;
|
|
165
|
+
background: var(--az-field); color: rgba(242, 234, 214, 0.7);
|
|
166
|
+
border: 1px solid rgba(242, 234, 214, 0.2); border-radius: 5px;
|
|
167
|
+
font-family: inherit; font-size: 0.62rem; cursor: pointer;
|
|
168
|
+
letter-spacing: 0.12em; text-transform: uppercase;
|
|
169
|
+
}
|
|
170
|
+
.tools button.on { color: #f2ead6; border-color: var(--az-accent-soft); background: var(--az-card-on); }
|
|
171
|
+
.tools button:active { background: var(--az-card-on); }
|
|
172
|
+
#swatches { display: flex; gap: 6px; margin-top: 0.55rem; }
|
|
173
|
+
.sw {
|
|
174
|
+
flex: 1; height: 22px; padding: 0; cursor: pointer;
|
|
175
|
+
border: 1px solid rgba(242, 234, 214, 0.25); border-radius: 5px;
|
|
176
|
+
}
|
|
177
|
+
.sw.on { outline: 2px solid var(--az-accent); outline-offset: 1px; }
|
|
178
|
+
.btn:disabled { opacity: 0.6; cursor: progress; }
|
|
179
|
+
@media (max-width: 520px) {
|
|
180
|
+
#pad { width: 178px; left: 0.6rem; bottom: 0.6rem; }
|
|
181
|
+
}
|
package/src/azulejeria.js
CHANGED
|
@@ -49,8 +49,10 @@ export function hexA(hex, a) {
|
|
|
49
49
|
// elements, each `{ t: 'painterName', ...params }`. The context carries
|
|
50
50
|
// the seeded rng and a few helpers every motif wants: `pick` one of a
|
|
51
51
|
// list, `role` (wash or one of the accents), and `dots` for the
|
|
52
|
-
// scatter that higher densities add.
|
|
53
|
-
|
|
52
|
+
// scatter that higher densities add. `state`, if given, is the wall's
|
|
53
|
+
// state, for a motif that paints something the state carries (a
|
|
54
|
+
// drawing, say) rather than what the seed grows.
|
|
55
|
+
export function makeDesign(seed, density, bands, bold, motif, state) {
|
|
54
56
|
const rng = mulberry32(seed);
|
|
55
57
|
bold = bold || 1; // single tiles carry the motif larger
|
|
56
58
|
const pick = arr => arr[Math.floor(rng() * arr.length)];
|
|
@@ -63,7 +65,7 @@ export function makeDesign(seed, density, bands, bold, motif) {
|
|
|
63
65
|
}
|
|
64
66
|
return { t: 'dots', dots: d };
|
|
65
67
|
};
|
|
66
|
-
return motif({ rng, density, bands, bold, pick, role, dots });
|
|
68
|
+
return motif({ rng, density, bands, bold, pick, role, dots, state });
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
// ---------------------------------------------------------- brushwork ---
|
|
@@ -235,7 +237,7 @@ export function paintDesign(g, els, pal, hand, lw, jseed, painters, material, br
|
|
|
235
237
|
const amp = m.ampOf ? m.ampOf(hand) : 0.012 * hand;
|
|
236
238
|
const Q = Math.PI / 2, D = Q / 2;
|
|
237
239
|
const dc = Math.cos(D), ds = Math.sin(D); // the diagonal
|
|
238
|
-
const b = { g, pal, lw, amp, rng, Q, D, dc, ds, col: pal.wash, hand, brush: brush === undefined ? 1 : brush };
|
|
240
|
+
const b = { g, pal, lw, amp, rng, Q, D, dc, ds, col: pal.wash, hand, brush: brush === undefined ? 1 : brush, material: material || null };
|
|
239
241
|
const shape = m.shape
|
|
240
242
|
? (pts, col) => m.shape(g, pts, col, b)
|
|
241
243
|
: (pts, col) => { wash(g, pts, col, rng); ink(g, pts, lw, pal, rng, true); };
|
|
@@ -334,7 +336,7 @@ const ROT = [0, Math.PI / 2, 3 * Math.PI / 2, Math.PI];
|
|
|
334
336
|
export function tileOpts(cfg, s) {
|
|
335
337
|
const pal = cfg.palettes[s.pal];
|
|
336
338
|
const quarter = s.repeat === 'single' || s.repeat === 'checker';
|
|
337
|
-
const design = makeDesign(s.seed, s.density, s.bands, quarter ? 1.35 : 1, cfg.motifs[s.motif]);
|
|
339
|
+
const design = makeDesign(s.seed, s.density, s.bands, quarter ? 1.35 : 1, cfg.motifs[s.motif], s);
|
|
338
340
|
return { pal, design, quarter, hand: s.hand, brush: s.brush, painters: cfg.painters, material: cfg.material };
|
|
339
341
|
}
|
|
340
342
|
|
|
@@ -468,6 +470,78 @@ export function paintThumb(cfg, p, g, T, k) {
|
|
|
468
470
|
}
|
|
469
471
|
}
|
|
470
472
|
|
|
473
|
+
// -------------------------------------------------------------- print ---
|
|
474
|
+
// exportTile(wall, { cm, dpi, bleed }) paints the wall's tile once at
|
|
475
|
+
// print size, for someone to have it made: 15 cm at 300 dpi by default
|
|
476
|
+
// (1772 pixels), with a bleed of 3 mm all round. The bleed is the tile
|
|
477
|
+
// mirrored out past each edge, which is what its neighbour is in the
|
|
478
|
+
// module and close enough under the other repeats for a cutter's
|
|
479
|
+
// tolerance. It resolves to a PNG blob that says its own dpi, so it
|
|
480
|
+
// opens at the right size. A checker exports its painted tile.
|
|
481
|
+
export function exportTile(wall, opts) {
|
|
482
|
+
opts = opts || {};
|
|
483
|
+
const cm = opts.cm || 15, dpi = opts.dpi || 300, bleedMm = opts.bleed === undefined ? 3 : opts.bleed;
|
|
484
|
+
const px = Math.round(cm / 2.54 * dpi), bl = Math.round(bleedMm / 25.4 * dpi);
|
|
485
|
+
const cfg = { palettes: wall.palettes, motifs: wall.motifs, painters: wall.painters, material: wall.material };
|
|
486
|
+
const tile = makeTile(tileOpts(cfg, wall.state), px, 1, wall.state.seed * 31);
|
|
487
|
+
const c = document.createElement('canvas');
|
|
488
|
+
c.width = c.height = px + 2 * bl;
|
|
489
|
+
const g = c.getContext('2d');
|
|
490
|
+
for (const fy of [-1, 0, 1]) for (const fx of [-1, 0, 1]) {
|
|
491
|
+
if ((fx || fy) && !bl) continue;
|
|
492
|
+
g.save();
|
|
493
|
+
g.translate(bl + px / 2 + fx * px, bl + px / 2 + fy * px);
|
|
494
|
+
g.scale(fx ? -1 : 1, fy ? -1 : 1);
|
|
495
|
+
g.drawImage(tile, -px / 2, -px / 2);
|
|
496
|
+
g.restore();
|
|
497
|
+
}
|
|
498
|
+
return new Promise((resolve, reject) => c.toBlob(blob => {
|
|
499
|
+
if (!blob) { reject(new Error('the tile could not be encoded')); return; }
|
|
500
|
+
blob.arrayBuffer().then(buf => resolve(new Blob([pngWithDpi(new Uint8Array(buf), dpi)], { type: 'image/png' })), reject);
|
|
501
|
+
}, 'image/png'));
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
let CRC_TABLE = null;
|
|
505
|
+
export function crc32(bytes) {
|
|
506
|
+
if (!CRC_TABLE) {
|
|
507
|
+
CRC_TABLE = new Uint32Array(256);
|
|
508
|
+
for (let n = 0; n < 256; n++) {
|
|
509
|
+
let c = n;
|
|
510
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
511
|
+
CRC_TABLE[n] = c >>> 0;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
let c = 0xffffffff;
|
|
515
|
+
for (let i = 0; i < bytes.length; i++) c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ (c >>> 8);
|
|
516
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// a PNG's bytes with a pHYs chunk saying `dpi`, replacing one it has
|
|
520
|
+
export function pngWithDpi(png, dpi) {
|
|
521
|
+
const ppm = Math.round(dpi / 0.0254);
|
|
522
|
+
const chunk = new Uint8Array(21), v = new DataView(chunk.buffer);
|
|
523
|
+
v.setUint32(0, 9);
|
|
524
|
+
chunk.set([112, 72, 89, 115], 4); // pHYs
|
|
525
|
+
v.setUint32(8, ppm); v.setUint32(12, ppm);
|
|
526
|
+
chunk[16] = 1; // per metre
|
|
527
|
+
v.setUint32(17, crc32(chunk.subarray(4, 17)));
|
|
528
|
+
const dv = new DataView(png.buffer, png.byteOffset, png.byteLength);
|
|
529
|
+
let at = 8, after = 33; // the signature, then IHDR
|
|
530
|
+
while (at + 8 <= png.length) {
|
|
531
|
+
const len = dv.getUint32(at), type = String.fromCharCode(...png.subarray(at + 4, at + 8));
|
|
532
|
+
if (type === 'pHYs') {
|
|
533
|
+
const out = new Uint8Array(png.length - (len + 12) + 21);
|
|
534
|
+
out.set(png.subarray(0, at)); out.set(chunk, at); out.set(png.subarray(at + len + 12), at + 21);
|
|
535
|
+
return out;
|
|
536
|
+
}
|
|
537
|
+
if (type === 'IDAT' || type === 'IEND') break;
|
|
538
|
+
at += len + 12;
|
|
539
|
+
}
|
|
540
|
+
const out = new Uint8Array(png.length + 21);
|
|
541
|
+
out.set(png.subarray(0, after)); out.set(chunk, after); out.set(png.subarray(after), after + 21);
|
|
542
|
+
return out;
|
|
543
|
+
}
|
|
544
|
+
|
|
471
545
|
// ------------------------------------------------------------- viewer ---
|
|
472
546
|
// createViewer(canvas, { paint, scale, minZoom, maxZoom, margin }) is
|
|
473
547
|
// a canvas you paint a world into. It fills the window, and handles
|
|
@@ -741,8 +815,10 @@ export function createWall(canvas, cfg) {
|
|
|
741
815
|
// query string sets it; `change(value)` is what to do after. Then
|
|
742
816
|
// `newId` and `onNew` for the button that starts over, `mood(state)`
|
|
743
817
|
// for the line under it, `query(q)` for anything else in the query
|
|
744
|
-
// string, `fileName` and `suffix(state)` for the saved png,
|
|
745
|
-
// `
|
|
818
|
+
// string, `fileName` and `suffix(state)` for the saved png,
|
|
819
|
+
// `order(state)` (a promise of a blob) for the `#order` button that
|
|
820
|
+
// saves one tile at print size, and `ready()` once everything is
|
|
821
|
+
// applied.
|
|
746
822
|
export function mountChrome(viewer, spec) {
|
|
747
823
|
const doc = spec.document || document;
|
|
748
824
|
const $ = id => doc.getElementById(id);
|
|
@@ -804,14 +880,23 @@ export function mountChrome(viewer, spec) {
|
|
|
804
880
|
const on = (id, ev, fn) => { const el = $(id); if (el) el.addEventListener(ev, fn); };
|
|
805
881
|
if (spec.onNew) on(spec.newId || 'newDesign', 'click', () => { spec.onNew(); sync(); });
|
|
806
882
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
883
|
+
const download = (blob, tail) => {
|
|
884
|
+
const a = doc.createElement('a');
|
|
885
|
+
a.href = URL.createObjectURL(blob);
|
|
886
|
+
a.download = (spec.fileName || 'wall') + '-' + tail + (spec.suffix ? spec.suffix(state) : state.seed) + '.png';
|
|
887
|
+
a.click();
|
|
888
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 4000);
|
|
889
|
+
};
|
|
890
|
+
on('save', 'click', () => viewer.canvas.toBlob(blob => download(blob, '')));
|
|
891
|
+
if (spec.order) on('order', 'click', () => {
|
|
892
|
+
const btn = $('order'), label = btn.textContent;
|
|
893
|
+
btn.disabled = true; btn.textContent = 'painting the tile…';
|
|
894
|
+
// let the button say so before the paint holds the page
|
|
895
|
+
setTimeout(() => Promise.resolve()
|
|
896
|
+
.then(() => spec.order(state))
|
|
897
|
+
.then(blob => download(blob, 'tile-'))
|
|
898
|
+
.catch(e => console.error(e))
|
|
899
|
+
.finally(() => { btn.disabled = false; btn.textContent = label; }), 30);
|
|
815
900
|
});
|
|
816
901
|
|
|
817
902
|
const panel = $('panel');
|
|
@@ -868,7 +953,8 @@ export function mountChrome(viewer, spec) {
|
|
|
868
953
|
// tile wall's controls: selects `repeat`, `motif` and `palette`; ranges
|
|
869
954
|
// `density`, `hand`, `brush` and `zoom` with `densityVal`, `handVal`,
|
|
870
955
|
// `brushVal` and `zoomVal` beside them; checkboxes `bands`, `grout` and
|
|
871
|
-
// `age`; the `newDesign` button
|
|
956
|
+
// `age`; the `newDesign` button; the `order` button, which saves one
|
|
957
|
+
// tile at print size (`opts.print` is passed to `exportTile`). The query string takes ?preset=,
|
|
872
958
|
// ?seed=, ?repeat=, ?pal=, ?motif=, ?density=, ?hand=, ?zoom=, ?bands=0
|
|
873
959
|
// and ?age=1.
|
|
874
960
|
export function mountPanel(wall, opts) {
|
|
@@ -897,6 +983,7 @@ export function mountPanel(wall, opts) {
|
|
|
897
983
|
mood: s => 'design nº ' + s.seed,
|
|
898
984
|
query: q => { if (q.has('seed')) { state.seed = parseInt(q.get('seed'), 10) || state.seed; wall.preset = ''; } },
|
|
899
985
|
fileName: opts.fileName,
|
|
986
|
+
order: () => exportTile(wall, opts.print),
|
|
900
987
|
ready: tiles,
|
|
901
988
|
});
|
|
902
989
|
}
|