計算機科学のブログ

Building Abstractions with Data - Hierarchical Data and the Closure Property - Example: A Picture Language - Transforming and combining painters - below operation

Structure and Interpretation of Computer Programs: JavaScript Edition(Harold Abelson(著)、Gerald Jay Sussman(著)、Julie Sussman(著)、The MIT Press)のChapter 2(Building Abstractions with Data)、2.2(Hierarchical Data and the Closure Property)、2.2.4(Example: A Picture Language)、Transforming and combining painters、Exercise 2.51の解答を求めてみる。

コード

function below1(painter1, painter2) {
    const split_point = make_vect(0, 0.5);
    const paint_bottom = transform_painter(
        painter1,
        make_vect(0, 0),
        make_vect(1, 0),
        split_point
    );
    const paint_top = transform_painter(
        painter2,
        split_point,
        make_vect(1, 0.5),
        make_vect(0, 1)
    );
    return frame => {
        paint_bottom(frame);
        paint_top(frame);
    };
}
function below2(painter1, painter2) {
    return rotate180(
        rotate270(
            beside(
                rotate270(painter1),
                rotate270(painter2)
            )));
}