<div dir="ltr">Yes, I think this is the right approach, too. <div><br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 24, 2014 at 3:40 PM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Probably something like this function belongs in `pict`:<br>
<br>
;; smoothed : pict -> pict<br>
;;  Produces a pict like `p`, but that always draws in<br>
;;  'smoothed mode<br>
(define (smoothed p)<br>
  (define draw-p (make-pict-drawer p))<br>
  (define p2<br>
<div class="">    (dc (lambda (dc x y)<br>
</div>          (define s (send dc get-smoothing))<br>
          (send dc set-smoothing 'smoothed)<br>
          (draw-p dc x y)<br>
          (send dc set-smoothing s))<br>
        (pict-width p)<br>
        (pict-height p)))<br>
  (make-pict (pict-draw p2)<br>
             (pict-width p)<br>
             (pict-height p)<br>
             (pict-ascent p)<br>
             (pict-descent p)<br>
             (list p)<br>
             #f<br>
             (pict-last p)))<br>
<div class="HOEnZb"><div class="h5"><br>
At Mon, 24 Mar 2014 21:00:37 +0100, Jens Axel Søgaard wrote:<br>
> Hi all,<br>
><br>
> DrRacket draws pict values in REPL. It seems DrRacket uses the<br>
> smoothing mode 'aligned.<br>
><br>
> Is there a way to change this to 'smooth ?<br>
><br>
> Below is a program that draws graphs of functions of a single variable<br>
> using Bezier curves.<br>
> It turns out that the Bezier curves doesn't fit together nicely when<br>
> the smoothing mode<br>
> 'aligned is used. On the bitmap version below this results in a<br>
> slightly jagged appearance.<br>
> If rendered to pdf, it becomes painfully obvious when you zoom.<br>
><br>
> If on the other 'smooth is used everything fits nicely together.<br>
><br>
> [Does 'aligned move all control points?]<br>
><br>
> The program below draws the graph of x^2 in two ways: The first use DrRacket to<br>
> convert a pict to bitmap without touching the smoothing mode, the second<br>
> explicitly set smoothing to 'smooth.<br>
><br>
> #lang racket<br>
> (require racket/draw pict)<br>
><br>
> (define (f x)     (* x x))<br>
> (define (df/dx x) (* 2 x))<br>
><br>
> (struct pt  (x y) #:transparent)              ; point<br>
> (struct vec (x y) #:transparent)              ; vector<br>
> (struct bez (p0 p1 p2 p3) #:transparent)      ; Bezier curve<br>
><br>
> (define (vec* k v) ; multiply vector v with constant k<br>
>   (vec (* k (vec-x v)) (* k (vec-y v))))<br>
><br>
> (define (pt+ p v)  ; add vector v to point p<br>
>   (pt (+ (pt-x p) (vec-x v)) (+ (pt-y p) (vec-y v))))<br>
><br>
><br>
> (define (draw-bezs dc bs) ; assumes the end and start points of each curve match<br>
>   (define p (new dc-path%))<br>
>   (match-define (list b0 b. ...) bs)<br>
>   (match-define (bez (pt x0 y0) (pt x1 y1) (pt x2 y2) (pt x3 y3)) b0)<br>
>   (send p move-to x0 y0)<br>
>   (send p curve-to x1 y1 x2 y2 x3 y3)<br>
>   (for ([b b.])<br>
>     (match-define (bez (pt x0 y0) (pt x1 y1) (pt x2 y2) (pt x3 y3)) b)<br>
>     (send p curve-to x1 y1 x2 y2 x3 y3))<br>
>   (send dc draw-path p))<br>
><br>
> (define (graph #:samples [n 200])<br>
>   (define-values (xmin xmax ymin ymax) (values -1 1 -1 1))<br>
>   (define ε 1.0e-10)<br>
>   (define (φ x) (pt x (f x)))      ; x -> (x,f(x))<br>
>   (define (τ x) (vec 1 (df/dx x))) ; vector along tangent<br>
>   (define Δx (/ (- xmax xmin) n))<br>
>   (define x0 xmin)<br>
>   (define (xi i) (+ x0 (* i Δx)))<br>
>   (define bs (for/list ([i (in-range 0 (+ n 1))])<br>
>                (define x0 (xi i))<br>
>                (define x3 (xi (+ i 1)))<br>
>                ; See page 7 of:<br>
>                ; <a href="http://www.math.ubc.ca/~cass/graphics/manual/pdf/ch6.pdf" target="_blank">http://www.math.ubc.ca/~cass/graphics/manual/pdf/ch6.pdf</a><br>
>                (bez (φ x0)<br>
>                     (pt+ (φ x0) (vec* (/ Δx  3) (τ x0)))<br>
>                     (pt+ (φ x3) (vec* (/ Δx -3) (τ x3)))<br>
>                     (φ x3))))<br>
>   ; return pict that draws the Bezier curves<br>
>   (dc (lambda (dc x y)<br>
>         (define-values (old-x0 old-y0)           (send dc get-origin))<br>
>         (define-values (old-scale-x old-scale-y) (send dc get-scale))<br>
>         (define old-pen    (send dc get-pen))<br>
>         (send dc set-origin 200 200)<br>
>         (send dc set-scale 200 -200)<br>
>         (send dc set-pen "black" 0 'solid)<br>
>         (draw-bezs dc bs)<br>
>         (send dc set-pen    old-pen)<br>
>         (send dc set-scale  old-scale-x old-scale-y)<br>
>         (send dc set-origin old-x0 old-y0))<br>
>       400 400))<br>
><br>
> (define bm (make-object bitmap% 400 400))<br>
> (define bm-dc (new bitmap-dc% [bitmap bm]))<br>
> (send bm-dc set-smoothing 'smoothed)<br>
><br>
> (define p (graph #:samples 100))<br>
> (draw-pict p bm-dc 0 0)<br>
><br>
> (list p bm)<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>
<br>
____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>