sicp.io
2.2.5 · Picture language · transformations and composition

A geometric transform returns another painter.

Transforming a painter changes the frame passed to it, so beside, below, flips, rotations, and splits compose procedures into a finite segment list.

Guiding question

How can a few frame transformations create a language of reusable picture combinations?

  • Transform a painter by constructing a subframe
  • Define beside and below as procedure combinators
  • Express flips and rotations with the same transformation primitive
  • Build a four-part composition without changing the base painter
  • Generate a recursive split whose segment count grows with depth
  • Relate the rendered SVG to the segment transcript from the selected run

transform-painter does not rewrite the painter’s segment data. It maps three unit-square control points through the outer frame and constructs a new subframe. The original painter then runs inside that subframe. beside and below create two transformed painters and append their segment lists, while flips and rotation are just different choices of the three control points.

The first run places four transformed chevrons in a square. The second defines right-split recursively: the left half keeps the original painter while the right half stacks two smaller copies. At depth three, a three-segment base painter produces 45 mapped segments. The visualizer draws exactly the SEG lines produced by Lispex and caps only the browser rendering, not the runtime’s own execution limits.

SICP code4,491 of 1,048,576 UTF-8 bytes
Examples
Result
Output
Value
Diagnostic
Execution trace0 / 0 events
    Programs run in the browser with their result and execution trace.
    Picture languageRender the segments produced by the program.
    Loading runtime
    No valid SEG lines were produced by this run.
    0 segments rendered from program output.
    The SVG renders SEG lines produced by the program in the browser.
    Expected result

    The four-part composition prints twelve SEG lines and returns (segments 12). The depth-three right split prints forty-five SEG lines and returns (segments 45). Both SVGs are derived from the selected Lispex transcript.

    Trace focus

    Find each transform-painter call constructing a subframe before the base painter maps its segments. In right-split, follow the returned painter procedures through the recursive depth, then distinguish procedure composition from the later finite segment production at paint time.

    Try it yourself

    Change the program and compare the result.

    Define up-split by stacking the original painter below two smaller copies placed beside each other. Render depth three and predict the segment count before running it.

    Show hint

    Use below painter (beside smaller smaller). The segment-count recurrence is the same as right-split because one current copy and two smaller copies are produced at each positive depth.

    Complete this lesson

    0 of 20 lessons complete in this chapter0%