Testing Lightweight Models on Complex Frontend Code: Constructing a Regular Heptagon with a Marked Ruler

    This article describes a test for evaluating how lightweight models handle complex frontend code. The task asks for a web page that animates the construction of a regular heptagon with a marked ruler and exports the animation as a GIF. It explains how to split the task into geometric, timing, and third-party library requirements, and covers numerical modeling, trace control, export risks, a scoring rubric, and common failure cases.

    1. Why Standard Test Prompts Are Not Enough

    Login forms, styled buttons, and simple animations can be completed in one attempt by most models. Their scores differ little, so they do not reflect how models perform on complex logic. To test real capability, a test should include at least three types of requirements:

    1. Geometric or mathematical constraints: the model must translate a theorem into numerical conditions in code.
    2. State and timing control: the animation path, the trace range, and the order of events must all be correct.
    3. External capability calls: for example, using a third-party library to export a file and handling the asynchronous result.

    A task that meets all three requirements is more likely to reveal differences in reasoning and engineering detail between models. The example below, “constructing a regular heptagon with a marked ruler and exporting it as a GIF,” shows how to break such a task into items that can be checked one by one.

    2. Task and Conventions

    The task asks for a web page that dynamically demonstrates how to construct a regular heptagon with a marked ruler, and exports the animation as a GIF.

    The original figure does not give the distance between the two marks on the ruler. This article assumes that the mark spacing a equals the side length of the square, so a = 1. With this value, the root of the equation in Section 4 is exactly 3π/7, which can be checked against the analytic expression. This makes it suitable as a reference answer for evaluation.

    The following letters are used throughout. Square DEFG has D at the bottom left, E at the bottom right, F at the top right, and G at the top left. The coordinates are D=(0,0), E=(1,0), F=(1,1), and G=(0,1). The perpendicular bisector of base DE is the line x=0.5.

    3. Steps and Checkpoints

    Each step should produce a result that can be verified directly.

    1. Draw square DEFG and the perpendicular bisector of base DE. Checkpoint: the bisector is the vertical line x=0.5 and passes through the midpoint of DE, (0.5, 0).
    2. Draw circle E, centered at E, with a radius equal to the length of diagonal EG. Checkpoint: the radius is √2, and circle E passes through G=(0,1).
    3. Place one end of the marked ruler against D and rotate it around D. The first mark M1 lies on circle E. The second mark M2 lies on the perpendicular bisector, and the distance between M1 and M2 equals a. Checkpoint: |M1−E| = √2, the x-coordinate of M2 is 0.5, and |M1−M2| = 1.
    4. Draw the line segment through D and M2, and draw the circumscribed circle of the regular heptagon. The circumcenter O is the intersection of the perpendicular bisector with the perpendicular bisector of segment DM2. Checkpoint: |OD| = |OM2|. Then, using radius 1 on circle O, take chords in succession to get each vertex. The point obtained from the fourth chord should coincide with M2.
    5. Keep only the segments and arcs needed for the final construction, and export the GIF file. Checkpoint: the file can be downloaded and played frame by frame in an image viewer.

    4. Numerical Modeling of the Geometric Constraints

    Let θ be the angle between the marked ruler and the horizontal axis, and let u = (cosθ, sinθ) be the unit direction vector.

    The first mark M1 = D + t·u satisfies |M1−E|² = 2. Expanding gives t² − 2t·cosθ − 1 = 0. Take the positive root:

    t(θ) = cosθ + √(cos²θ + 1)

    The second mark M2 lies at distance a beyond M1, so M2 = (t + a)·u. Setting its x-coordinate to 0.5 gives the equation to solve:

    f(θ) = (t(θ) + a)·cosθ − 0.5 = 0

    On (0, π/2), f changes sign only once. With a = 1, the root is θ = 3π/7 ≈ 77.14°. At this angle, t ≈ 1.24698, which equals 2cos(2π/7). This gives:

    • M1 ≈ (0.27748, 1.21563)
    • M2 ≈ (0.5, 2.19064)

    The implementation is as follows.

    1. const a = 1; // Mark spacing, equal to the side length of the square
    2. const t = (theta) => {
    3. const c = Math.cos(theta);
    4. return c + Math.sqrt(c * c + 1);
    5. };
    6. const f = (theta) => (t(theta) + a) * Math.cos(theta) - 0.5;
    7. function bisect(lo, hi, eps = 1e-12) {
    8. let flo = f(lo);
    9. for (let i = 0; i < 200 && hi - lo > eps; i++) {
    10. const mid = (lo + hi) / 2;
    11. const fm = f(mid);
    12. if (Math.sign(fm) === Math.sign(flo)) {
    13. lo = mid;
    14. flo = fm;
    15. } else {
    16. hi = mid;
    17. }
    18. }
    19. return (lo + hi) / 2;
    20. }
    21. function findRoots(n = 1000) {
    22. const roots = [];
    23. for (let i = 0; i < n; i++) {
    24. const lo = (i / n) * (Math.PI / 2);
    25. const hi = ((i + 1) / n) * (Math.PI / 2);
    26. if (Math.sign(f(lo)) !== Math.sign(f(hi))) {
    27. roots.push(bisect(lo, hi));
    28. }
    29. }
    30. return roots;
    31. }
    32. const theta = findRoots()[0];
    33. const M1 = [t(theta) * Math.cos(theta), t(theta) * Math.sin(theta)];
    34. const M2 = [(t(theta) + a) * Math.cos(theta), (t(theta) + a) * Math.sin(theta)];
    35. // Verify: all three geometric conditions must hold
    36. console.assert(Math.abs(M2[0] - 0.5) < 1e-9);
    37. console.assert(Math.abs(Math.hypot(M1[0] - 1, M1[1]) - Math.SQRT2) < 1e-9);
    38. console.assert(Math.abs(Math.hypot(M2[0] - M1[0], M2[1] - M1[1]) - a) < 1e-9);

    Without these three assertions, the geometry in model-generated code may be wrong even when the animation looks normal. For example, if a is set to 0.5, the solver still returns a root and M2 still falls on the perpendicular bisector. The later vertex check, however, fails.

    5. Full Construction from the Ruler to the Regular Heptagon

    The M2 obtained in the previous section is exactly one vertex of the regular heptagon. Take a regular heptagon with side length 1. Let D and E be two adjacent vertices, labeled V0 = D and V1 = E, and number the remaining vertices counterclockwise. Because DE is a side, M2 lies on the perpendicular bisector. M2 must therefore be the vertex V4, opposite DE.

    The circumradius is R = 1/(2sin(π/7)) ≈ 1.15238, and the center is O = (0.5, R·cos(π/7)) ≈ (0.5, 1.03826). The vertex coordinates are as follows.

    Vertex Coordinates
    V0 = D (0, 0)
    V1 = E (1, 0)
    V2 (1.62349, 0.78186)
    V3 (1.40097, 1.75668)
    V4 = M2 (0.5, 2.19064)
    V5 (−0.40097, 1.75668)
    V6 (−0.62349, 0.78186)

    Vertices are generated by polar angle. The polar angle of V4 is 90°, and adjacent vertices differ by 2π/7, or 360/7 ≈ 51.43°.

    1. const R = 1 / (2 * Math.sin(Math.PI / 7));
    2. const O = [0.5, R * Math.cos(Math.PI / 7)];
    3. const vertex = (k) => {
    4. const phi = Math.PI / 2 + (k - 4) * (2 * Math.PI / 7);
    5. return [O[0] + R * Math.cos(phi), O[1] + R * Math.sin(phi)];
    6. };
    7. const V = [0, 1, 2, 3, 4, 5, 6].map(vertex);
    8. const dist = (p, q) => Math.hypot(p[0] - q[0], p[1] - q[1]);
    9. // Equal side lengths, closed polygon, and V4 coincides with M2
    10. for (let k = 0; k < 7; k++) {
    11. console.assert(Math.abs(dist(V[k], vertex(k + 1)) - 1) < 1e-6);
    12. }
    13. console.assert(dist(vertex(7), V[0]) < 1e-6);
    14. console.assert(dist(V[4], M2) < 1e-6);

    These checks confirm three things. The seven sides all have length 1, so the vertices form a regular heptagon. The seventh vertex returns to the starting point, so the closure error is negligible. V4 coincides with M2 from the ruler construction, so the geometric construction and the numerical solution agree. If the output contains only M1 and M2 and not the full set of vertices, it does not prove that the regular heptagon was constructed.

    6. Trace Control

    The canvas redraws every frame, so the two types of elements must be clearly separated.

    • Static traces: stored in the array traces and appended only when a construction step is completed. Each record is a segment or an arc, for example {type: 'segment', p1, p2} or {type: 'arc', c, r, a0, a1}.
    • Dynamic elements: such as the current marked ruler, compass, and mark points. They are recalculated and drawn each frame from the current θ, and they are not written to traces.

    The timing of each append must be written into the code, not estimated from the number of animation frames. For example, append the perpendicular bisector when step 1 is completed, append the arc of circle E when step 2 is completed, and append the seven sides and the circumscribed circle of the heptagon when step 4 is completed. When the animation ends, the contents of traces must match the final construction exactly. During frame-by-frame checks, look for segments in traces that depend on the current θ. If any appear, dynamic elements were written into traces by mistake.

    7. GIF Export: Implementation Points and Risks

    The front end has no native API for converting DOM animation into a GIF. A common approach is to use a library such as gif.js, which captures canvas content frame by frame and then encodes it. The points below apply to gif.js 0.2.0.

    Same-origin Worker. gif.js encodes frames in a Web Worker, and gif.worker.js must be served from the same origin as the page. With a relative path, a page deployed under a subpath may request the wrong address. When the path is wrong, encoding usually fails, and the error appears only in the console.

    Cross-origin taint. After a cross-origin image is drawn onto a canvas, calling getImageData or toDataURL throws a security error. This task uses only pure drawing and no external images, so it does not trigger the problem. If external assets are added later, check the CORS response headers of those images first.

    Memory usage. Uncompressed RGBA frames take width × height × 4 bytes each. The table counts only frame buffers and excludes encoder internal state, so actual memory use is higher.

    Resolution Frames Uncompressed frame buffer
    800×800 300 About 768 MB
    600×600 180 About 259 MB
    480×480 120 About 111 MB
    400×400 90 About 58 MB

    Memory limits differ widely across devices and browsers. This article uses 100 MB as a conservative budget for mobile devices. Within this budget, keep the resolution at or below 480×480 and limit the frame count to 120 or fewer.

    To reduce memory use, take the following steps. First, after each addFrame call, release the reference to that frame’s data. Do not store all the ImageData objects in an array. Second, lower the frame rate where appropriate, or remove repeated still frames. Third, increase the quality parameter to reduce the computation needed for color quantization.

    1. const gif = new GIF({
    2. workers: 2,
    3. quality: 10,
    4. width: 480,
    5. height: 480,
    6. workerScript: '/static/gif.worker.js', // Absolute path, same origin as the page
    7. });
    8. const timer = setTimeout(() => {
    9. fail(new Error('GIF encoding timed out. Lower the resolution or frame count.'));
    10. }, 60000);
    11. gif.on('finished', (blob) => {
    12. clearTimeout(timer);
    13. save(blob);
    14. });

    Errors inside the gif.js 0.2.0 Worker do not always propagate to the page, so a timeout is needed as a fallback. Before exporting, you can also use fetch to check whether workerScript is accessible. If the response is not 2xx, show the user a message immediately.

    Fallback options. When the device runs out of memory or GIF encoding fails, two alternative export methods are available. The first saves each frame as a PNG and packages the frames into a zip file for download. Users can then combine them into an animated image with other tools. The second records canvas.captureStream() with MediaRecorder and exports a WebM file. MediaRecorder is available in most desktop browsers, but its output is not a GIF, so the interface must state this.

    8. Reproducible Evaluation Conditions

    So that results from different models can be compared, the evaluation should fix the following conditions.

    • Prompt: use the original task statement from before Section 4, without adding hints about the drawing method.
    • Environment: the latest stable version of Chrome or Edge, gif.js 0.2.0, a canvas of 800×800 on desktop, and a simulated 480×480 canvas on mobile.
    • Sampling: use each model’s default sampling parameters and record them. Run each model three times and take the median.
    • Judging: a script runs the assertions in Sections 4 and 5. A person only checks the GIF playback.
    Check item Points Pass criteria
    Geometric parameters 15 θ is within (0, π/2), \ M1−E\ = √2, the x-coordinate of M2 is 0.5, and \ M1−M2\ = a
    Construction order 15 The five steps are followed in order, with the perpendicular bisector, circle E, and the marked ruler in the correct sequence
    Vertex generation 20 Errors in all seven side lengths are less than 1e-6, the closure error is less than 1e-6, and V4 coincides with M2
    Trace control 15 traces contains only static segments and arcs, and no dynamic elements appear frame by frame
    GIF export 20 The file can be downloaded, plays correctly frame by frame, and matches the set size and frame count
    Error handling 15 A message is shown when the Worker path is wrong or a timeout occurs, with no silent failure

    The pass criteria are a total score of at least 80, with full marks for both “Geometric parameters” and “Vertex generation.” If either of these two items falls short of full marks, the model is judged to have not completed the regular heptagon construction.

    9. Common Failure Cases

    The following situations often appear in actual evaluations.

    1. The mark spacing is chosen incorrectly. The solver returns a root that does not correspond to a regular heptagon, yet M2 still falls on the perpendicular bisector. The vertex check exposes this error.
    2. Dynamic segments of the marked ruler are written into traces, so several slanted lines remain on screen after the animation ends.
    3. Only M1 and M2 are computed, without the full set of vertices, so the animation stops at two points.
    4. The Worker path is written as a relative path. After deployment in a subdirectory, the request returns 404, the console shows an error, and the page shows no message.
    5. Export parameters of 800×800 and 300 frames are hard-coded. On mobile devices, this causes the page to freeze or the tab to crash.

    Each failure can be located with the assertions or checks above. During evaluation, record the failure type as well as the total score. This shows which kinds of engineering detail each model struggles with.