{"slug": "show-hn-pencil-llm-writes-whiteboard-lessons-as-json-a-browser-draws-them", "title": "Show HN: Pencil – LLM writes whiteboard lessons as JSON, a browser draws them", "summary": "A developer released Pencil, an open-source tool that has a large language model write a whiteboard lesson as strict JSON, validates that JSON with a Node script, and plays it back in a single-file browser player that draws SVG figures in sync with narration by word index. The planner defaults to DeepSeek's deepseek-flash model, requires only the Python standard library, and prints token counts and per-lesson cost from user-supplied input and output token prices plus an --inr-per-usd rate of 88; an Anthropic provider path exists but is untested live. The project includes a repair loop that feeds validator issues back to the model, unit tests using a scripted fake model, and headless-Chrome player tests covering playback, quizzes, bad input and XSS safety.", "body_md": "A small open-source take on the \"AI teacher that draws on a whiteboard\" idea: a model writes a lesson as strict JSON, code validates it, and a browser player draws it in time with the narration. Everything here (prompts, schema, player) is original code.\n\n**[Live demo](https://vbs2004.github.io/pencil/)**: a lesson written by DeepSeek, played by the single-file player (press Play, untick \"Silent\" for voice).\n\n``` php\ntopic --> planner.py --(LLM)--> lesson.json --> validator.js --(issues)--> repair loop\n                                                      |\n                                                      v\n                                       player.html (SVG draw-on + speech, cues by word index)\nopen player.html                       # plays the built-in rainbow sample (no server needed)\nnode validator.js samples/rainbow.json # exit 0 = valid; prints issues as JSON otherwise\n\nexport DEEPSEEK_API_KEY=...           # default provider; stdlib only, no pip install needed\npython3 planner.py --topic \"How tides work\" --minutes 4 --out lesson.json \\\n    --price-in <USD per 1M input tokens> --price-out <USD per 1M output tokens> --inr-per-usd 88\n# then open player.html, \"Load a lesson\", pick lesson.json\n# or: python3 -m http.server and open player.html?src=lesson.json&autoplay=1\n\n# Anthropic instead: pip install anthropic; export ANTHROPIC_API_KEY=...; add --provider anthropic\n```\n\n`--model` (or env `LESSON_MODEL`) picks the model; the default is `deepseek-flash`. Prices are\ninputs on purpose: the planner prints tokens and cost per lesson so you can measure your real number.\n`--topic -` reads the topic from stdin; `--research-file` adds reference notes; `--dry-run` prints the prompts.\n\n`beats[]` each hold `narration` plus `ops[]`: `heading`, `paragraph`, `callout`, `definition`,\n`table`, `figure`. A figure is `parts[]` of `marks[]` (`circle`, `ellipse`, `rect`, `line`, `path`,\n`label`). Each part has a `cue`: the index of the narration word at which it is drawn. Paths use\nabsolute commands only. `checks[]` are end-of-lesson multiple-choice questions.\n\n```\npython3 -m unittest test_planner   # repair loop, parsing, cost math (fake LLM, no key needed)\npython3 test_player.py             # headless Chrome: playback, quiz, bad input, XSS safety\npython3 build.py                   # regenerate player.html from player.template.html\n```\n\n- Unit tests use a scripted fake model; live runs have been done with DeepSeek (`deepseek-flash` ). The Anthropic path is untested live.\n- Narration uses the browser's built-in speech synthesis. Swap in an on-device TTS for a consistent voice.\n- The wobble effect is opt-in: the SVG displacement filter can leave small notches in thin strokes.\n- No accounts, storage, uploads, video export or billing.", "url": "https://wpnews.pro/news/show-hn-pencil-llm-writes-whiteboard-lessons-as-json-a-browser-draws-them", "canonical_source": "https://github.com/VBS2004/pencil", "published_at": "2026-11-21 18:33:22+00:00", "updated_at": "2026-11-21 18:43:09.078221+00:00", "lang": "en", "topics": ["ai-tools", "large-language-models", "generative-ai", "developer-tools"], "entities": ["Pencil", "DeepSeek", "deepseek-flash", "Anthropic"], "also_reported_by": [], "takeaway": "Pencil validates LLM-generated lesson JSON with validator.js and loops validator issues back to the model for repair, while the planner prints token counts and cost per lesson from user-supplied per-1M-token prices.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-pencil-llm-writes-whiteboard-lessons-as-json-a-browser-draws-them", "markdown": "https://wpnews.pro/news/show-hn-pencil-llm-writes-whiteboard-lessons-as-json-a-browser-draws-them.md", "text": "https://wpnews.pro/news/show-hn-pencil-llm-writes-whiteboard-lessons-as-json-a-browser-draws-them.txt", "jsonld": "https://wpnews.pro/news/show-hn-pencil-llm-writes-whiteboard-lessons-as-json-a-browser-draws-them.jsonld"}}