Documentation
¶
Overview ¶
Package render draws a sheet of handwriting from its strokes, as the board shows it: ink of the board's pen, #111, 3 px wide with round ends and joins, on white, one pixel to a unit of the sheet. It draws the sheet at any moment of the writing: as it was finished, and just before each erasure, the frame of that erasure. One renderer draws every form of the measurement.
The drawing is the same on every machine: it works in whole numbers alone. A point stands at the nearest sixteenth of a pixel, each pixel is sampled at 4 × 4 places, and a pixel takes the ink of the share of its samples the line covers. Floating-point arithmetic may round differently where a compiler fuses its operations, and a picture would then differ from one architecture to another.
It draws a sample that passes its check (sample.Check), on a sheet of at most MaxSide units a side, and refuses any other.
It cuts the crop of a sheet for checking too, by the rule of the eval protocol (crop.go): the work with its margins, scaled so that its digits stand a given height, and drawn by the same whole numbers, in 48ths of a pixel, each stroke black at a line of the crop's own width or in its style, its colour and its width at the crop's scale.
Index ¶
- Constants
- Variables
- func At(s *sample.Sample, t int64) (*image.Gray, error)
- func Before(s *sample.Sample, i int) (*image.Gray, error)
- func Bundles(strokes []sample.Stroke) ([][]int, error)
- func Final(s *sample.Sample) (*image.Gray, error)
- func Heights() []int
- func MedianOf(strokes []sample.Stroke) (float64, error)
- func PNG(img image.Image) ([]byte, error)
- func Shown(s *sample.Sample, t int64) []sample.Stroke
- func ShownBefore(s *sample.Sample, i int) ([]sample.Stroke, error)
- func Tokens(w, h int) int
- type Crop
- type Frame
Constants ¶
const ( // CropMargin is the least margin around the work, px: a wide line of a style widens it to hold // half the line and the pixel at its edge. CropMargin = 12 // CropSide is the least width and height of a crop, px: Claude may err on images under 200 // pixels. CropSide = 200 // Digit is the height of a digit a crop is drawn at unless the module's manifest names another, // px. Digit = 32 // MaxDigit is the tallest digit a crop takes, px: its ink then still stays within the margin. MaxDigit = 256 )
The crop of a sheet for checking is cut by the rule of the eval protocol, canvas's as it is. Its numbers are canvas's to the bit: the bundles of the strokes, the median height h_med, the height D′ the digits are drawn at, the size, the margins, where the crop lies on the sheet and the frames of the groups. They are whole numbers, in tenths of a unit for places, and each one that is not whole is one division of two of them, which IEEE 754 rounds alike in Go and in JavaScript. Its pixels are this renderer's, in whole numbers as the board's are; canvas's raster may draw them a level of a channel apart, as canvas's vectors allow.
const Ink = 0x11
Ink is the grey of the board's pen, #111.
const MaxSide = 2048
MaxSide is the longest side of a sheet the renderer draws, in units of the sheet: up to it, the whole numbers of the drawing fit in 64 bits. The board's sheet is 1000 × 600.
Variables ¶
var ErrNoInk = errors.New("render: the sheet shows no strokes, and a crop is cut around strokes")
ErrNoInk is the error of a crop of no strokes: a sheet that shows none goes to no check.
Functions ¶
func At ¶
At draws the sheet as it stood at the moment t of its clock: the points written by then, without the strokes the erasures made by then took away. What happened at t itself is on it.
func Before ¶
Before draws the sheet just before its erasure i, the frame of that erasure: the strokes written by the erasure's moment, the ones it takes away among them, without those the erasures before it took away. A stroke that begins at the erasure's very moment and that it does not take away is the next stroke, written after it.
func Bundles ¶
Bundles are the bundles of the strokes: the strokes no lower than cropFlat, joined by a chain of boxes that touch or overlap, whenever each was written. Each is the indexes of its strokes in those given, ascending, and they go by their least index.
func Heights ¶
func Heights() []int
Heights are the heights of digits the measurement draws crops at, px; Digit is the main one.
func MedianOf ¶
MedianOf is h_med of the strokes, in units: the height the crop scales to that of a digit.
func Shown ¶
Shown is what the sheet shows at the moment t of its clock, as At draws it: of each stroke no erasure made by then took away, the points written by then; a stroke with none of them is left out. The strokes go in the sample's order.
func ShownBefore ¶
ShownBefore is what the sheet shows just before its erasure i, as Before draws it.
func Tokens ¶
Tokens is what a picture of w × h pixels costs in tokens of a Claude model's input, ⌈w / 28⌉ × ⌈h / 28⌉ (Anthropic's guide Vision), as the model takes it unresized. A picture the model would resize is not charged so: the Claude adapter has the API refuse it (oversized_image: error). The board's sheet, 1000 × 600, costs 792.
Types ¶
type Crop ¶
type Crop struct {
// Digit is the height of a digit asked for, D, and Drawn the height digits are drawn at, D′: D,
// or less if the crop at D would be too large.
Digit, Drawn int
// Median is h_med, the lower median of the heights of the bundles, in units: cropFlat if there
// are none.
Median float64
// Scale is the crop's pixels to a unit of the sheet: D′ over h_med, or over cropCeiling if h_med
// is above it.
Scale float64
// Line is the width of the widest line of the strokes, px: without a style D′ / 12 and 1 at
// least, and of a style its width at the scale, 1 at least.
Line float64
Width, Height int
// Margins are the margins above and to the left of the work, px; below and to the right is what
// is left.
Margins [2]int
// SheetBox is where the crop with its margins lies on the sheet, [ymin, xmin, ymax, xmax], in
// units.
SheetBox [4]float64
// Frames are the frames of the groups, in the order of their labels.
Frames []Frame
// contains filtered or unexported fields
}
Crop is the crop of a sheet for checking, all but its pixels: what lies where, at what scale.
func CropOf ¶
CropOf cuts the crop of the strokes a sheet shows, with its digits digit px high, and the frames of their groups: each stroke in exactly one of them. Groups may be nil, and the crop then has no frames. A sheet that shows no strokes has no crop: ErrNoInk. The width of each stroke's line is its style's, and the margins and the frames hold the widest.
func Cropped ¶
Cropped cuts the crop of the strokes a sheet shows, with its digits digit px high, and draws them: their groups are those lines.Groups finds among them, as a device's are.
func (*Crop) Draw ¶
Draw draws strokes on the crop as the board's renderer draws a sheet, in whole numbers: each point at the nearest 48th of a pixel of the crop, by the crop's own whole numbers, each line with round ends and joins, on white, by the strokes' IDs ascending (drawOrder). A stroke without a style is black and opaque, its line max(D′, 12) / 12 px wide; one of a style is its width at the crop's scale, 1 px at least — a pen's with no pressure and no speed —, its colour at its opacity over what lies under it, and a marker's what lies under it multiplied by its colour, at its opacity. Each stroke is one layer, no darker where it crosses itself. The picture is grey when no stroke has a style, and RGB when one has. The strokes are those the crop was cut around, or others on the same sheet: what falls off the crop is cut off.
func (*Crop) InkBox ¶ added in v0.1.5
InkBox is the box of the points the crop was cut around, in whole tenths of a unit, [ymin, xmin, ymax, xmax]: the ink_box of the eval protocol's set of crops.
func (*Crop) MedianTenths ¶ added in v0.1.5
MedianTenths is h_med in whole tenths of a unit, as it is: the bundle_median of the protocol's set of crops, which the scale takes no higher than cropCeiling.
func (*Crop) PNG ¶ added in v0.1.3
PNG draws strokes on the crop, as Draw does, and encodes the picture as the eval protocol writes a crop's PNG: 8 bits, not interlaced, grey, colour type 0, when no stroke has a style and RGB, colour type 2, when one has, and the chunks IHDR, IDAT and IEND alone — no ancillary chunk, which could hold a text, metadata or a time. Go's encoder writes a grey picture and an opaque RGBA one so, its IDAT in pieces of one zlib stream.