synth

package
v0.1.74 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package synth draws synthetic samples, for eval and for tests, and a synthetic bank of tasks for tests. No handwriting is in the repository: the strokes here are drawn by code, from a simple vector font, with time and a little jitter, so that they look like what a pen gives without being anyone's hand. Every sample is the same each time it is drawn, on any machine. The same font, with the signs of school mathematics, writes the tutor's own lines on a sheet (Handwriting).

A product that goes into a sum is rounded on its own, float64(…). Go may otherwise fuse a multiplication and an addition into one instruction where the processor has one, as arm64 does, and a point would then come out a little different from one architecture to another; the golden pictures of internal/render are drawn from these samples. A length is a square root of rounded squares for the same reason: math.Hypot is assembly on amd64 and Go elsewhere, and the two need not give the same bits.

Index

Constants

View Source
const (
	EssayWidth  = 1000
	EssayHeight = 1400
)

The page of an essay is a handwriting sheet of the module format, 1000 × 1400 units. The title stands on its first line, and the text below it, broken between words into lines of at most essayMinLine to essayMaxLine characters, a number each essay draws from the seed: so the size of the hand varies from essay to essay, since the hand is fitted to the longest line (Text).

View Source
const (
	TaskLinear      = "synthetic-linear-01"
	TaskCalculation = "synthetic-calculation-01"
	TaskFree        = "synthetic-free-01"
)

The IDs of the synthetic tasks.

View Source
const (
	PageWidth  = 1000
	PageHeight = 1400
	// BoxSide is the width and the height of a box.
	BoxSide = 100
)

A page of the workbook is laid out by canvas's numbers — a page of 1000 × 1400 units, boxes of 100 × 100, margins of 40, rows 100 high and 32 apart, the line 56 from the item's left edge and a box 16 from a word — in a layout of tutor's own, simpler than canvas's: every item on a row of its own, its boxes where the widths of the print before them put them. Only the strokes of a box go to the reading, so the layout tells where the hand writes and no more.

View Source
const SimilarShift = 0.1

SimilarShift is how far toward the digit of its pair the digit of a sheet of the scenario "similar-digits" is drawn: 0 is the digit as the font has it, 1 the digit of its pair. It is the largest share of those tried, 0.5 down to 0.1, at which Opus without the key read 11 of the 12 sheets of the plan right, drawn with the seed 2. The near set is drawn and split with it, and is not drawn again.

Variables

This section is empty.

Functions

func Bank

func Bank() *sample.Bank

Bank returns the synthetic bank: one task of each kind.

func CheckLayout

func CheckLayout(wb *sample.Workbook) error

CheckLayout checks that every page of a workbook can be laid out: its items fit the rows of a page, and each line fits across it. It lists every line that does not, by its path in the file.

func Essay

func Essay(e *sample.Essay, seed uint64) (lines []string, strokes []sample.Stroke)

Essay draws an essay as a learner writes it, from the seed, on a page of EssayWidth × EssayHeight: the lines it is written in, and its strokes in the order they were written. Each essay draws the width of its lines and its hand from the seed and its number. Between two words the hand leaves a gap of two spaces, a whole advance: the half advance of a space in a line of sums would run the words of a text together. It panics on an essay with no words.

func EssayLines

func EssayLines(e *sample.Essay, width int) []string

EssayLines are the lines an essay is written in: its title, when it has one, and its text broken between words into lines at most width characters long. A word longer than that takes a line of its own.

func EssayLinesOf added in v0.1.7

func EssayLinesOf(e *sample.Essay, seed uint64) []string

EssayLinesOf are the lines Essay writes an essay in from the seed, without drawing it: the width of its lines is the first thing the seed and the essay's number draw.

func Handwriting added in v0.1.67

func Handwriting(s string, x, baseline, size float64) (strokes [][]Point, missing []rune)

Handwriting writes a line of text in the hand of the font, as polylines: x is the left end of its baseline and baseline the foot of a capital or a digit, whose height is size; a small letter takes its lower part and a tail goes below the line. Each character takes the room its strokes need, and a dot is a short stroke, so that every stroke has two points. A character it does not write is left out, with the room of a space, and named among missing, each once, in its order.

func Plan

func Plan() (*sample.Plan, []*sample.Sample)

