azulejeria 2.2.0 → 2.3.1

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 CHANGED
@@ -83,9 +83,11 @@ tap. Drive it from your own controls through `wall.state` and
83
83
 
84
84
  ## The parts
85
85
 
86
- **`createWall(canvas, { palettes, motifs, painters, presets, material })`** returns
86
+ **`createWall(canvas, { palettes, motifs, painters, presets, material, variants })`** returns
87
87
  the wall. `wall.state` holds `seed`, `repeat` (`module`, `rotate`,
88
- `single` or `checker`), `pal`, `motif`, `density` (1 to 5), `hand` (0 to
88
+ `single`, `checker`, or `whole` for a tile that is a picture, every one
89
+ laid the same way up; `variants` is how many paintings of the design
90
+ such a wall draws from, four by default), `pal`, `motif`, `density` (1 to 5), `hand` (0 to
89
91
  1, how far the brush drifts), `brush` (line weight), `scale` (pixels per
90
92
  tile), `panX`, `panY`, `bands`, `grout` and `age`. After changing any of
91
93
  them call `wall.rebuild(true)` to repaint the tiles, or `wall.rebuild(false)`
@@ -181,7 +183,7 @@ diamond), `ring` (a scalloped ring around the main corner), `lattice` (a
181
183
  line edge to edge that mirrors into a lozenge net) and `dots`.
182
184
 
