▼ |  | 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 | Signature and Unit
28 | Unsafe Libraries
29 | Platform Dependencies
| Bibliography
| Index

On this page:

get-line
get-stops

top← prev up next →

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

A linear gradient is used with a brush% to fill areas, such as the interior of a rectangle or ellipse, with smooth color transitions.

Colors transitions are based on a line, where colors are assigned to stop points along the line, and colors for in-between points are interpolated from the stop-point colors. The color of a point on the gradient’s line is propagated to all points in the drawing context that are touched by a line through the point and perpendicular to the gradient’s line.

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

Creates a linear gradient with a line from (x0, y0) to end point (x1, y1). The stops list assigns colors to stop points along the line, where 0.0 corresponds to (x0, y0), 1.0 corresponds to (x1, y2), and numbers in between correspond to points in between.

Examples:
> > (define no-pen (make-object pen% "BLACK" 1 'transparent))
> > (define brush-grad (new brush% [gradient
> (new linear-gradient%
> [x0 300] [y0 250] [x1 500] [y1 50]
> [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)))])]))
> > (define brush-grad2 (new brush% [gradient
> (make-object linear-gradient%
> 50 150 250 150
> (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 (lambda (dc x y)
> (send dc set-pen no-pen)
> (send dc set-brush brush-grad2)
> (send dc draw-ellipse 50 50 200 200)
> (send dc set-brush brush-grad)
> (send dc draw-rectangle 300 50 200 200)) 550 300)

> > method
> > (send a-linear-gradient get-line) |  | → |  |
> > real? |  | real? |  | real? |  | real?

Returns the gradient’s control line as x0, y0, x1, and y1.

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

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