Plan returns the sheet plan of the synthetic samples a plan can hold, one sheet each in the order of sample.Scenarios, and those samples in the plan's order: each plan sheet has its sample's task, scenario, line texts, answer line, outcome and planned erasure, which writes its whole line again. The scenarios a plan cannot hold — illegible-crossed-out, nearly-empty and injection — are left out.

func Sample

func Sample(sc sample.Scenario) *sample.Sample

Sample returns the synthetic sample of a scenario. It panics on a scenario sample.Scenarios does not list.

func Samples

func Samples() []*sample.Sample

Samples returns one synthetic sample of each scenario, in the order of sample.Scenarios.

func Sheet

func Sheet(sh *sample.PlanSheet, seed uint64) *sample.Sample

Sheet draws a plan sheet as a writer would write it, from the seed; each plan sheet draws its own hand from it, and the same seed draws the same sheet again: its lines top to bottom in the plan's order and, on a sheet of an erasure scenario, the planned erasure in the order the plan gives — the lines before it, the writing to erase, one move of the eraser, what is written in its place and the rest of the lines. Its markup is the plan's, and its writer is "synthetic". A sheet of a plan of parts is written part by part, each where its place puts it (sheetOfParts). On a sheet of the scenario "similar-digits", the last digit of the answer line leans toward the digit of its pair (SimilarShift); a digit of no pair, an answer line with the planned erasure and a sheet of parts do not lean. It panics on a plan sheet the plan's check refuses, such as one without lines, and on one code cannot draw (Drawable).

func SheetLeaning

func SheetLeaning(sh *sample.PlanSheet, seed uint64, shift float64) *sample.Sample

SheetLeaning is Sheet with the digit of the answer of a sheet of the scenario "similar-digits" leaning the share shift toward the digit of its pair: draw takes it with -shift, to draw the near sheets of the extended measurement at shares 0.1 to 0.4.

func Similar

func Similar(r rune) (rune, bool)

Similar is the digit of a digit's pair, and false for a digit of no pair or no digit at all: the pairs of digits a hand writes alike, each the other's (sample.PairOf), so the digit of a key and the digit of its near key, which a sheet of the near set mixes.

func SimilarDigit

func SimilarDigit(line string) (at int, toward rune, ok bool)

SimilarDigit is the digit a sheet of the scenario "similar-digits" draws shifted in its answer line: the last digit of the line, by its place among the characters of the line, and the digit of its pair it leans toward; false when the last digit has no pair or the line no digit.

func Text

func Text(lines []string, sheet sample.Sheet, seed uint64) []sample.Stroke

Text draws lines of text as a writer would write them, from the seed, top to bottom on a sheet of the size given: a hand of its own, fitted so that the longest line fits across the sheet, and, when the lines are many, made smaller so that a line is at least 1.6 of its height below the one before it and the tails of one line clear the capitals of the next. The lines are laid out and paused between as on a sheet of the plan (nextLine). It returns the strokes in the order they were written. The essays are drawn with it. It panics on no lines, and on a sheet the strokes of a sample cannot lie on.

func Writes added in v0.1.67

func Writes(r rune) bool

Writes reports whether Handwriting writes a character: a space, or one of its glyphs.

Types

type Box

type Box struct {
	Item, Slot int
	Left, Top  float64
	Strokes    []sample.Stroke
}

Box is a box of a page: the place of its item and its own among the item's boxes, from 1, where it stands, its top left corner in units of the page, and the strokes written in it.

type Page

type Page struct {
	Number int
	Boxes  []Box
}

Page is a page of the workbook as code writes it: its boxes, in the order of the page, by item and then by box, with the strokes written in each. A blank box has none.

func PageOf

func PageOf(pg *sample.WorkbookPage, seed uint64) (*Page, error)

PageOf draws a page of the workbook as a learner writes it, from the seed: one hand for the page, drawn from the seed and the page's number, item by item and box by box, with a pause to read each item. A box holds its value written plainly, or as its scenario says: a digit leaning toward another, a digit mirrored, a wrong value crossed out and the value written beside it. A fraction is written stacked or inline, as its box says. The writing stays within its box, so that by the canvas's rule of boxes each stroke is its box's. The same seed draws the same page again. A page that cannot be laid out (CheckLayout) is an error.

type Point added in v0.1.67

type Point struct{ X, Y float64 }

Point is a point of a line of handwriting, x to the right and y downwards.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL