Advertisement
benjisimon

Logo

Jan 3rd, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.25 KB | None | 0 0
  1. #lang racket
  2.  
  3. ;;
  4. ;; Implement the most basic of logo functionality for:
  5. ;;   http://programmingpraxis.com/2012/01/03/turtle-graphics/
  6. ;;
  7.  
  8. (require racket/gui
  9.          racket/draw)
  10.  
  11. (struct pos (x y) #:prefab)
  12. (struct context (pos heading canvas) #:prefab #:mutable)
  13. (define *ctx* (context (pos 0 0) 0 #f))
  14.  
  15. (define no-pen (new pen% [style 'transparent]))
  16. (define black-pen (new pen% [color "black"] [width 2]))
  17.  
  18.  
  19. (define (penup)
  20.   (send (send (context-canvas *ctx*) get-dc) set-pen no-pen))
  21.  
  22. (define (pendown)
  23.   (send (send (context-dc *ctx*) get-dc) set-pen black-pen))
  24.  
  25. (define (setheading h)
  26.   (set-context-heading! *ctx* h))
  27.  
  28. (define (setpos x y)
  29.   (set-context-pos! *ctx* (pos x y)))
  30.  
  31. (define (clearscreen)
  32.   (unless (context-frame *ctx*)
  33.     (let* ([f (new frame% [label "Logo Output"])]
  34.            [c (new canvas% [parent f] [min-width 400] [min-height 500]
  35.                    [paint-callback (lambda (c dc)
  36.                                      
  37.                                      )])])
  38.       (set-context-canvas! *ctx*)
  39.       (send f show #t)))
  40.   (send (context-dc *ctx*) clear)
  41.   (penup)
  42.   (setheading 0)
  43.   (setpos (/ (send (context-frame *ctx*) get-width) 2)
  44.           (/ (send (context-frame *ctx*) get-height) 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement