Testing Lightweight LLMs with Geometric Animation: A Frontend Generation and Validation Approach

    This article explains how to use a neusis (two-marked ruler) construction of a regular heptagon as a test task for evaluating LLM frontend code generation. It covers why geometric construction is a good benchmark, how to define a reproducible test prompt and acceptance criteria, how to record results rigorously, and three engineering practices—prompt decomposition, log-driven feedback loops, and preloaded domain knowledge—along with risks and limitations of this testing method.

    Why Use Geometric Construction to Test Code Generation

    Most LLMs can produce routine UI code such as buttons, forms, and lists. To reveal a model’s capability boundaries, you need a task that simultaneously involves mathematical derivation, state management, and graphics rendering. Constructing a regular heptagon with a neusis (a two-marked ruler) fits this requirement. The neusis is a non-standard construction tool whose constraints cannot be copied directly from ordinary straightedge-and-compass rules. The model must first translate the textual description into coordinates and equations before it can write correct animation code.

    This article focuses on three questions: Can the model correctly understand the tool constraints? Can the generated code run in the browser as required? When errors occur, can developers quickly locate the cause?

    The Full Test Task Description

    The original test prompt reads as follows:

    1. Create an HTML page that animates the construction of a regular heptagon using a neusis.
    2. Step constraints: Start with a square and draw the perpendicular bisector of its bottom edge. Then, with the bottom-right vertex E as the center, draw circle E with a radius equal to the square’s diagonal.
    3. Dynamic interaction: Using the “two-marked ruler,” keep the ruler pressed against the bottom-left vertex D so that the first mark moves along circle E until the second mark passes through the perpendicular bisector of the bottom edge.
    4. Logic completion: Fill in all omitted straightedge-and-compass construction steps. Retain trace marks only where necessary.
    5. Extended feature: Add a GIF export function.

    Several decisions in this description are left to the model: the side length of the square, the position of the coordinate origin, the animation frame rate and duration, and how to determine which traces are “necessary.” These unspecified parameters directly affect whether the result is “correct,” so they should be fixed before testing.

    To make outputs from different models comparable, testers should agree on the following in advance:

    • Coordinate system: Set the square’s side length to 1, with bottom-left vertex D at the origin (0,0), the bottom edge on the x-axis, vertex E at (1,0), the top-right vertex at (1,1), and the top-left vertex at (0,1).
    • Circle E: Center (1,0), radius equal to the diagonal length √2.
    • Animation states: At minimum, include four states—“initial,” “moving,” “second mark crossing the perpendicular bisector,” and “complete”—each of which should be traceable to a corresponding variable in the code.
    • Acceptance method: Use a script to read the point coordinates recorded on the page and check the distance error between marked points and circle E, with a suggested tolerance of 1e-6. Verify that the second mark passes through the perpendicular bisector x=0.5. Check whether the number of trace elements matches the definition of “necessary traces.”

    These checks can be written as automated tests, avoiding reliance on visual judgment of whether the animation merely “looks right.”

    How to Record Test Results and Current Limitations

    In one test, a lightweight model took a long time to generate output, with extended periods of reasoning and no text output during inference. The code it eventually produced was largely consistent with the geometric logic required by the task. Another, larger model generated output faster, but after browser rendering, some point trajectories deviated from circle E, and the correspondence between marks and coordinates was misaligned.

    These observations can only serve as directional reference. This article does not disclose specific model names, versions, runtime environments, or complete conversation logs, so readers cannot independently reproduce these conclusions. The timing data also lacks measurement details—for example, whether queueing time was included or whether the same network conditions were used. Future evaluation reports should record at least the following fields: model name and version, call parameters, runtime environment (browser version, operating system), dependency library versions, start and end points of timing measurements, the hash of the generated code, and the pass/fail status of each acceptance criterion.

    Three Dimensions of Capability Assessment

    Instruction following. Whether the model strictly obeys constraints such as “leave traces only where necessary” can be checked via the number of trace elements and when they are drawn.

    Mathematical modeling. Whether the model can translate descriptions like “neusis” and “perpendicular bisector” into algebraic equations can be verified through the distance error of points on the circle and the coordinates of line intersections.

    Long-output stability. Whether long code contains inconsistent variable names, undefined functions, or syntax errors can be assessed by running static checks and inspecting the browser console after generation, and by counting where errors occur.

    Engineering Practice 1: Decompose the Prompt and Validate Step by Step

    For complex tasks, it is not advisable to ask the model to output a complete program in one pass. A more robust approach is to split the task into four stages: first, set up the coordinate system and render the static figure; second, implement the rendering of circle E and the square; third, design the animation state machine; and finally, integrate GIF export. After each stage, run the corresponding acceptance checks and proceed to the next stage only after they pass.

    Engineering Practice 2: Log-Driven Feedback Loop

    Deploy the generated code to an isolated sandbox page, collect runtime errors, and feed the error information back to the model as context for repair. Recommended log fields include: timestamp, prompt version, model version, error type, error message and stack trace, browser and OS information, and code hash. Logs should contain only the information needed for debugging—do not record users’ personal data or access credentials. The sandbox page should be blocked from accessing external networks to prevent generated code from calling unknown resources.

    Engineering Practice 3: Preload a Domain Knowledge Base

    Models’ understanding of unconventional tools like the neusis is often unstable. You can attach a knowledge entry to the prompt, for example:

    Name: Neusis (two-marked ruler)
    Definition: A straightedge with two marks. When moving the ruler, the first mark must lie on a specified circle, and the second mark must pass through a specified line or point.
    Constraints for this task: The first mark moves along circle E, the ruler always passes through point D, and the intersection of the second mark with the perpendicular bisector must be recorded.
    Numerical check: The difference between the marked point’s distance to center E and the radius must not exceed 1e-6.

    Preloaded knowledge reduces the burden of deriving everything from scratch, but it does not guarantee correctness—acceptance tests remain essential.

    Risks and Applicability Boundaries

    Before using the GIF export feature, verify the open-source license of the chosen library to confirm it permits use and distribution in your project. GIF encoding runs on the main thread, so a high frame count can cause page jank and heavy memory usage; consider using a Web Worker or limiting the number of frames. Canvas and SVG differ across browsers in pixel precision, font rendering, and event handling, so acceptance testing should cover at least two major browsers.

    This test involves only one geometric task, and its conclusions cannot be generalized to all frontend scenarios. The same model may perform differently under different prompts, temperature settings, and run times. When selecting a model, repeat the tests with your own business tasks and keep complete test records.