183
185
  **The lower level** is there if you want it: `makeDesign(seed, density,
184
- bands, bold, motif)`, `paintDesign(g, els, pal, hand, lw, seed, painters)`,
186
+ bands, bold, motif)`, `paintDesign(g, els, pal, hand, lw, seed, painters, material, brush)`,
185
187
  `makeTile(opts, size, pixelRatio, seed)`, `tileOpts(cfg, state)` and
186
188
  `paintThumb(cfg, preset, g, size, pixelRatio)`.
187
189
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azulejeria",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "description": "Tin-glazed tiles painted by rule. A seeded canvas engine for Spanish azulejo walls: a diagonal-symmetric design, brushwork that drifts, washes that pool, and four ways to repeat the tile.",
5
5
  "keywords": ["canvas", "generative", "tiles", "azulejo", "mudejar", "sevilla", "pattern", "procedural", "art", "wallpaper", "interlace", "knotwork", "celtic", "mosaic", "voronoi", "trencadis"],
6
6
  "license": "MIT",
package/src/azulejeria.js CHANGED
@@ -219,14 +219,16 @@ export const PAINTERS = {
219
219
 
220
220
  // paints one design into the unit square of g (already scaled). The
221
221
  // material, if given, may supply `ampOf(hand)`, `shape(g, pts, col, b)`,
222
- // `line(g, pts, lw, close, b)` and `dot(g, x, y, r, col, a, b)`.
223
- export function paintDesign(g, els, pal, hand, lw, jseed, painters, material) {
222
+ // `line(g, pts, lw, close, b)` and `dot(g, x, y, r, col, a, b)`. The
223
+ // brush `b` also carries `hand` and `brush` as the state has them, for
224
+ // a painter whose line is not drawn with `lw` (a traced drawing, say).
225
+ export function paintDesign(g, els, pal, hand, lw, jseed, painters, material, brush) {
224
226
  const rng = mulberry32(jseed);
225
227
  const m = material || {};
226
228
  const amp = m.ampOf ? m.ampOf(hand) : 0.012 * hand;
227
229
  const Q = Math.PI / 2, D = Q / 2;
228
230
  const dc = Math.cos(D), ds = Math.sin(D); // the diagonal
229
- const b = { g, pal, lw, amp, rng, Q, D, dc, ds, col: pal.wash };
231
+ const b = { g, pal, lw, amp, rng, Q, D, dc, ds, col: pal.wash, hand, brush: brush === undefined ? 1 : brush };
230
232
  const shape = m.shape
231
233
  ? (pts, col) => m.shape(g, pts, col, b)
232
234
  : (pts, col) => { wash(g, pts, col, rng); ink(g, pts, lw, pal, rng, true); };
@@ -262,7 +264,9 @@ export function paintDesign(g, els, pal, hand, lw, jseed, painters, material) {
262
264
  // --------------------------------------------------------------- tile ---
263
265
  // One tile, painted. `o.quarter` lays the design four times mirrored
264
266
  // about the centre; otherwise the design fills the tile with its main
265
- // corner at bottom right, for the module to complete. `o.plain` paints
267
+ // corner at bottom right, for the module to complete (or, with the
268
+ // 'whole' repeat, every tile laid the same way up: a tile that is a
269
+ // picture). `o.plain` paints
266
270
  // the small tile a checker alternates with.
267
271
  export function makeTile(o, S, k, jseed) {
268
272
  const c = document.createElement('canvas');
@@ -305,18 +309,18 @@ export function makeTile(o, S, k, jseed) {
305
309
  let v = 0;
306
310
  for (const [fx, fy] of [[1, 1], [-1, 1], [1, -1], [-1, -1]]) {
307
311
  g.save(); g.translate(S / 2, S / 2); g.scale(fx * S / 2, fy * S / 2);
308
- paintDesign(g, o.design, pal, o.hand, 0.024 * o.brush, jseed + 17 + v++, o.painters, o.material);
312
+ paintDesign(g, o.design, pal, o.hand, 0.024 * o.brush, jseed + 17 + v++, o.painters, o.material, o.brush);
309
313
  g.restore();
310
314
  }
311
315
  } else {
312
316
  g.save(); g.translate(S, S); g.scale(-S, -S);
313
- paintDesign(g, o.design, pal, o.hand, 0.012 * o.brush, jseed + 17, o.painters, o.material);
317
+ paintDesign(g, o.design, pal, o.hand, 0.012 * o.brush, jseed + 17, o.painters, o.material, o.brush);
314
318
  g.restore();
315
319
  }
316
320
  return c;
317
321
  }
318
322
 
319
- export const REPEATS = ['module', 'rotate', 'single', 'checker'];
323
+ export const REPEATS = ['module', 'rotate', 'single', 'checker', 'whole'];
320
324
  const ROT = [0, Math.PI / 2, 3 * Math.PI / 2, Math.PI];
321
325
 
322
326
  // the tile options for a given state (preset or live)
@@ -468,8 +472,10 @@ export function createViewer(canvas, opts) {
468
472
  }
469
473
 
470
474
  // --------------------------------------------------------------- wall ---
471
- // createWall(canvas, { palettes, motifs, painters, presets, material })
472
- // is a viewer that paints a wall of tiles. It returns the wall, which
475
+ // createWall(canvas, { palettes, motifs, painters, presets, material,
476
+ // variants }) is a viewer that paints a wall of tiles. `variants` is how
477
+ // many paintings of the design the wall draws from (four unless told
478
+ // otherwise; a wall of whole tiles, each its own picture, wants more). It returns the wall, which
473
479
  // is the viewer with more on it: `state` to read or change, then
474
480
  // `rebuild(true)` to repaint the tiles or `rebuild(false)` to redraw
475
481
  // the wall with the tiles it has. `applyPreset(name)`, `newDesign()`
@@ -485,6 +491,7 @@ export function createWall(canvas, cfg) {
485
491
  const painters = cfg.painters || PAINTERS;
486
492
  const material = cfg.material || null, m = material || {};
487
493
  const lay = m.lay || { shift: 0.014, turn: 0.016 };
494
+ const variants = cfg.variants || 4;
488
495
  const firstMotif = Object.keys(motifs)[0];
489
496
  for (const p of Object.values(presets)) if (!p.motif) p.motif = firstMotif;
490
497
 
@@ -511,7 +518,7 @@ export function createWall(canvas, cfg) {
511
518
  const o = tileOpts(tcfg, state);
512
519
  tiles.A = [];
513
520
  tiles.B = [];
514
- for (let v = 0; v < 4; v++) tiles.A.push(makeTile(o, state.scale, DPR, state.seed * 31 + v));
521
+ for (let v = 0; v < variants; v++) tiles.A.push(makeTile(o, state.scale, DPR, state.seed * 31 + v));
515
522
  if (state.repeat === 'checker')
516
523
  for (let v = 0; v < 3; v++) tiles.B.push(makeTile({ ...o, plain: true }, state.scale, DPR, state.seed * 37 + v));
517
524
  needTiles = false;