#lang scheme/gui ;; draw.ss ;; Lee Spector, lspector@hampshire.edu, 20091004 ;; Simple code for drawing shapes in a separate window in DrScheme. ;; ;; User functions: ;; (make-window) -- creates the window ;; (clear) -- clears the drawing ;; (ellipse x y width height r g b a) -- draw ellipse; r g & b are 0-255, a is 0.0-1.0 ;; (rectangle x y width height r g b a) -- draw ellipse; r g & b are 0-255, a is 0.0-1.0 (define width 500) (define height 500) (define frame (new frame% (label "Drawing Window") (width width) (height height))) (define bm (make-object bitmap% width height)) (define canvas (new canvas% [parent frame] [paint-callback (lambda (canvas dc) (send dc draw-bitmap bm 0 0))])) (define dc (make-object bitmap-dc% bm)) (send dc set-pen (make-object pen% "BLACK" 1 'transparent)) ;; No pen (send dc set-smoothing 'smoothed) (define make-window (lambda () (send frame show #t))) (define ellipse (lambda (x y width height r g b a) (send dc set-brush (make-object brush% (make-object color% r g b) 'solid)) (send dc set-alpha a) (send dc draw-ellipse x y width height))) (define rectangle (lambda (x y width height r g b a) (send dc set-brush (make-object brush% (make-object color% r g b) 'opaque)) (send dc set-alpha a) (send dc draw-rectangle x y width height))) (define clear (lambda () (rectangle 0 0 width height 255 255 255 1.0))) (define test (lambda () (clear) (rectangle 20 30 300 210 255 0 120 0.5) (ellipse 120 100 135 265 43 154 0 0.5) (make-window))) (test)