Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created March 6, 2013 03:03
Show Gist options
  • Select an option

  • Save dyoo/5096373 to your computer and use it in GitHub Desktop.

Select an option

Save dyoo/5096373 to your computer and use it in GitHub Desktop.
dc example
#lang racket
(require racket/draw)
;; draw-rectangle: dc -> void
(define (draw-rectangle dc)
(send dc set-brush "green" 'solid)
(send dc set-pen "blue" 1 'solid)
(send dc draw-rectangle 0 10 30 10)
(send dc set-pen "red" 3 'solid)
(send dc draw-line 0 0 30 30)
(send dc draw-line 0 30 30 0))
;; as-bitmap: -> bitmap
(define (as-bitmap)
(define bm (make-bitmap 30 30))
(define dc (send bm make-dc))
(draw-rectangle dc)
bm)
;; as-svg: -> bytes
(define (as-svg)
(define op (open-output-bytes))
(define dc (new svg-dc%
[width 30]
[height 30]
[output op]))
(send dc start-doc "test")
(send dc start-page)
(draw-rectangle dc)
(send dc end-page)
(send dc end-doc)
(get-output-bytes op))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment