Coded lens
A camera lens designed and ray-traced in code: focal length, spot size and aberrations versus targets, with ray-trace plots as goldens.
This is a CAD spec on Spekkr, published by onyx. It is listed with the other specs. Paste the line to an agent that can open a web address, and the agent fetches the files and builds from them.
- Spec
onyx/coded-lens- Version
- 0.2.0
- Published by
- onyx
- Updated
- 15 Nov 2026
Build this spec
Build the spec at https://spekkr.com/onyx/coded-lens/start.md.
Paste this to your AI agent. It opens the address, fetches the spec's files, records your choices and builds from them. Nothing to install, no account.
Published by onyx.
What does the result look like?
What can I customize?
Your choices go into the line you copy. Anything else is yours to edit, but it leaves the tested path.
What do I get?
-
spec.mdRequirements and acceptance checks.Coded lens
What this builds
A small camera lens, designed in code: a few elements, a stop, an image plane. A ray tracer (a shipped one, or an open library) reports focal length, an on-axis and an off-axis spot size, and a simple aberration or ray-fan metric, against documented targets. Ray-trace plots are committed as goldens. No glass is melted, and no bench is required. This is an original prescription, not a commercial lens's exact data presented as a product.
Read
spekkr.inputs.jsonfirst.focalandapertureare design targets.formatis the image diagonal.aspheresandcoatingschange what the design may use.tracerchooses the engine.Out of scope
- A lab bench, a real glass melt, or a commercial lens prescription copied as the product.
- A camera body in the checks.
- A network licence server for a CAD package.
Requirements
Each requirement has an id. Checks name the id they cover.
R1. Metrics
- The effective focal length is
focalwithin 2%. The on-axis RMS spot size at the image plane, at the design wavelength, is under the bound indesign.md(for example 15 µm at F/2.8, 50 mm, as in the file). - An off-axis field (0.7 of the image circle) has a spot size under its own bound. A ray-fan or Seidel-style figure is within the table in the file.
- The prescription (radii, thicknesses, glasses or index values) is in a file the tests read back.
Accept when: focal length, both spot sizes, and the aberration figure match the bounds, and the prescription round-trips.
R2. Plots and files
- Goldens: a layout (elements and rays), an on-axis spot, an off-axis spot, and a ray-fan plot, compared with a documented tolerance on plots.
- One command traces, measures, and writes the plots. No bench, no glass, no camera.
Accept when: the command passes for both tracers if the external one is present (otherwise shipped only), and a deliberately defocused fixture fails the on-axis bound.
R3. Inputs
- Numeric inputs are read from
spekkr.inputs.jsonand must stay inside the ranges in the Inputs table indesign.md. - A value outside a range is refused before modelling, with a message that names the key.
- Options add or remove the features in that table. The
toolswap selects CadQuery or OpenSCAD; both must meet the same numbers.
Accept when: default and one out-of-range value are handled as above, and a second legal input set still matches the formulas in
design.md.R4. Checks and report
- One command builds the model at the defaults and at the person's inputs, measures it against
design.md, and writes a short report. - A model broken on purpose, for example a wall thinner than
wall, must fail the report. - The command exports the files this spec asks for (STL, and STEP when the tool can). No physical print is required.
Accept when: the report says pass at the defaults and at the person's inputs, and fail on a deliberately broken model.
Verification
Focal length, image-plane spot size, and an aberration metric are compared to documented targets. Ray-trace plots are checked as goldens. No optical bench and no physical glass are required.
Definition of done
- Every acceptance check above runs from one command, and all pass at the person's inputs.
- A README says how to run the tracer, how the targets are listed, and that a bench is not a check.
# Coded lens ## What this builds A small camera lens, designed in code: a few elements, a stop, an image plane. A ray tracer (a shipped one, or an open library) reports focal length, an on-axis and an off-axis spot size, and a simple aberration or ray-fan metric, against documented targets. Ray-trace plots are committed as goldens. No glass is melted, and no bench is required. This is an original prescription, not a commercial lens's exact data presented as a product. Read `spekkr.inputs.json` first. `focal` and `aperture` are design targets. `format` is the image diagonal. `aspheres` and `coatings` change what the design may use. `tracer` chooses the engine. ## Out of scope - A lab bench, a real glass melt, or a commercial lens prescription copied as the product. - A camera body in the checks. - A network licence server for a CAD package. ## Requirements Each requirement has an id. Checks name the id they cover. ### R1. Metrics - The effective focal length is `focal` within 2%. The on-axis RMS spot size at the image plane, at the design wavelength, is under the bound in `design.md` (for example 15 µm at F/2.8, 50 mm, as in the file). - An off-axis field (0.7 of the image circle) has a spot size under its own bound. A ray-fan or Seidel-style figure is within the table in the file. - The prescription (radii, thicknesses, glasses or index values) is in a file the tests read back. Accept when: focal length, both spot sizes, and the aberration figure match the bounds, and the prescription round-trips. ### R2. Plots and files - Goldens: a layout (elements and rays), an on-axis spot, an off-axis spot, and a ray-fan plot, compared with a documented tolerance on plots. - One command traces, measures, and writes the plots. No bench, no glass, no camera. Accept when: the command passes for both tracers if the external one is present (otherwise shipped only), and a deliberately defocused fixture fails the on-axis bound. ### R3. Inputs - Numeric inputs are read from `spekkr.inputs.json` and must stay inside the ranges in the Inputs table in `design.md`. - A value outside a range is refused before modelling, with a message that names the key. - Options add or remove the features in that table. The `tool` swap selects CadQuery or OpenSCAD; both must meet the same numbers. Accept when: default and one out-of-range value are handled as above, and a second legal input set still matches the formulas in `design.md`. ### R4. Checks and report - One command builds the model at the defaults and at the person's inputs, measures it against `design.md`, and writes a short report. - A model broken on purpose, for example a wall thinner than `wall`, must fail the report. - The command exports the files this spec asks for (STL, and STEP when the tool can). No physical print is required. Accept when: the report says pass at the defaults and at the person's inputs, and fail on a deliberately broken model. ## Verification Focal length, image-plane spot size, and an aberration metric are compared to documented targets. Ray-trace plots are checked as goldens. No optical bench and no physical glass are required. ## Definition of done - Every acceptance check above runs from one command, and all pass at the person's inputs. - A README says how to run the tracer, how the targets are listed, and that a bench is not a check.
-
design.mdFocal-length and spot-size targets, the prescription file, and ray-trace plot goldens.Design
This file fixes the geometry. How the model's code is organised is up to you, as long as the numbers here hold.
Targets (defaults)
Focal 50 mm ± 2%. On-axis RMS spot ≤ 15 µm. 0.7-field RMS spot ≤ 40 µm. The exact bounds and the wavelength (for example 587 nm) are
fixtures/lens-targets.json.Prescription
Element count, radii, thicknesses, and index (or a glass name from a shipped table) are
fixtures/lens-prescription.jsonafter a design run, or a shipped starting point that already meets the bounds.Plot tolerance
A pixel tolerance of 8 levels, 98% of pixels, or a numeric plot array within 1e-3 of a fixture, as the tests prefer.
Inputs
Key Label Default Notes focalTarget focal length, mm 50 From 24 to 85, the design target. apertureF-number 2.8 From 1.8 to 8. formatImage circle, mm 43.3 The diagonal of the image plane, default a 35 mm still frame. coatingsSimple coatings off A transmission factor in the tracer, not a physical lab coating. aspheresAllow an asphere on If off, all surfaces are spherical or planar. tracerTracer shipped shipped is a small tracer in the project. external is a named open library, if present. Acceptance at the defaults
Millimetres and a unit-focal tracing. Default aperture 25, focal length 50, two elements, aspheres on, coatings off.
Quantity Value Tolerance Source Clear aperture 25.00 0.05 Of the first surface Focal length, on axis 50.00 0.20 At the design wavelength 550 nm On-axis spot radius 0.050 0.010 RMS at the focal plane, 550 nm Field, half-angle 5 deg — The off-axis check Aspheric term 4th order only — When aspheresis onA ray tracer in the repo (Python is fine) traces a documented 21-ray pencil on axis and a 21-ray pencil at 5 degrees. The prescription is a table in this file or a shipped
fixtures/lens-prescription.csv. No lab coating or optical bench is required.Screenshots
These pictures are headless OpenSCAD renders of the reference model in
reference/model.scad, at the default inputs. They are not drawings of a product that has not been modelled. The first picture is the one Spekkr shows on the spec's card. A build may ship its own goldens; those goldens are of that build and do not have to match these frames pixel-for-pixel.File What it shows shots/cell.pngTwo-element cell 25 mm aperture, 50 mm focal length How to verify
- Build the model at the default inputs and at two other legal input sets.
- Measure every row of the acceptance table in this file; each must fall inside its tolerance. Use the solid itself or a mesh library on the exported STL, as
design.mdsays for the chosen tool. - Refuse at least one out-of-range input by name before modelling.
- Confirm each exported part is a manifold, watertight mesh, and that walls and print orientation hold where this file asks.
- Focal length, image-plane spot size, and an aberration metric are compared to documented targets. Ray-trace plots are checked as goldens. No optical bench and no physical glass are required.
# Design This file fixes the geometry. How the model's code is organised is up to you, as long as the numbers here hold. ## Targets (defaults) Focal 50 mm ± 2%. On-axis RMS spot ≤ 15 µm. 0.7-field RMS spot ≤ 40 µm. The exact bounds and the wavelength (for example 587 nm) are `fixtures/lens-targets.json`. ## Prescription Element count, radii, thicknesses, and index (or a glass name from a shipped table) are `fixtures/lens-prescription.json` after a design run, or a shipped starting point that already meets the bounds. ## Plot tolerance A pixel tolerance of 8 levels, 98% of pixels, or a numeric plot array within 1e-3 of a fixture, as the tests prefer. ## Inputs | Key | Label | Default | Notes | | --- | --- | --- | --- | | `focal` | Target focal length, mm | 50 | From 24 to 85, the design target. | | `aperture` | F-number | 2.8 | From 1.8 to 8. | | `format` | Image circle, mm | 43.3 | The diagonal of the image plane, default a 35 mm still frame. | | `coatings` | Simple coatings | off | A transmission factor in the tracer, not a physical lab coating. | | `aspheres` | Allow an asphere | on | If off, all surfaces are spherical or planar. | | `tracer` | Tracer | shipped | shipped is a small tracer in the project. external is a named open library, if present. | ## Acceptance at the defaults Millimetres and a unit-focal tracing. Default aperture 25, focal length 50, two elements, aspheres on, coatings off. | Quantity | Value | Tolerance | Source | | --- | --- | --- | --- | | Clear aperture | 25.00 | 0.05 | Of the first surface | | Focal length, on axis | 50.00 | 0.20 | At the design wavelength 550 nm | | On-axis spot radius | 0.050 | 0.010 | RMS at the focal plane, 550 nm | | Field, half-angle | 5 deg | — | The off-axis check | | Aspheric term | 4th order only | — | When `aspheres` is on | A ray tracer in the repo (Python is fine) traces a documented 21-ray pencil on axis and a 21-ray pencil at 5 degrees. The prescription is a table in this file or a shipped `fixtures/lens-prescription.csv`. No lab coating or optical bench is required. ## Screenshots These pictures are headless OpenSCAD renders of the reference model in `reference/model.scad`, at the default inputs. They are not drawings of a product that has not been modelled. The first picture is the one Spekkr shows on the spec's card. A build may ship its own goldens; those goldens are of that build and do not have to match these frames pixel-for-pixel. | File | What it shows | | --- | --- | | `shots/cell.png` | Two-element cell 25 mm aperture, 50 mm focal length | ## How to verify 1. Build the model at the default inputs and at two other legal input sets. 2. Measure every row of the acceptance table in this file; each must fall inside its tolerance. Use the solid itself or a mesh library on the exported STL, as `design.md` says for the chosen tool. 3. Refuse at least one out-of-range input by name before modelling. 4. Confirm each exported part is a manifold, watertight mesh, and that walls and print orientation hold where this file asks. 5. Focal length, image-plane spot size, and an aberration metric are compared to documented targets. Ray-trace plots are checked as goldens. No optical bench and no physical glass are required.
-
tasks.mdBuild tasks in order, each with a check.Tasks
Work in order. Finish a task's check before starting the next.
- Set up. Install the tool in the
toolinput (CadQuery or OpenSCAD) and a mesh library for the checks. Readspekkr.inputs.jsoninto one place at the top of the model. Check: an empty or trivial model is written and read back, and the inputs are visible in that source. - Metrics (R1). Build what
R1. Metricsasks for, to the numbers indesign.md. In particular: The effective focal length isfocalwithin 2%. The on-axis RMS spot size at the image plane, at the design wavelength, is under the bound indesign.md(for example 15 µm at F/2.8, 50 mm, as in the file). Check: theR1. Metricsacceptance checks pass. - Plots and files (R2). Build what
R2. Plots and filesasks for, to the numbers indesign.md. In particular: Goldens: a layout (elements and rays), an on-axis spot, an off-axis spot, and a ray-fan plot, compared with a documented tolerance on plots. Check: theR2. Plots and filesacceptance checks pass. - Inputs (R3). Build what
R3. Inputsasks for, to the numbers indesign.md. In particular: Numeric inputs are read fromspekkr.inputs.jsonand must stay inside the ranges in the Inputs table indesign.md. Check: theR3. Inputsacceptance checks pass. - Checks and report (R4). Build what
R4. Checks and reportasks for, to the numbers indesign.md. In particular: One command builds the model at the defaults and at the person's inputs, measures it againstdesign.md, and writes a short report. Check: theR4. Checks and reportacceptance checks pass. - Goldens and the report. Render the documented views of the default model. Run the one-command report at the defaults, at the person's inputs, and at one more legal set. Check: the report says pass throughout, and the rendered views are written next to the model.
- Finish. Write a README that says how to install what is needed, how to change the inputs, and how to run the checks. Run the one command from a clean folder. Check: every item under Definition of done in
spec.mdis true.
# Tasks Work in order. Finish a task's check before starting the next. 1. **Set up.** Install the tool in the `tool` input (CadQuery or OpenSCAD) and a mesh library for the checks. Read `spekkr.inputs.json` into one place at the top of the model. Check: an empty or trivial model is written and read back, and the inputs are visible in that source. 2. **Metrics (R1).** Build what `R1. Metrics` asks for, to the numbers in `design.md`. In particular: The effective focal length is `focal` within 2%. The on-axis RMS spot size at the image plane, at the design wavelength, is under the bound in `design.md` (for example 15 µm at F/2.8, 50 mm, as in the file). Check: the `R1. Metrics` acceptance checks pass. 3. **Plots and files (R2).** Build what `R2. Plots and files` asks for, to the numbers in `design.md`. In particular: Goldens: a layout (elements and rays), an on-axis spot, an off-axis spot, and a ray-fan plot, compared with a documented tolerance on plots. Check: the `R2. Plots and files` acceptance checks pass. 4. **Inputs (R3).** Build what `R3. Inputs` asks for, to the numbers in `design.md`. In particular: Numeric inputs are read from `spekkr.inputs.json` and must stay inside the ranges in the Inputs table in `design.md`. Check: the `R3. Inputs` acceptance checks pass. 5. **Checks and report (R4).** Build what `R4. Checks and report` asks for, to the numbers in `design.md`. In particular: One command builds the model at the defaults and at the person's inputs, measures it against `design.md`, and writes a short report. Check: the `R4. Checks and report` acceptance checks pass. 6. **Goldens and the report.** Render the documented views of the default model. Run the one-command report at the defaults, at the person's inputs, and at one more legal set. Check: the report says pass throughout, and the rendered views are written next to the model. 7. **Finish.** Write a README that says how to install what is needed, how to change the inputs, and how to run the checks. Run the one command from a clean folder. Check: every item under Definition of done in `spec.md` is true.
- Set up. Install the tool in the
-
reference/model.scadA parametric OpenSCAD reference of the default model, used to make the listing pictures. A build may use CadQuery or OpenSCAD and does not have to start from this file. -
shots/hero.pngStudio hero of the default model. -
shots/detail.pngCloser studio still of a joint, pocket, or surface.
Is it for me?
- Kind
- CAD
- Tools
- Python
What does it need?
- Agent permissions
- shell
- Commands it runs
install a Python optics or ray-trace library, or a small shipped tracerinstall a tool that compares plots
What changed?
- 0.2.015 Nov 2026Studio product shots from a shared Cycles rig (cyclorama, PLA materials), including a short loop when present.
- 0.1.014 Nov 2026First version.
For agents: start.md says how to build this spec, spec.json holds everything on this page, and bundle.tar.gz holds its files.