@altnovatrail/picture-kit 0.1.1 → 0.2.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.
Files changed (130) hide show
  1. package/README.md +1 -1
  2. package/lib/index.d.ts +45 -1
  3. package/lib/index.js +34 -3
  4. package/lib/kinds/balance.js +2 -3
  5. package/lib/kinds/calendar.d.ts +5 -1
  6. package/lib/kinds/calendar.js +33 -11
  7. package/lib/kinds/chart.js +2 -4
  8. package/lib/kinds/clock.d.ts +5 -0
  9. package/lib/kinds/clock.js +45 -4
  10. package/lib/kinds/coins.js +3 -2
  11. package/lib/kinds/column.js +2 -3
  12. package/lib/kinds/commands.d.ts +8 -6
  13. package/lib/kinds/commands.js +57 -15
  14. package/lib/kinds/containers.js +2 -1
  15. package/lib/kinds/countfig.d.ts +2 -0
  16. package/lib/kinds/countfig.js +6 -1
  17. package/lib/kinds/cubes.d.ts +29 -5
  18. package/lib/kinds/cubes.js +82 -34
  19. package/lib/kinds/die.d.ts +8 -0
  20. package/lib/kinds/die.js +75 -14
  21. package/lib/kinds/domino.js +3 -3
  22. package/lib/kinds/dotgrid.d.ts +3 -0
  23. package/lib/kinds/dotgrid.js +6 -4
  24. package/lib/kinds/figure.js +5 -4
  25. package/lib/kinds/fold-parts.d.ts +0 -2
  26. package/lib/kinds/fold-parts.js +0 -4
  27. package/lib/kinds/fold.d.ts +20 -1
  28. package/lib/kinds/fold.js +15 -6
  29. package/lib/kinds/fraction.js +3 -2
  30. package/lib/kinds/gauges.js +2 -1
  31. package/lib/kinds/gears.d.ts +21 -2
  32. package/lib/kinds/gears.js +113 -62
  33. package/lib/kinds/grid.d.ts +5 -0
  34. package/lib/kinds/grid.js +30 -2
  35. package/lib/kinds/groups.d.ts +3 -1
  36. package/lib/kinds/groups.js +142 -28
  37. package/lib/kinds/lanes.js +3 -2
  38. package/lib/kinds/layers.d.ts +6 -0
  39. package/lib/kinds/layers.js +23 -4
  40. package/lib/kinds/line.d.ts +4 -0
  41. package/lib/kinds/line.js +117 -32
  42. package/lib/kinds/matchsticks.d.ts +4 -0
  43. package/lib/kinds/matchsticks.js +5 -3
  44. package/lib/kinds/net.js +4 -3
  45. package/lib/kinds/overlay.d.ts +23 -1
  46. package/lib/kinds/overlay.js +7 -3
  47. package/lib/kinds/pieces.js +3 -2
  48. package/lib/kinds/plane-parts.d.ts +0 -2
  49. package/lib/kinds/plane-parts.js +0 -6
  50. package/lib/kinds/plane.js +6 -6
  51. package/lib/kinds/ropes.js +1 -3
  52. package/lib/kinds/shapes.js +5 -7
  53. package/lib/kinds/solids.js +3 -2
  54. package/lib/kinds/tangram.js +2 -4
  55. package/lib/kinds/target.js +4 -6
  56. package/lib/kinds/tiles.js +5 -4
  57. package/lib/kinds/venn.js +3 -5
  58. package/lib/noto.js +1 -0
  59. package/lib/objects.js +2 -1
  60. package/lib/read.d.ts +2 -2
  61. package/lib/read.js +3 -3
  62. package/lib/solve/balance.d.ts +11 -0
  63. package/lib/solve/balance.js +116 -1
  64. package/lib/solve/calendar.d.ts +46 -0
  65. package/lib/solve/calendar.js +206 -0
  66. package/lib/solve/choice-scenes.d.ts +20 -0
  67. package/lib/solve/choice-scenes.js +51 -0
  68. package/lib/solve/clock.d.ts +54 -0
  69. package/lib/solve/clock.js +240 -0
  70. package/lib/solve/coins.d.ts +71 -0
  71. package/lib/solve/coins.js +222 -0
  72. package/lib/solve/commands.d.ts +36 -0
  73. package/lib/solve/commands.js +210 -0
  74. package/lib/solve/countfig.d.ts +41 -0
  75. package/lib/solve/countfig.js +199 -0
  76. package/lib/solve/cubes.d.ts +49 -0
  77. package/lib/solve/cubes.js +255 -0
  78. package/lib/solve/die.d.ts +39 -0
  79. package/lib/solve/die.js +93 -0
  80. package/lib/solve/domino.d.ts +57 -0
  81. package/lib/solve/domino.js +263 -0
  82. package/lib/solve/enumerate.d.ts +75 -0
  83. package/lib/solve/enumerate.js +323 -0
  84. package/lib/solve/figure.d.ts +26 -0
  85. package/lib/solve/figure.js +88 -0
  86. package/lib/solve/fold.d.ts +22 -0
  87. package/lib/solve/fold.js +68 -0
  88. package/lib/solve/gaps.d.ts +65 -0
  89. package/lib/solve/gaps.js +292 -0
  90. package/lib/solve/gears.d.ts +33 -0
  91. package/lib/solve/gears.js +130 -0
  92. package/lib/solve/grid.d.ts +35 -0
  93. package/lib/solve/grid.js +194 -0
  94. package/lib/solve/groups.d.ts +93 -0
  95. package/lib/solve/groups.js +346 -0
  96. package/lib/solve/index.d.ts +60 -0
  97. package/lib/solve/index.js +194 -0
  98. package/lib/solve/layers.d.ts +30 -0
  99. package/lib/solve/layers.js +72 -0
  100. package/lib/solve/magic.d.ts +32 -0
  101. package/lib/solve/magic.js +216 -0
  102. package/lib/solve/matchsticks.d.ts +37 -0
  103. package/lib/solve/matchsticks.js +214 -0
  104. package/lib/solve/order.d.ts +94 -0
  105. package/lib/solve/order.js +419 -0
  106. package/lib/solve/overlay.d.ts +22 -0
  107. package/lib/solve/overlay.js +56 -0
  108. package/lib/solve/parity.d.ts +22 -0
  109. package/lib/solve/parity.js +27 -0
  110. package/lib/solve/pattern.d.ts +62 -0
  111. package/lib/solve/pattern.js +533 -0
  112. package/lib/solve/pieces.d.ts +57 -0
  113. package/lib/solve/pieces.js +309 -0
  114. package/lib/solve/pigeonhole.d.ts +38 -0
  115. package/lib/solve/pigeonhole.js +95 -0
  116. package/lib/solve/proof.d.ts +115 -0
  117. package/lib/solve/proof.js +105 -0
  118. package/lib/solve/pyramid.d.ts +28 -0
  119. package/lib/solve/pyramid.js +161 -0
  120. package/lib/solve/question.d.ts +25 -0
  121. package/lib/solve/question.js +75 -0
  122. package/lib/solve/shapes.d.ts +30 -0
  123. package/lib/solve/shapes.js +182 -0
  124. package/lib/solve/target.d.ts +40 -0
  125. package/lib/solve/target.js +190 -0
  126. package/lib/style.d.ts +1 -1
  127. package/lib/style.js +1 -1
  128. package/lib/words.d.ts +15 -0
  129. package/lib/words.js +39 -0
  130. package/package.json +1 -1
