PasteRack.org
Paste # 7953
2014-02-11 11:33:14

Fork as a new paste.

Paste viewed 916 times.


Embed:

  1. #lang racket
  2. (require pict)
  3.  
  4. ; debug : value pict -> pict
  5. ;  return a pict, that when drawn prints the
  6. ;  brush and drawing context transformation
  7. (define (debug who pict)
  8.   (dc (lambda (dc x y)
  9.         (define b   (send dc get-brush))
  10.         (define bt  (send b  get-transformation))
  11.         (define dct (send dc get-transformation))
  12.         (displayln (list who 'x x 'y y 'brush: bt 'dc: dct))
  13.         (draw-pict pict dc x y))
  14.       (pict-width pict) (pict-height pict)))
  15.  
  16. (define r 20) ; use same box side for the entire example
  17.  
  18. ; a black filled rectangle
  19. (define (rect) (filled-rectangle r r))
  20.  
  21. ;;; Examine whether hc-append does any transformation.
  22. "Expected Image:          Two squares a black and a red"
  23. "Expected Transformation: Same for A and B. Some difference for C."
  24. (debug 'A
  25.        (hc-append (debug 'B (rect))
  26.                   (debug 'C (colorize (rect) "red" ))))
  27.  
  28. ;;; --------------------------------------------------------------
  29. (require racket/draw)
  30.  
  31. ; colors
  32. (define (color: name) (send the-color-database find-color name))
  33. (define red   (color: "red"))
  34. (define green (color: "green"))
  35. (define blue  (color: "blue"))
  36.  
  37. ; square-path : real real real real -> path%
  38. ;     make square with side r and upper left corner (x,y)
  39. (define (square-path x y w h)
  40.   (define p (new dc-path%))
  41.   (send p move-to    x      y)
  42.   (send p line-to    x   (+ y h))
  43.   (send p line-to (+ x w)(+ y h))
  44.   (send p line-to (+ x w)(+ y 0))
  45.   (send p line-to (+ x 0)(+ y 0))
  46.   p)
  47.  
  48. ; fill : pict -> pict
  49. ;   draw a path around pict using current pen and brush
  50. (define (fill pict)
  51.   (define w (pict-width pict))
  52.   (define h (pict-height pict))
  53.   (dc (lambda (dc x y)
  54.         (draw-pict pict dc x y)
  55.         (send dc draw-path (square-path x y w h)))
  56.       w h))
  57.  
  58. ; shady : pict -> pict
  59. ;   Draws pict with a brush given by a linear, horizontal
  60. ;   gradient from (0,0) to (0,2r). The colors are red->green->blue.
  61. (define (shady pict)
  62.   (dc (lambda (dc x y)
  63.         ; get old brush
  64.         (define b (send dc get-brush))
  65.         ; make new brush, only change gradient
  66.         (define new-brush
  67.           (new brush%
  68.                [color          (send b get-color)]
  69.                [style          (send b get-style)]
  70.                [stipple        (send b get-stipple)]
  71.                [gradient       (new linear-gradient%
  72.                                 [x0 0] [y0 0] [x1 (* 2 r)] [y1 0] ; horizontal gradient
  73.                                 [stops (list (list 0   red)   ; (0,0) to ( r,0) red->green
  74.                                              (list 1/2 green) ; (r,0) to (2r,0) green->blue
  75.                                              (list 1   blue))])]
  76.                [transformation (send b get-transformation)]))
  77.         ; use new brush to draw the pict
  78.         (send dc set-brush new-brush)
  79.         (draw-pict pict dc x y)
  80.         ; restore old brush
  81.         (send dc set-brush b))
  82.       (pict-width pict) (pict-height pict)))
  83.  
  84. (define-syntax (echo stx) (syntax-case stx () [(_ expr) #'(values 'expr expr)]))
  85.  
  86. (newline) (newline)
  87. "Expected: A (black) rectangle"
  88. (echo (rect))
  89. "Expected: A rectangle filled with nothing (default brush is empty)"
  90. (echo (fill (rect)))
  91. "Expected: A rectangle filled with linear gradient (red to green)"
  92. (echo (shady (fill (rect))))
  93. "Expected: Two red-to-green rectangles"
  94. (echo (hc-append (shady (fill (rect))) (shady (fill (rect)))))
  95. "Expected: Two red-to-green rectangles"
  96. (echo (let () (define p (shady (fill (rect)))) (hc-append p p)))
  97.  

=>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
(A x 0 y 0 brush: #f dc: #(#(1.0 0.0 0.0 1.0 0.0 0.0) 0.0 0.0 1.0 1.0 0.0))
(B x 0 y 0 brush: #f dc: #(#(1.0 0.0 0.0 1.0 0.0 0.0) 0.0 0.0 1.0 1.0 0.0))
(C x 20 y 0 brush: #f dc: #(#(1.0 0.0 0.0 1.0 0.0 0.0) 0.0 0.0 1.0 1.0 0.0))
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title></title><link rel="stylesheet" type="text/css" href="scribble.css" title="default" /><link rel="stylesheet" type="text/css" href="racket.css" title="default" /><link rel="stylesheet" type="text/css" href="scribble-style.css" title="default" /><script type="text/javascript" src="scribble-common.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="scribble-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;">&bull;</td><td></td><td><a href="" class="tocviewselflink" data-pltdoc="x">???</a></td></tr></table></div></div></div><div class="tocsub"><table class="tocsublist" cellspacing="0"><tr><td><span class="tocsublinknumber"></span><a href="#%28part._%28gentag._0%29%29" class="tocsubseclink" data-pltdoc="x">???</a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="versionbox"><span class="versionNoNav">5.90.0.9</span></div><blockquote class="SCodeFlow"><table cellspacing="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">void</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">debug</span><span class="hspace">&nbsp;</span><span class="RktSym">who</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">get-brush</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">bt</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">get-transformation</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">dct</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">get-transformation</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">displayln</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">list</span><span class="hspace">&nbsp;</span><span class="RktSym">who</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">x</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">y</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">brush:</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">bt</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">dc:</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">dct</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">draw-pict</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">pict-width</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">pict-height</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">r</span><span class="hspace">&nbsp;</span><span class="RktVal">20</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">filled-rectangle</span><span class="hspace">&nbsp;</span><span class="RktSym">r</span><span class="hspace">&nbsp;</span><span class="RktSym">r</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktVal">"Expected Image:</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">Two squares a black and a red"</span></td></tr><tr><td><p><span class="RktRes">"Expected Image:</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktRes"></span><span class="hspace">&nbsp;&nbsp;</span><span class="RktRes"></span><span class="hspace">&nbsp;&nbsp;</span><span class="RktRes"></span><span class="hspace">&nbsp;&nbsp;</span><span class="RktRes"></span><span class="hspace">&nbsp;&nbsp;</span><span class="RktRes">Two squares a black and a red"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktVal">"Expected Transformation: Same for A and B. Some difference for C."</span></td></tr><tr><td><p><span class="RktRes">"Expected Transformation: Same for A and B. Some difference for C."</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">debug</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">A</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">hc-append</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">debug</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">B</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">debug</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">C</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">colorize</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">"red"</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><p><img src="pict.png" alt="image" width="40" height="20" /></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">color:</span><span class="hspace">&nbsp;</span><span class="RktSym">name</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">the-color-database</span><span class="hspace">&nbsp;</span><span class="RktSym">find-color</span><span class="hspace">&nbsp;</span><span class="RktSym">name</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">red</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">color:</span><span class="hspace">&nbsp;</span><span class="RktVal">"red"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">green</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">color:</span><span class="hspace">&nbsp;</span><span class="RktVal">"green"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">blue</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">color:</span><span class="hspace">&nbsp;</span><span class="RktVal">"blue"</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">square-path</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="hspace">&nbsp;</span><span class="RktSym">h</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">new</span><span class="hspace">&nbsp;</span><span class="RktSym">dc-path%</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="hspace">&nbsp;</span><span class="RktSym">move-to</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="hspace">&nbsp;</span><span class="RktSym">line-to</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">h</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="hspace">&nbsp;</span><span class="RktSym">line-to</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">h</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="hspace">&nbsp;</span><span class="RktSym">line-to</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="hspace">&nbsp;</span><span class="RktSym">line-to</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fill</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">pict-width</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">h</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">pict-height</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">draw-pict</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">draw-path</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">square-path</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="hspace">&nbsp;</span><span class="RktSym">h</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="hspace">&nbsp;</span><span class="RktSym">h</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">shady</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">get-brush</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">new-brush</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">new</span><span class="hspace">&nbsp;</span><span class="RktSym">brush%</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">color</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">get-color</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">style</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">get-style</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">stipple</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">get-stipple</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">gradient</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">new</span><span class="hspace">&nbsp;</span><span class="RktSym">linear-gradient%</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">*</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktSym">r</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y1</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">stops</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">list</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">list</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktSym">red</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">list</span><span class="hspace">&nbsp;</span><span class="RktVal">1/2</span><span class="hspace">&nbsp;</span><span class="RktSym">green</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">list</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">blue</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">transformation</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">get-transformation</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">set-brush</span><span class="hspace">&nbsp;</span><span class="RktSym">new-brush</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">draw-pict</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">send</span><span class="hspace">&nbsp;</span><span class="RktSym">dc</span><span class="hspace">&nbsp;</span><span class="RktSym">set-brush</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">pict-width</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">pict-height</span><span class="hspace">&nbsp;</span><span class="RktSym">pict</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">newline</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktOut"></span></p></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">newline</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktOut"></span></p></td></tr><tr><td><table cellspacing="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktVal">"Expected: A (black) rectangle"</span></td></tr><tr><td><p><span class="RktRes">"Expected: A (black) rectangle"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">echo</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td><p><span class="RktRes">'(rect)</span></p></td></tr><tr><td><p><img src="pict_2.png" alt="image" width="20" height="20" /></p></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktVal">"Expected: A rectangle filled with nothing (default brush is empty)"</span></td></tr><tr><td><p><span class="RktRes">"Expected: A rectangle filled with nothing (default brush is empty)"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">echo</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fill</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td><p><span class="RktRes">'(fill (rect))</span></p></td></tr><tr><td><p><img src="pict_3.png" alt="image" width="20" height="20" /></p></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktVal">"Expected: A rectangle filled with linear gradient (red to green)"</span></td></tr><tr><td><p><span class="RktRes">"Expected: A rectangle filled with linear gradient (red to green)"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">echo</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">shady</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fill</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td><p><span class="RktRes">'(shady (fill (rect)))</span></p></td></tr><tr><td><p><img src="pict_4.png" alt="image" width="20" height="20" /></p></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktVal">"Expected: Two red-to-green rectangles"</span></td></tr><tr><td><p><span class="RktRes">"Expected: Two red-to-green rectangles"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">echo</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">hc-append</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">shady</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fill</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">shady</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fill</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td><p><span class="RktRes">'(hc-append (shady (fill (rect))) (shady (fill (rect))))</span></p></td></tr><tr><td><p><img src="pict_5.png" alt="image" width="40" height="20" /></p></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktVal">"Expected: Two red-to-green rectangles"</span></td></tr><tr><td><p><span class="RktRes">"Expected: Two red-to-green rectangles"</span></p></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">echo</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">shady</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fill</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">rect</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">hc-append</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="hspace">&nbsp;</span><span class="RktSym">p</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0"><tr><td><p><span class="RktRes">'(let () (define p (shady (fill (rect)))) (hc-append p p))</span></p></td></tr><tr><td><p><img src="pict_6.png" alt="image" width="40" height="20" /></p></td></tr></table></td></tr></table></blockquote></div></div><div id="contextindicator">&nbsp;</div></body></html>