Reference · Stroke order from KanjiVG: draw it, and find a kanji by drawing it
findByDrawingfunction
The kanji whose strokes are nearest to what was drawn, nearest first. The strokes are compared one by one, in the order they were drawn, so a kanji has to be drawn with the right number of strokes (one more or fewer is allowed, at a cost) and in the order it is written. The size and the place of the drawing do not matter; the lengths and directions of the strokes do. It reads the table as it is and fetches nothing.
Import it
import { findByDrawing } from "@johnmorrisdotca/jisho/strokes";
Definition
function findByDrawing(table: PackedStrokes, drawn: readonly (readonly Point[])[], options?: { readonly limit?: number; }): DrawingMatch[]
Parameters
| Name | Type | Description |
|---|---|---|
table | PackedStrokes | What |
drawn | readonly (readonly Point[])[] | The strokes, each a list of points in any units (a canvas's pixels, say), in the order they were drawn. A stroke of one point is a dot. |
options (optional) | { readonly limit?: number; } |
|
Returns
DrawingMatch[]
The nearest kanji, with their distances; none for a drawing with no stroke.
Examples
import { findByDrawing, loadAllStrokes } from "@johnmorrisdotca/jisho/strokes";
const drawn = [[[10, 50], [90, 50]]] as const; // one straight line across
console.log(findByDrawing(await loadAllStrokes(), drawn, { limit: 1 })[0]?.kanji); // 一一What it prints (run when this page was built)