<div dir="ltr">Is the problem that you need to use (more) absolute coordinates in the coordinate arguments to linear-gradient% (either that or set the origin of the dc, in the case that you wanted to create the brush only once)?<div>
<br></div><div>Robby</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 11, 2014 at 10:49 AM, Jens Axel Søgaard <span dir="ltr"><<a href="mailto:jensaxel@soegaard.net" target="_blank">jensaxel@soegaard.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The intent of hc-append is that (hc-append p1 p2) draws p1 and p2<br>
beside each other.<br>
<br>
The question is whether (hc-append p p) should draw to identical picts?<br>
<br>
When I use a non-solid brush I get the two ps are drawn differently.<br>
In (hc-append p1 p2) I was expecting a transformation (translation) on<br>
the brush.<br>
<br>
As a demonstration I offer the following program (a bit long, but<br>
hopefully clear.<br>
<br>
See a syntax-highligthed version here: <a href="http://pasterack.org/pastes/7953" target="_blank">http://pasterack.org/pastes/7953</a><br>
The DrRacket output is here: <a href="http://imgur.com/5BRiY0Z" target="_blank">http://imgur.com/5BRiY0Z</a><br>
<br>
/Jens Axel<br>
<br>
<br>
#lang racket<br>
(require pict)<br>
<br>
; debug : value pict -> pict<br>
; return a pict, that when drawn prints the<br>
; brush and drawing context transformation<br>
(define (debug who pict)<br>
(dc (lambda (dc x y)<br>
(define b (send dc get-brush))<br>
(define bt (send b get-transformation))<br>
(define dct (send dc get-transformation))<br>
(displayln (list who 'x x 'y y 'brush: bt 'dc: dct))<br>
(draw-pict pict dc x y))<br>
(pict-width pict) (pict-height pict)))<br>
<br>
(define r 20) ; use same box side for the entire example<br>
<br>
; a black filled rectangle<br>
(define (rect) (filled-rectangle r r))<br>
<br>
;;; Examine whether hc-append does any transformation.<br>
"Expected Image: Two squares a black and a red"<br>
"Expected Transformation: Same for A and B. Some difference for C."<br>
(debug 'A<br>
(hc-append (debug 'B (rect))<br>
(debug 'C (colorize (rect) "red" ))))<br>
<br>
;;; --------------------------------------------------------------<br>
(require racket/draw)<br>
<br>
; colors<br>
(define (color: name) (send the-color-database find-color name))<br>
(define red (color: "red"))<br>
(define green (color: "green"))<br>
(define blue (color: "blue"))<br>
<br>
; square-path : real real real real -> path%<br>
; make square with side r and upper left corner (x,y)<br>
(define (square-path x y w h)<br>
(define p (new dc-path%))<br>
(send p move-to x y)<br>
(send p line-to x (+ y h))<br>
(send p line-to (+ x w)(+ y h))<br>
(send p line-to (+ x w)(+ y 0))<br>
(send p line-to (+ x 0)(+ y 0))<br>
p)<br>
<br>
; fill : pict -> pict<br>
; draw a path around pict using current pen and brush<br>
(define (fill pict)<br>
(define w (pict-width pict))<br>
(define h (pict-height pict))<br>
(dc (lambda (dc x y)<br>
(draw-pict pict dc x y)<br>
(send dc draw-path (square-path x y w h)))<br>
w h))<br>
<br>
; shady : pict -> pict<br>
; Draws pict with a brush given by a linear, horizontal<br>
; gradient from (0,0) to (0,2r). The colors are red->green->blue.<br>
(define (shady pict)<br>
(dc (lambda (dc x y)<br>
; get old brush<br>
(define b (send dc get-brush))<br>
; make new brush, only change gradient<br>
(define new-brush<br>
(new brush%<br>
[color (send b get-color)]<br>
[style (send b get-style)]<br>
[stipple (send b get-stipple)]<br>
[gradient (new linear-gradient%<br>
[x0 0] [y0 0] [x1 (* 2 r)] [y1 0] ;<br>
horizontal gradient<br>
[stops (list (list 0 red) ; (0,0)<br>
to ( r,0) red->green<br>
(list 1/2 green) ; (r,0)<br>
to (2r,0) green->blue<br>
(list 1 blue))])]<br>
[transformation (send b get-transformation)]))<br>
; use new brush to draw the pict<br>
(send dc set-brush new-brush)<br>
(draw-pict pict dc x y)<br>
; restore old brush<br>
(send dc set-brush b))<br>
(pict-width pict) (pict-height pict)))<br>
<br>
(define-syntax (echo stx) (syntax-case stx () [(_ expr) #'(values 'expr expr)]))<br>
<br>
(newline) (newline)<br>
"Expected: A (black) rectangle"<br>
(echo (rect))<br>
"Expected: A rectangle filled with nothing (default brush is empty)"<br>
(echo (fill (rect)))<br>
"Expected: A rectangle filled with linear gradient (red to green)"<br>
(echo (shady (fill (rect))))<br>
"Expected: Two red-to-green rectangles"<br>
(echo (hc-append (shady (fill (rect))) (shady (fill (rect)))))<br>
"Expected: Two red-to-green rectangles"<br>
(echo (let () (define p (shady (fill (rect)))) (hc-append p p)))<br>
<br>
<br>
<br>
--<br>
Jens Axel Søgaard<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div><br></div>