PasteRack.org
Paste # 75063
2022-06-16 14:48:57

Fork as a new paste.

Paste viewed 906 times.


Embed:

Вопрос

  1. #lang racket
  2. (require 2htdp/image)
  3.  
  4. (define R 100)
  5.  
  6. (define (ring-color x)
  7.   [case x
  8.     ['b 'blue]
  9.     ['r 'red]
  10.     ['g 'green]
  11.     ['y 'yellow]
  12.     ])
  13. (define (draw-ring xs)
  14.   (let ([r (/ (* 2 R) (length xs))]
  15.         [step (/ 360 (length xs))])
  16.  
  17.   (foldr (λ (x s)
  18.            (rotate step (if (not x) s
  19.                           (overlay/offset
  20.                            (circle r 'outline (ring-color x))
  21.                            0 R
  22.                            s))))
  23.          (circle R 'outline 'black)
  24.          xs)))
  25.  
  26. (define (draw-game-telega commands rings)
  27.     (foldl
  28.      (λ (x y)
  29.        (if (not x) y
  30.            (case (car x)
  31.              [':draw (draw-ring (hash-ref rings (second x)))]
  32.              [':to-right  (overlay/offset
  33.                            (draw-ring  (hash-ref rings (third x)))
  34.                            (second x) 0
  35.                            y)])))
  36.  
  37.      (square R 0 'black)
  38.      commands))
  39.  
  40. (draw-game-telega (list (list ':draw 'circle1) (list ':to-right R 'circle2))
  41.                    (make-hash
  42.                (list
  43.                 (cons 'circle1 '(b b b g y y y y y y y y y y y b b b b g b b b))
  44.                 (cons 'circle2 '(b b b g b b b b b b b b b b b b b b b g b b b)))))

=>

image