(define Point% (class object% (super-new) (init-field x y) (public get-x get-y normalize translate) (define (get-x) x) (define (get-y) y) (define (normalize) (let* ([x x] [y y] [scale (sqrt (+ (* x x) (* y y)))]) (new Point% [x (/ x scale)] [y (/ y scale)]))) (define (translate dx dy) (new Point% [x (+ x dx)] [y (+ y dy)])))) (define Polygon% (class object% (super-new) (define vertices (vector)) (public add-vertex translate) (define (add-vertex v) (set! vertices (list->vector (append (vector->list vertices) (list v))))) (define (translate dx dy) (let* ([vs vertices] [size (vector-length vs)]) (let loop ([i 0]) (when (< i size) (vector-set! vs i (send (vector-ref vs i) translate dx dy)) (loop (+ i 1)))))))) (define (complex-picture) (send* (new Polygon%) (add-vertex (new Point% [x 0] [y 0])) (add-vertex (new Point% [x 5] [y 0])) (add-vertex (new Point% [x 0] [y 5])) (translate 5 5))) (define (simple-picture) (send (new Point% [x 1.0] [y 1.0]) normalize))