递归方案的迭代:Racket博士

时间:2019-06-13 19:57:57

标签: racket

帮助,我编写了6次手臂旋转迭代,但是我想递归地编写此函数。有人有提示吗?

(: rotate-arm : Image Image Natural -> Image)

;; rotates the entire arm 5 times, returning the full star

(define (rotate-arm tile tile2 i)
  (local 
      {(define arm (draw-arm tile tile2 i))}
    (clear-pinhole
     (overlay/pinhole
       (put-pinhole 
         (center-x (draw-arm tile tile2 i)) 0 arm)
       (rotate (* i 60) (put-pinhole 
                          (center-x arm) 0 arm))
       (rotate 60 (put-pinhole 
                    (center-x arm) 0 arm))
       (rotate 120 (put-pinhole 
                    (center-x arm) 0 arm))
       (rotate 180 (put-pinhole 
                    (center-x arm) 0 arm))
       (rotate 240 (put-pinhole 
                    (center-x arm) 0 arm))
       (rotate 300 (put-pinhole 
                    (center-x arm) 0 arm))))))

是正确的,只是效率低下。

0 个答案:

没有答案