package/README.md CHANGED
@@ -22,7 +22,7 @@ A model that writes a task writes its scene, and a program draws it, so the pict
22
22
 
23
23
  A component of [NovaTrail](https://github.com/altnovatrail/spec), a universal open platform for adaptive learning, interactive lessons and AI tutoring.
24
24
 
25
- It is a library for the pictures of the tasks of `modules`, and later for a module's task generator and for `app`, which may draw a picture on the device; it calls no other component.
25
+ It is a library for the writer of tasks in `modules`, which draws each picture as a PNG and proves each key with its topic solvers when a module is prepared; it calls no other component.
26
26
 
27
27
  To see the pictures, open the repository in its devcontainer and run `just gallery`: it draws every example scene and serves them at http://127.0.0.1:5180/. `just ci` runs the checks CI runs.
28
28
 
package/lib/index.d.ts CHANGED
@@ -1,9 +1,53 @@
1
1
  export { type EmojiSource, noto } from "./emoji.ts";
2
2
  export type { Kind } from "./kind.ts";
3
3
  export type { BalanceScene, Scale } from "./kinds/balance.ts";
4
+ export type { ChoicesScene } from "./kinds/choices.ts";
5
+ export type { CoinsScene, Good, Money, Purse } from "./kinds/coins.ts";
6
+ export type { CommandsScene } from "./kinds/commands.ts";
7
+ export type { Countable, CountfigScene, FigPoint, Highlight } from "./kinds/countfig.ts";
8
+ export type { DieScene } from "./kinds/die.ts";
9
+ export type { DominoScene } from "./kinds/domino.ts";
10
+ export type { GridScene } from "./kinds/grid.ts";
11
+ export type { Group, GroupsScene } from "./kinds/groups.ts";
4
12
  export { kinds } from "./kinds/index.ts";
13
+ export type { MagicScene } from "./kinds/magic.ts";
14
+ export type { PiecesScene } from "./kinds/pieces.ts";
15
+ export type { PyramidScene } from "./kinds/pyramid.ts";
16
+ export type { ShapesScene } from "./kinds/shapes.ts";
17
+ export type { TangramScene } from "./kinds/tangram.ts";
18
+ export type { TargetScene } from "./kinds/target.ts";
19
+ export type { TilesScene } from "./kinds/tiles.ts";
5
20
  export { type ObjectEntry, objects } from "./objects.ts";
6
21
  export { check, describe, type Rendered, render, SceneError } from "./render.ts";
7
- export { type Answer, type Givens, type Question, solve as solveBalance } from "./solve/balance.ts";
22
+ export { type Answer, balanceSolver, type Givens, type Question, solve as solveBalance, } from "./solve/balance.ts";
23
+ export { type CalendarGivens, type CalendarQuestion, calendarSolver, type DayRef, } from "./solve/calendar.ts";
24
+ export { type ClockGivens, type ClockQuestion, type ClockRef, clockSolver } from "./solve/clock.ts";
25
+ export { type CoinsQuestion, coinsSolver, type GoodRef } from "./solve/coins.ts";
26
+ export { type CommandsGivens, type CommandsQuestion, commandsSolver } from "./solve/commands.ts";
27
+ export { type CountfigQuestion, countfigSolver, type Figure } from "./solve/countfig.ts";
28
+ export { type CubesGivens, type CubesQuestion, cubesSolver, type Ground, type StructureRef, } from "./solve/cubes.ts";
29
+ export { type DieQuestion, type DieRef, dieSolver, type HiddenFace } from "./solve/die.ts";
30
+ export { type DominoGivens, type DominoQuestion, dominoSolver } from "./solve/domino.ts";
31
+ export { type EnumerateGivens, type EnumerateQuestion, enumerateSolver, type ShelfRule, } from "./solve/enumerate.ts";
32
+ export { type FigureQuestion, figureSolver } from "./solve/figure.ts";
33
+ export { type FoldQuestion, foldSolver } from "./solve/fold.ts";
34
+ export { type GapsGivens, type GapsQuestion, type GapsScene, gapsSolver, } from "./solve/gaps.ts";
35
+ export { type GearsQuestion, gearsSolver, type Spin } from "./solve/gears.ts";
36
+ export { type GridGivens, type GridQuestion, gridSolver } from "./solve/grid.ts";
37
+ export { type GroupsGivens, type GroupsQuestion, groupsSolver, type HolderRef, type Move, type Parts, type Selection, type Things, } from "./solve/groups.ts";
38
+ export { checkTask, prove, solvers, type Task } from "./solve/index.ts";
39
+ export { type LayersGivens, type LayersQuestion, layersSolver } from "./solve/layers.ts";
40
+ export { type MagicGivens, type MagicQuestion, magicSolver } from "./solve/magic.ts";
41
+ export { type MatchsticksGivens, type MatchsticksQuestion, matchsticksSolver, } from "./solve/matchsticks.ts";
42
+ export { type OrderClue, type OrderEvent, type OrderGivens, type OrderQuestion, orderSolver, type Who, } from "./solve/order.ts";
43
+ export { type OverlayQuestion, overlaySolver } from "./solve/overlay.ts";
44
+ export { type ParityGivens, type ParityQuestion, paritySolver } from "./solve/parity.ts";
45
+ export { type PatternGivens, type PatternQuestion, type PatternScene, patternSolver, } from "./solve/pattern.ts";
46
+ export { type PiecesGivens, type PiecesQuestion, piecesSolver } from "./solve/pieces.ts";
47
+ export { type PigeonholeGivens, type PigeonholeQuestion, pigeonholeSolver, } from "./solve/pigeonhole.ts";
48
+ export { matches, type Offered, type Option, type Proof, provesKey, type Solver, sameValue, unread, type Value, } from "./solve/proof.ts";
49
+ export { type PyramidQuestion, pyramidSolver } from "./solve/pyramid.ts";
50
+ export { type ShapesQuestion, shapesSolver } from "./solve/shapes.ts";
51
+ export { type BoardRef, type TargetGivens, type TargetQuestion, targetSolver, } from "./solve/target.ts";
8
52
  export { type ColorName, colorNames } from "./style.ts";
9
53
  export { type ShapeName, sameThing, shapeNames, type Thing, wordOf } from "./things.ts";
package/lib/index.js CHANGED
@@ -1,10 +1,41 @@
1
1
  // The package's one entry point. A scene is drawn with render, its problems listed with check,
2
- // and its words given with describe; noto is the source of the emoji the package holds. What is
3
- // not exported here is the package's own and may change in any version.
2
+ // and its words given with describe; noto is the source of the emoji the package holds. A topic's
3
+ // solver proves a task's answer from its scene with prove, and checkTask holds a task's options
4
+ // and key to that proof. What is not exported here is the package's own and may change in any
5
+ // version.
4
6
  export { noto } from "./emoji.js";
5
7
  export { kinds } from "./kinds/index.js";
6
8
  export { objects } from "./objects.js";
7
9
  export { check, describe, render, SceneError } from "./render.js";
8
- export { solve as solveBalance } from "./solve/balance.js";
10
+ export { balanceSolver, solve as solveBalance, } from "./solve/balance.js";
11
+ export { calendarSolver, } from "./solve/calendar.js";
12
+ export { clockSolver } from "./solve/clock.js";
13
+ export { coinsSolver } from "./solve/coins.js";
14
+ export { commandsSolver } from "./solve/commands.js";
15
+ export { countfigSolver } from "./solve/countfig.js";
16
+ export { cubesSolver, } from "./solve/cubes.js";
17
+ export { dieSolver } from "./solve/die.js";
18
+ export { dominoSolver } from "./solve/domino.js";
19
+ export { enumerateSolver, } from "./solve/enumerate.js";
20
+ export { figureSolver } from "./solve/figure.js";
21
+ export { foldSolver } from "./solve/fold.js";
22
+ export { gapsSolver, } from "./solve/gaps.js";
23
+ export { gearsSolver } from "./solve/gears.js";
24
+ export { gridSolver } from "./solve/grid.js";
25
+ export { groupsSolver, } from "./solve/groups.js";
26
+ export { checkTask, prove, solvers } from "./solve/index.js";
27
+ export { layersSolver } from "./solve/layers.js";
28
+ export { magicSolver } from "./solve/magic.js";
29
+ export { matchsticksSolver, } from "./solve/matchsticks.js";
30
+ export { orderSolver, } from "./solve/order.js";
31
+ export { overlaySolver } from "./solve/overlay.js";
32
+ export { paritySolver } from "./solve/parity.js";
33
+ export { patternSolver, } from "./solve/pattern.js";
34
+ export { piecesSolver } from "./solve/pieces.js";
35
+ export { pigeonholeSolver, } from "./solve/pigeonhole.js";
36
+ export { matches, provesKey, sameValue, unread, } from "./solve/proof.js";
37
+ export { pyramidSolver } from "./solve/pyramid.js";
38
+ export { shapesSolver } from "./solve/shapes.js";
39
+ export { targetSolver, } from "./solve/target.js";
9
40
  export { colorNames } from "./style.js";
10
41
  export { sameThing, shapeNames, wordOf } from "./things.js";
@@ -4,6 +4,7 @@ import { int, isObj, list, oneOf, only, text } from "../read.js";
4
4
  import { colors, ink, outline } from "../style.js";
5
5
  import { poly } from "../svg.js";
6
6
  import { checkThing, count, drawThing, sameThing } from "../things.js";
7
+ import { listOf } from "../words.js";
7
8
  const tilts = ["left", "right", "level"];
8
9
  const size = 46;
9
10
  const perRow = 4;
@@ -30,9 +31,7 @@ export function groupThings(things) {
30
31
  return out;
31
32
  }
32
33
  function sayPan(things) {
33
- return groupThings(things)
34
- .map((g) => count(g.thing, g.count))
35
- .join(" and ");
34
+ return listOf(groupThings(things).map((g) => count(g.thing, g.count)));
36
35
  }
37
36
  /** drawScale draws one balance into a pen of its own, at 0, 0. */
38
37
  function drawScale(pen, scale) {
@@ -8,7 +8,9 @@ import { type Thing } from "../things.ts";
8
8
  * torn-off sheets, each with a month, a date and a weekday. A date may be
9
9
  * coloured or carry a thing, a "?" may stand in place of a date, and an ink
10
10
  * blot may cover one. Dates are named by their number, weekdays by their
11
- * first three letters: "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun".
11
+ * first three letters: "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun". A
12
+ * month page may show "?" in place of the names of some weekdays above their
13
+ * columns, as a torn-off sheet may in place of its weekday.
12
14
  */
13
15
  export declare const weekdays: readonly ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
14
16
  export type Weekday = (typeof weekdays)[number];
@@ -40,7 +42,9 @@ export type CalendarScene = {
40
42
  blots?: number[];
41
43
  sheets?: Sheet[];
42
44
  color?: ColorName;
45
+ askWeekdays?: Weekday[];
43
46
  };
47
+ export declare const dayWords: Record<Weekday, string>;
44
48
  /** ordinal writes a date as words read it: 1st, 2nd, 3rd, 4th, 11th, 22nd. */
45
49
  export declare function ordinal(d: number): string;
46
50
  /** columnsOf is the order of the weekdays across a month page. */
@@ -3,6 +3,7 @@ import { int, isObj, list, oneOf, only, text } from "../read.js";
3
3
  import { colorNames, colors, ink, isColor, outline, soft, textOn, } from "../style.js";
4
4
  import { n } from "../svg.js";
5
5
  import { checkThing, drawThing, wordOf } from "../things.js";
6
+ import { article } from "../words.js";
6
7
  /**
7
8
  * A calendar: a month page, its dates in rows of weeks under the names of
8
9
  * the days, the 1st under the weekday the scene names; or a strip of days
@@ -10,12 +11,14 @@ import { checkThing, drawThing, wordOf } from "../things.js";
10
11
  * torn-off sheets, each with a month, a date and a weekday. A date may be
11
12
  * coloured or carry a thing, a "?" may stand in place of a date, and an ink
12
13
  * blot may cover one. Dates are named by their number, weekdays by their
13
- * first three letters: "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun".
14
+ * first three letters: "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun". A
15
+ * month page may show "?" in place of the names of some weekdays above their
16
+ * columns, as a torn-off sheet may in place of its weekday.
14
17
  */
15
18
  export const weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
16
19
  export const calendarStyles = ["month", "strip", "sheets"];
17
20
  export const sheetAsks = ["day", "weekday", "month"];
18
- const dayWords = {
21
+ export const dayWords = {
19
22
  Mon: "Monday",
20
23
  Tue: "Tuesday",
21
24
  Wed: "Wednesday",
@@ -26,7 +29,7 @@ const dayWords = {
26
29
  };
27
30
  /** The members each style takes besides kind and style. */
28
31
  const styleMembers = {
29
- month: ["month", "first", "days", "weekStart", "marks", "ask", "blots", "color"],
32
+ month: ["month", "first", "days", "weekStart", "marks", "ask", "blots", "color", "askWeekdays"],
30
33
  strip: ["month", "first", "days", "start", "count", "marks", "ask", "blots", "color"],
31
34
  sheets: ["sheets", "color"],
32
35
  };
@@ -99,6 +102,18 @@ function checkPage(scene, style, problems) {
99
102
  int(scene.days, "days", problems, 28, 31);
100
103
  if (scene.weekStart !== undefined)
101
104
  oneOf(scene.weekStart, ["Mon", "Sun"], "weekStart", problems);
105
+ if (scene.askWeekdays !== undefined) {
106
+ const seen = new Set();
107
+ list(scene.askWeekdays, "askWeekdays", problems, 1, 7).forEach((w, i) => {
108
+ const before = problems.length;
109
+ oneOf(w, weekdays, `askWeekdays[${i}]`, problems);
110
+ if (problems.length > before)
111
+ return;
112
+ if (seen.has(w))
113
+ problems.push(`askWeekdays[${i}]: names ${String(w)} twice`);
114
+ seen.add(w);
115
+ });
116
+ }
102
117
  }
103
118
  else {
104
119
  if (scene.first !== undefined)
@@ -274,7 +289,10 @@ function monthPage(pen, c) {
274
289
  band(pen, c, width, top);
275
290
  pen.el("rect", { x: 0, y: top, width, height: head, fill: soft });
276
291
  columnsOf(c).forEach((w, i) => {
277
- pen.text((i + 0.5) * cellW, top + head / 2, w, { size: 15, weight: 700 });
292
+ if (c.askWeekdays?.includes(w))
293
+ drawThing(pen, { ask: true }, (i + 0.5) * cellW, top + head / 2, 28);
294
+ else
295
+ pen.text((i + 0.5) * cellW, top + head / 2, w, { size: 15, weight: 700 });
278
296
  });
279
297
  for (let day = 1; day <= c.days; day++) {
280
298
  const { row, col } = cellOf(c, day);
@@ -402,16 +420,13 @@ function sheetsPage(pen, c) {
402
420
  return { width: k * w + (k - 1) * gap, height: h + 10 };
403
421
  }
404
422
  // --- words ------------------------------------------------------------------
405
- function an(words) {
406
- return `${/^[aeiou]/.test(words) ? "an" : "a"} ${words}`;
407
- }
408
423
  function sayMarks(c, place) {
409
424
  return (c.marks ?? []).map((m) => {
410
425
  const what = [];
411
426
  if (m.color)
412
427
  what.push(`is coloured ${colors[m.color].word}`);
413
428
  if (m.thing !== undefined)
414
- what.push(`has ${an(wordOf(m.thing))} drawn on it`);
429
+ what.push(`has ${article(wordOf(m.thing))} drawn on it`);
415
430
  return `${place(m.day)} ${what.join(" and ")}.`;
416
431
  });
417
432
  }
@@ -438,6 +453,7 @@ export const calendar = {
438
453
  "blots",
439
454
  "sheets",
440
455
  "color",
456
+ "askWeekdays",
441
457
  ],
442
458
  check(scene, problems) {
443
459
  only(scene, this.members, "scene", problems);
@@ -506,11 +522,17 @@ export const calendar = {
506
522
  }
507
523
  const cols = columnsOf(c);
508
524
  const rows = rowsOf(c);
509
- const head = `A calendar page${c.month ? ` for ${c.month}` : ""}: ${c.days} days in ${rows} rows of weeks, the columns from ${dayWords[cols[0]]} to ${dayWords[cols[6]]}.`;
525
+ // Once a weekday's name is asked, a column is named by its place, never by its weekday.
526
+ const asked = c.askWeekdays ?? [];
527
+ const columns = asked.length === 0
528
+ ? `the columns from ${dayWords[cols[0]]} to ${dayWords[cols[6]]}`
529
+ : `in 7 columns headed, from left to right: ${cols.map((w) => (asked.includes(w) ? "?" : dayWords[w])).join(", ")}`;
530
+ const under = (col) => asked.length === 0 ? `under ${dayWords[cols[col]]}` : `in the ${ordinal(col + 1)} column`;
531
+ const head = `A calendar page${c.month ? ` for ${c.month}` : ""}: ${c.days} days in ${rows} rows of weeks, ${columns}.`;
510
532
  const hidden = (c.ask?.length ?? 0) + (c.blots?.length ?? 0) > 0;
511
533
  const out = [head];
512
534
  if (!hidden)
513
- out.push(`The 1st is in the first row under ${dayWords[c.first]}, and the dates follow in order, a row for each week, up to the ${ordinal(c.days)}.`);
535
+ out.push(`The 1st is in the first row ${under(cellOf(c, 1).col)}, and the dates follow in order, a row for each week, up to the ${ordinal(c.days)}.`);
514
536
  else
515
537
  for (let r = 0; r < rows; r++) {
516
538
  const cells = [];
@@ -524,7 +546,7 @@ export const calendar = {
524
546
  if (!c.ask?.includes(day))
525
547
  return `The ${ordinal(day)}`;
526
548
  const { row, col } = cellOf(c, day);
527
- return `The question mark in row ${row + 1} under ${dayWords[cols[col]]}`;
549
+ return `The question mark in row ${row + 1} ${under(col)}`;
528
550
  };
529
551
  out.push(...sayMarks(c, where));
530
552
  return out.join(" ");
@@ -4,6 +4,7 @@ import { int, isObj, list, oneOf, only, text } from "../read.js";
4
4
  import { colorNames, colors, faint, ink, isColor, outline, soft, } from "../style.js";
5
5
  import { n } from "../svg.js";
6
6
  import { checkThing, count, drawThing, wordOf } from "../things.js";
7
+ import { article } from "../words.js";
7
8
  /**
8
9
  * A chart: a bar chart, its bars standing on a line side by side or lying
9
10
  * one under another, read against a scale with a line at every step; or a
@@ -522,9 +523,6 @@ function nameOf(b) {
522
523
  return `"${b.label}"`;
523
524
  return wordOf(b.thing, 2);
524
525
  }
525
- function an(words) {
526
- return `${/^[aeiou]/.test(words) ? "an" : "a"} ${words}`;
527
- }
528
526
  function sayBar(b, step, color) {
529
527
  if (b.ask)
530
528
  return "the bar is missing, a question mark stands in its place";
@@ -546,7 +544,7 @@ function sayIcons(b, icon, unit) {
546
544
  if (whole > 0)
547
545
  parts.push(count(icon, whole));
548
546
  if (half)
549
- parts.push(`half ${an(wordOf(icon))}`);
547
+ parts.push(`half ${article(wordOf(icon))}`);
550
548
  return parts.join(" and ");
551
549
  }
552
550
  export const chart = {
@@ -6,6 +6,8 @@ import { type ColorName } from "../style.ts";
6
6
  * minute hand turns 6 degrees a minute and the hour hand 30 degrees an hour
7
7
  * and half a degree a minute, so the hour hand stands between the hours as
8
8
  * on a real clock. A clock may show its time in digits below, and a label.
9
+ * A mirrored clock is the clock as a mirror shows it: the face, its numbers
10
+ * and its hands turned left for right, its time the time of the real clock.
9
11
  */
10
12
  export declare const faces: readonly ["numbers", "quarters", "ticks"];
11
13
  export type Face = (typeof faces)[number];
@@ -15,6 +17,7 @@ export type Clock = {
15
17
  digital?: boolean;
16
18
  label?: string;
17
19
  color?: ColorName;
20
+ mirror?: boolean;
18
21
  };
19
22
  export type ClockScene = {
20
23
  kind: "clock";
@@ -33,4 +36,6 @@ export declare function angles(time: string): {
33
36
  };
34
37
  /** handsOf says where the hands of a time point, as a learner reads them. */
35
38
  export declare function handsOf(time: string): string;
39
+ /** mirrored is the time a clock seems to show in a mirror: the hands turned left for right. */
40
+ export declare function mirrored(time: string): string;
36
41
  export declare const clock: Kind;
@@ -8,11 +8,16 @@ import { esc, n } from "../svg.js";
8
8
  * minute hand turns 6 degrees a minute and the hour hand 30 degrees an hour
9
9
  * and half a degree a minute, so the hour hand stands between the hours as
10
10
  * on a real clock. A clock may show its time in digits below, and a label.
11
+ * A mirrored clock is the clock as a mirror shows it: the face, its numbers
12
+ * and its hands turned left for right, its time the time of the real clock.
11
13
  */
12
14
  export const faces = ["numbers", "quarters", "ticks"];
13
15
  const most = 6;
14
16
  const perRow = 4;
15
- const gap = 22;
17
+ const gap = 12;
18
+ /** Half a digit's width on a face, and half its height, for each pixel of the numbers' size. */
19
+ const digitWidth = 0.3;
20
+ const digitHeight = 0.37;
16
21
  /** parse reads "H:MM", H from 0 to 23 and MM from 00 to 59. */
17
22
  export function parse(time) {
18
23
  const match = /^(\d{1,2}):(\d{2})$/.exec(time);
@@ -49,6 +54,10 @@ function hand(pen, cx, cy, length, width, turn, name) {
49
54
  });
50
55
  }
51
56
  function drawClock(pen, clock, face, cx, cy, r) {
57
+ // A mirror turns everything left for right about the clock's upright middle line, the
58
+ // numbers' glyphs too; the "?" of an asked clock stays readable, so it is drawn outside.
59
+ if (clock.mirror)
60
+ pen.add(`<g class="mirror" transform="translate(${n(2 * cx)} 0) scale(-1 1)">`);
52
61
  const c = colors[clock.color ?? "blue"];
53
62
  const rim = Math.max(6, r * 0.09);
54
63
  const inner = r - rim;
@@ -69,11 +78,16 @@ function drawClock(pen, clock, face, cx, cy, r) {
69
78
  }
70
79
  if (face !== "ticks") {
71
80
  const size = Math.max(14, r * 0.2);
72
- const rn = inner - Math.max(6, r * 0.11) - 6 - size * 0.7;
81
+ // Each number stands as near the hour marks as its box lets it, the box as wide as its
82
+ // digits and as tall as a digit, a few pixels inside the marks: so 12 stands higher than 11
83
+ // and 1, and the two-digit numbers at the top keep apart at every size a face is drawn at.
84
+ const ring = inner - Math.max(6, r * 0.11) - 6;
73
85
  const shown = face === "numbers" ? [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] : [12, 3, 6, 9];
74
86
  let numbers = "";
75
87
  for (const h of shown) {
76
88
  const a = (h * Math.PI) / 6;
89
+ const half = { x: String(h).length * digitWidth * size, y: digitHeight * size };
90
+ const rn = ring - half.x * Math.abs(Math.sin(a)) - half.y * Math.abs(Math.cos(a));
77
91
  const x = cx + rn * Math.sin(a);
78
92
  const y = cy - rn * Math.cos(a) + size * 0.36;
79
93
  numbers += `<text x="${n(x)}" y="${n(y)}" font-size="${n(size)}" font-weight="700" text-anchor="middle" fill="${ink}" font-family="${esc(font)}">${h}</text>`;
@@ -81,6 +95,8 @@ function drawClock(pen, clock, face, cx, cy, r) {
81
95
  pen.add(`<g class="numbers">${numbers}</g>`);
82
96
  }
83
97
  if (clock.ask) {
98
+ if (clock.mirror)
99
+ pen.add("</g>");
84
100
  const q = r * 0.3;
85
101
  pen.el("circle", {
86
102
  cx,
@@ -105,6 +121,8 @@ function drawClock(pen, clock, face, cx, cy, r) {
105
121
  stroke: ink,
106
122
  "stroke-width": 2,
107
123
  });
124
+ if (clock.mirror)
125
+ pen.add("</g>");
108
126
  }
109
127
  // --- words -------------------------------------------------------------------
110
128
  function hourWord(h) {
@@ -124,6 +142,18 @@ export function handsOf(time) {
124
142
  : `the minute hand points between ${Math.floor(mark) === 0 ? 12 : Math.floor(mark)} and ${Math.ceil(mark) === 12 ? 12 : Math.ceil(mark)}, at minute ${m}`;
125
143
  return `${minute}, ${hour}`;
126
144
  }
145
+ /** mirrored is the time a clock seems to show in a mirror: the hands turned left for right. */
146
+ export function mirrored(time) {
147
+ const { h, m } = parse(time);
148
+ const seen = (720 - ((h % 12) * 60 + m)) % 720;
149
+ const hours = Math.floor(seen / 60);
150
+ return `${hours === 0 ? 12 : hours}:${String(seen % 60).padStart(2, "0")}`;
151
+ }
152
+ const mirrorFace = {
153
+ numbers: ": its numbers are drawn back to front and run anticlockwise, 12 at the top, 3 on the left, 6 at the bottom and 9 on the right;",
154
+ quarters: ": its numbers are drawn back to front, 12 at the top, 3 on the left, 6 at the bottom and 9 on the right;",
155
+ ticks: ";",
156
+ };
127
157
  export const clock = {
128
158
  kind: "clock",
129
159
  members: ["kind", "clocks", "face"],
@@ -137,7 +167,7 @@ export const clock = {
137
167
  problems.push(`${path}: must be a clock with a time`);
138
168
  return;
139
169
  }
140
- only(c, ["time", "ask", "digital", "label", "color"], path, problems);
170
+ only(c, ["time", "ask", "digital", "label", "color", "mirror"], path, problems);
141
171
  if (c.ask !== undefined && c.ask !== true)
142
172
  problems.push(`${path}.ask: must be true, or left out`);
143
173
  if (c.ask === true) {
@@ -148,6 +178,10 @@ export const clock = {
148
178
  problems.push(`${path}.time: must be a time "H:MM", hours 0 to 23, minutes 00 to 59, or ask: true`);
149
179
  if (c.digital !== undefined && typeof c.digital !== "boolean")
150
180
  problems.push(`${path}.digital: must be true or false`);
181
+ if (c.mirror !== undefined && typeof c.mirror !== "boolean")
182
+ problems.push(`${path}.mirror: must be true or false`);
183
+ if (c.mirror === true && c.digital === true)
184
+ problems.push(`${path}.digital: a mirrored clock shows no digits; draw the clock as it is beside it for that`);
151
185
  if (c.label !== undefined)
152
186
  text(c.label, `${path}.label`, problems, 8);
153
187
  if (c.color !== undefined && !isColor(c.color))
@@ -204,13 +238,20 @@ export const clock = {
204
238
  ? "with only the numbers 12, 3, 6 and 9"
205
239
  : "with marks but no numbers";
206
240
  const one = (c) => {
241
+ if (c.mirror) {
242
+ // The words say what the mirror shows, so that the real time is worked out, not read.
243
+ const seen = c.ask
244
+ ? "no hands, a question mark in the middle"
245
+ : `its hands stand as an ordinary clock's do at ${mirrored(c.time)}: ${handsOf(mirrored(c.time))}, the places named as on an ordinary clock`;
246
+ return `seen in a mirror${mirrorFace[s.face ?? "numbers"]} ${seen}`;
247
+ }
207
248
  if (c.ask)
208
249
  return `no hands, a question mark in the middle${c.digital ? ", and ? in digits below" : ""}`;
209
250
  return `${c.time}: ${handsOf(c.time)}${c.digital ? `; below it the time in digits, ${c.time}` : ""}`;
210
251
  };
211
252
  if (s.clocks.length === 1) {
212
253
  const c = s.clocks[0];
213
- return `A clock ${face}${c.label ? `, labelled ${c.label}` : ""}, showing ${one(c)}.`;
254
+ return `A clock ${face}${c.label ? `, labelled ${c.label}` : ""}, ${c.mirror ? "" : "showing "}${one(c)}.`;
214
255
  }
215
256
  return `${s.clocks.length} clocks in a row, each ${face}. ${s.clocks
216
257
  .map((c, i) => `Clock ${c.label ?? i + 1}: ${one(c)}.`)
@@ -4,7 +4,8 @@ import { int, isObj, list, oneOf, only, text } from "../read.js";
4
4
  import { colorNames, colors, ink, isColor, outline, textOn } from "../style.js";
5
5
  import { n } from "../svg.js";
6
6
  import { checkThing, drawThing, wordOf } from "../things.js";
7
- import { article, mix } from "./cubes.js";
7
+ import { article, listOf } from "../words.js";
8
+ import { mix } from "./cubes.js";
8
9
  /**
9
10
  * Coins: money and goods. Groups of coins and banknotes, each in a holder the
10
11
  * picture draws itself — a purse, a piggy bank, an open hand — or in none;
@@ -452,7 +453,7 @@ function sayMoney(group) {
452
453
  ? `${what} with a question mark instead of the value`
453
454
  : `${what} of ${value}`;
454
455
  });
455
- return parts.length === 1 ? parts[0] : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`;
456
+ return listOf(parts);
456
457
  }
457
458
  function sayGroup(group, i, many) {
458
459
  const holder = group.holder ?? "none";
@@ -3,6 +3,7 @@ import { isObj, list, oneOf, only } from "../read.js";
3
3
  import { colors, ink, outline } from "../style.js";
4
4
  import { n } from "../svg.js";
5
5
  import { checkThing, drawThing, sameThing, wordOf } from "../things.js";
6
+ import { article } from "../words.js";
6
7
  import { ordinal, plural, sayList } from "./magic-parts.js";
7
8
  /**
8
9
  * Column: a sum, a difference or a product written in columns, the units
@@ -189,8 +190,6 @@ function checkFacts(s, facts, problems) {
189
190
  }
190
191
  }
191
192
  }
192
- /** a puts "a" or "an" before a word. */
193
- const a = (word) => `${/^[aeiou]/i.test(word) ? "an" : "a"} ${word}`;
194
193
  function sayCell(c, masks) {
195
194
  if (/[0-9]/.test(c))
196
195
  return c;
@@ -201,7 +200,7 @@ function sayCell(c, masks) {
201
200
  if (c === "?")
202
201
  return "a question mark";
203
202
  const thing = masks?.[c];
204
- return thing === undefined ? `the letter ${c}` : a(wordOf(thing));
203
+ return thing === undefined ? `the letter ${c}` : article(wordOf(thing));
205
204
  }
206
205
  /** drawCell draws one cell of a row, centred at x, y. */
207
206
  function drawCell(pen, c, x, y, masks) {
@@ -4,12 +4,13 @@ import { type Thing } from "../things.ts";
4
4
  * Commands: a program, a strip of command tiles read from the left — arrows
5
5
  * that move one cell up, down, left or right whatever way the walker faces,
6
6
  * or blocks that step forward, jump, turn left or turn right from the way it
7
- * faces —, with a repeat drawn as a frame round the commands it repeats and
8
- * an if-block as a frame with a thing to check, a row for yes (✓) and a row
9
- * for no (✗). Beside or under the strip may stand a board: the walker (the
10
- * robot or an animal) on its start, a pointer on the side it faces, a
11
- * target, obstacles, other things, cells marked with letters and a drawn
12
- * path. A place is [row, column], counted from 1 at the top left.
7
+ * faces, a jump two cells forward, over the cell ahead and whatever stands on
8
+ * it —, with a repeat drawn as a frame round the commands it repeats and an
9
+ * if-block as a frame with a thing to check, a row for yes (✓) and a row for
10
+ * no (✗). Beside or under the strip may stand a board: the walker (the robot
11
+ * or an animal) on its start, a pointer on the side it faces, a target,
12
+ * obstacles, other things, cells marked with letters, walls between cells and
13
+ * a drawn path. A place is [row, column], counted from 1 at the top left.
13
14
  * {"ask": true} stands for a command, or a repeat's count, that the question
14
15
  * asks.
15
16
  */
@@ -51,6 +52,7 @@ export type Board = {
51
52
  at: At;
52
53
  label: string;
53
54
  }[];
55
+ walls?: [At, At][];
54
56
  path?: At[];
55
57
  };
56
58
  export type CommandsScene = {