mercredi 22 février 2017

Drawing Spirograph designs

I am trying to draw spirograph designs (http://ift.tt/1cTOuLV) in Racket. I could manage following code but it is not working:

#lang racket

(require 2htdp/image
         2htdp/universe) 

(define img (rectangle 500 500 "solid" "white"))

(let* ((R 300)   ; outer circle radius
       (r 100)   ; inner circle radius
       (c 30)    ; distance of pen-tip from center of inner circle

       (l (/ c r))
       (k (/ r R))
       (imgfn
        (λ (t)
          (set! img (overlay/xy
                     img
                     (* R(+ (* (- 1 k) (cos (modulo t 360)))
                            (* l k (cos (/(* (- 1 k)
                                             (modulo t 360))
                                          k)))))
                     (* R(- (* (- 1 k) (sin (modulo t 360)))
                            (* l k (sin (/(* (- 1 k)
                                             (modulo t 360))
                                          k)))))
                     (circle 2 "solid" "blue")))
          img)))
  (animate imgfn)) 

Following diagram shows the distances that would affect the design:

enter image description here

Above code shows small circles for points but they do not draw a line, even if I have tried to reuse previous image. Moreover, the points are moving very fast while I would like the speed to be slowed down somewhat. Only after this we can see if it is following correct path or not.

Any help/suggestions will be appreciated.

Aucun commentaire:

Enregistrer un commentaire