22 radial-gradient%

▼ |  | The Racket Drawing Toolkit

1 | Overview
2 | bitmap%
3 | bitmap-dc%
4 | brush%
5 | brush-list%
6 | color%
7 | color-database<%>
8 | dc<%>
9 | dc-path%
10 | font%
11 | font-list%
12 | font-name-directory<%>
13 | gl-config%
14 | gl-context<%>
15 | linear-gradient%
16 | pdf-dc%
17 | pen%
18 | pen-list%
19 | point%
20 | post-script-dc%
21 | ps-setup%
22 | radial-gradient%
23 | record-dc%
24 | region%
25 | svg-dc%
26 | Drawing Functions
27 | Drawing Contracts
28 | Signature and Unit
29 | Unsafe Libraries
30 | Drawing Conveniences
31 | Platform Dependencies
| Bibliography
| Index

On this page:

new
get-circles
get-stops

top ← prev up next →

class radial-gradient% : class?
superclass: object%

A radial gradient is used with a brush% to fill areas with smooth color transitions. Color transitions are based on two circles and the sequence of circles that “morph” from the starting circle to the ending circle. Normally, one of the two circles defining a gradient is nested within the other; in that case, points within the inner circle get the same color as the inner circle’s edge, while points outside the outer circle get the same color as the outer circle’s edge.

> > constructor
> > (new radial-gradient% |
> > |  | [x0 x0] |
> > |  | [y0 y0] |
> > |  | [r0 r0] |
> > |  | [x1 x1] |
> > |  | [y1 y1] |
> > |  | [r1 r1] |
> > |  | [stops stops]) |
> → (is-a?/c radial-gradient%)
> x0 : real?
> y0 : real?
> r0 : real?
> x1 : real?
> y1 : real?
> r1 : real?
> stops : (listof (list/c (real-in 0 1) (is-a?/c color%)))

Creates a radial gradient with the starting circle as the one with radius r0 centered at (x0, y0) and the ending circle as the one with radius r1 centered at (x1, y1). The stops list assigns colors to circles, where 0.0 corresponds to the starting circle, 1.0 corresponds to the ending circle, and numbers in between correspond to circles in between.

The order of elements within stops and duplicate points are treated in the same way for as linear-gradient%.

Examples:

> > (define ellipse-brush
> (new brush%
> [gradient
> (new radial-gradient%
> [x0 100] [y0 100] [r0 0]
> [x1 100] [y1 100] [r1 100]
> [stops
> (list (list 0 (make-object color% 0 0 255))
> (list 0.5 (make-object color% 0 255 0))
> (list 1 (make-object color% 255 0 0)))])]))
> > (define rectangle-brush
> (new brush%
> [gradient
> (new radial-gradient%
> [x0 100] [y0 100] [r0 10]
> [x1 100] [y1 100] [r1 100]
> [stops
> (list (list 0 (make-object color% 255 0 0))
> (list 0.5 (make-object color% 0 255 0))
> (list 1 (make-object color% 0 0 255)))])]))
> > (dc
> (λ (dc dx dy)
> (define old-pen (send dc get-pen))
> (define old-brush (send dc get-brush))
> (define-values (ox oy) (send dc get-origin))
> (send dc set-pen "black" 1 'transparent)
> (send dc set-brush ellipse-brush)
> (send dc set-origin (+ ox dx 50) (+ oy dy 50))
> (send dc draw-ellipse 0 0 200 200)
> (send dc set-origin (+ ox dx 300) (+ oy dy 50))
> (send dc set-brush rectangle-brush)
> (send dc draw-rectangle 0 0 200 200)
> (send dc set-pen old-pen)
> (send dc set-brush old-brush)
> (send dc set-origin ox oy))
> 550 300)

> method (send a-radial-gradient get-circles)
> | → |  |
> real? |  | real? |  | real? |  | real? |  | real? |  | real?

Returns the gradient’s boundary circles as x0, y0, r0, x1, y1, and r1.

> method (send a-radial-gradient get-stops)
> → (listof (list/c (real-in 0 1) (is-a?/c color%)))

Returns the gradient’s list of color stops.
top ← prev up next →