Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Turtle is just a list of (x, y, direction, color, tail-down)
- ;; I'm not Scheme expert, Common Lisp is superior
- (define (nth n l)
- (if (= n 0)
- (car l)
- (nth (- n 1) (cdr l))))
- (define (deg-to-rad degrees)
- (* degrees 0.0174532925))
- (define (draw-line x y x2 y2) ;; Define on own here
- '())
- (define (make-Turtle x y direction)
- `(,x ,y ,direction 'black #t))
- (define (get-x Turtle)
- (car Turtle))
- (define (get-y Turtle)
- (cadr Turtle))
- (define (get-direction Turtle)
- (caddr Turtle))
- (define (get-color Turtle)
- (cadddr Turtle))
- (define (get-tail-down Turtle)
- (nth 4 Turtle))
- (define (pos x y Turtle)
- `(,x
- ,y
- ,(get-direction Turtle)
- ,(get-color Turtle)
- ,(get-tail-down Turtle)))
- (define (rt angle Turtle)
- `(,(get-x Turtle)
- ,(get-y Turtle)
- ,(+ (get-direction Turtle) angle)
- ,(get-color Turtle)
- ,(get-tail-down Turtle)))
- (define (lt angle Turtle)
- `(,(get-x Turtle)
- ,(get-y Turtle)
- ,(- (get-direction Turtle) angle)
- ,(get-color Turtle)
- ,(get-tail-down Turtle)))
- (define (fd step Turtle)
- (let* ((rad-angle (deg-to-rad (get-direction Turtle)))
- (old-x (get-x Turtle))
- (old-y (get-y Turtle))
- (new-x (* (+ (get-x Turtle) (cos rad-angle)) step))
- (new-y (* (+ (get-y Turtle) (sin rad-angle)) step)))
- (if (get-tail-down Turtle)
- (draw-line old-x old-y new-x new-y))
- `(,new-x
- ,new-y
- ,(get-direction Turtle)
- ,(get-color Turtle)
- ,(get-tail-down Turtle))))
- (define (col color Turtle)
- `(,(get-x Turtle)
- ,(get-y Turtle)
- ,(get-direction Turtle)
- ,color
- ,(get-tail-down Turtle)))
- (define (pu Turtle)
- `(,(get-x Turtle)
- ,(get-y Turtle)
- ,(get-direction Turtle)
- ,(get-color Turtle)
- ,#f))
- (define (pd Turtle)
- `(,(get-x Turtle)
- ,(get-y Turtle)
- ,(get-direction Turtle)
- ,(get-color Turtle)
- ,#t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement