Added plot-background-alpha and plot-foreground-alpha

This commit is contained in:
Neil Toronto 2011-10-06 11:26:13 -06:00
parent 8ae5b8c1f3
commit ce68c697fc
11 changed files with 47 additions and 8 deletions

View File

@ -126,7 +126,8 @@
(set-pen (plot-foreground) (plot-line-width) 'solid)
(set-brush (plot-background) 'solid)
(set-background (plot-background))
(set-alpha 1))
(set-background-alpha (plot-background-alpha))
(set-alpha (plot-foreground-alpha)))
;; -----------------------------------------------------------------------------------------------
;; Pen, brush, alpha parameters
@ -171,6 +172,12 @@
(define/public (set-background color)
(send dc set-background (color->color% (->brush-color color))))
(define background-alpha 1)
;; Sets the background opacity.
(define/public (set-background-alpha alpha)
(set! background-alpha alpha))
;; -----------------------------------------------------------------------------------------------
;; Text parameters
@ -237,7 +244,10 @@
;; Drawing primitives
(define/public (clear)
(send dc clear))
(define old-alpha (send dc get-alpha))
(send dc set-alpha background-alpha)
(send dc clear)
(send dc set-alpha old-alpha))
(define/public (draw-point v)
(match-define (vector x y) v)

View File

@ -27,6 +27,8 @@
(defparam plot-foreground color plot-color/c 0)
(defparam plot-background color plot-color/c 0)
(defparam plot-foreground-alpha alpha (real-in 0 1) 1)
(defparam plot-background-alpha alpha (real-in 0 1) 1)
(defparam plot-font-size size (real>=/c 0) 11)
(defparam plot-font-family family font-family/c 'roman)
(defparam plot-line-width width (real>=/c 0) 1)

View File

@ -185,6 +185,7 @@
(define (draw-borders)
(set-minor-pen)
(set-brush (plot-background) 'transparent)
(draw-rectangle (vector area-x-min area-y-min)
(vector area-x-max area-y-max)))

View File

@ -121,6 +121,8 @@
) pict?
(define foreground (plot-foreground))
(define background (plot-background))
(define foreground-alpha (plot-foreground-alpha))
(define background-alpha (plot-background-alpha))
(define font-size (plot-font-size))
(define font-family (plot-font-family))
(define line-width (plot-line-width))
@ -133,6 +135,8 @@
(dc (λ (dc x y)
(parameterize ([plot-foreground foreground]
[plot-background background]
[plot-foreground-alpha foreground-alpha]
[plot-background-alpha background-alpha]
[plot-font-size font-size]
[plot-font-family font-family]
[plot-line-width line-width]

View File

@ -143,6 +143,8 @@
) pict?
(define foreground (plot-foreground))
(define background (plot-background))
(define foreground-alpha (plot-foreground-alpha))
(define background-alpha (plot-background-alpha))
(define font-size (plot-font-size))
(define font-family (plot-font-family))
(define line-width (plot-line-width))
@ -161,6 +163,8 @@
(dc (λ (dc x y)
(parameterize ([plot-foreground foreground]
[plot-background background]
[plot-foreground-alpha foreground-alpha]
[plot-background-alpha background-alpha]
[plot-font-size font-size]
[plot-font-family font-family]
[plot-line-width line-width]

View File

@ -69,6 +69,8 @@ The @(racket freq) parameter controls the ``shakiness'' of the transform. At hig
@doc-apply[plot-foreground]
@doc-apply[plot-background]{The plot foreground and background color. That both are @(racket 0) by default is not a mistake: for foreground colors, @(racket 0) is interpreted as black; for background colors, @(racket 0) is interpreted as white. See @(racket plot-color/c) for details on integer-indexed colors.}
@doc-apply[plot-foreground-alpha]
@doc-apply[plot-background-alpha]{The opacity of the background and foreground colors.}
@doc-apply[plot-font-size]{The font size of the title, axis labels, tick labels, and other labels, in drawing units.}
@doc-apply[plot-font-family]{The font family used for the title and labels.}
@doc-apply[plot-line-width]{The width of axis lines and major tick lines. (Minor tick lines are half this width.)}

View File

@ -66,26 +66,25 @@ When creating a PostScript or PDF file, the parameters @(racket plot-ps-interact
(See @(racket post-script-dc%) and @(racket pdf-dc%).)
When @(racket kind) is @(racket 'auto), @(racket plot-file) tries to determine the kind of file to write from the file name extension.
Use @(racket plot-pict) to create plots in slideshows. For example,
Use @(racket plot-pict) to plot to a slideshow @(racket pict). For example,
@racketmod[slideshow
(require plot)
(plot-font-size (current-font-size))
(plot-width (current-para-width))
(plot-height 600)
(plot-background-alpha 1/2)
(slide
#:title "A 2D Parabola"
(plot-pict (function sqr -1 1 #:label "y = x^2")))]
creates a slide containing a 2D plot of a parabola.
Use @(racket plot-bitmap) to create a bitmap.
Use @(racket plot-bitmap) to create a @(racket bitmap%).
Use @(racket plot-frame) to create a frame regardless of the value of @(racket plot-new-window?). The frame is initially hidden.
Use @(racket plot-frame) to create a @(racket frame%) regardless of the value of @(racket plot-new-window?). The frame is initially hidden.
Use @(racket plot-snip) to create an image snip regardless of the value of @(racket plot-new-window?).
Use @(racket plot-snip) to create an @(racket image-snip%) regardless of the value of @(racket plot-new-window?).
}
@doc-apply[plot/dc]{

View File

@ -85,6 +85,9 @@ The @(racket #:lncolor) keyword argument now does nothing; change the renderer i
For example, if you have @(racket (plot (function sin -5 5) #:lncolor '(0 0 128))), change it to
@interaction[#:eval plot-eval (plot (function sin -5 5 #:color '(0 0 128)))]
Change @(racket #:az) in calls to @(racket plot3d) to @(racket #:angle), and @(racket #:alt) to @(racket #:altitude).
Alternatively, parameterize multiple plots by setting the @(racket plot3d-angle) and @(racket plot3d-altitude) parameters.
@section{Fixing Broken Calls to @(racket points)}

View File

@ -11,6 +11,12 @@
(plot empty #:x-min -1 #:x-max 1 #:y-min -1 #:y-max 1)
(parameterize ([plot-background "black"]
[plot-foreground "white"]
[plot-background-alpha 1/2]
[plot-foreground-alpha 1/2])
(plot (function sin -4 4 #:label "y = sin(x)")))
(parameterize ([plot-x-transform (hand-drawn-transform 200)]
[plot-y-transform (hand-drawn-transform 200)])
(plot (function sqr -1 1)))

View File

@ -8,6 +8,12 @@
(time
(plot3d empty #:x-min -1 #:x-max 1 #:y-min -1 #:y-max 1 #:z-min -1 #:z-max 1))
(parameterize ([plot-background "black"]
[plot-foreground "white"]
[plot-background-alpha 1/2]
[plot-foreground-alpha 1/2])
(plot3d (surface3d (λ (x y) (* (sin x) (sin y))) -2 2 -2 2 #:label "z = trig(x,y)")))
(time
(define x-ivls (bounds->intervals (linear-seq 2 8 10)))
(define y-ivls (bounds->intervals (linear-seq -5 5 10)))

View File

@ -20,6 +20,7 @@
(slide
#:title "A 2D Parabola"
(parameterize ([plot-background 1]
[plot-background-alpha 1/2]
[plot-foreground 1])
(plot-pict (function sqr -1 1 #:label "y = x^2")
#:legend-anchor 'center)))
@ -37,6 +38,7 @@
(slide
#:title "A 3D Parabola"
(parameterize ([plot-background 1]
[plot-background-alpha 1/2]
[plot-foreground 1])
(plot3d-pict (list (surface3d parabola2d -1 1 -1 1
#:label "z = x^2 + y^2" #:color 3)