Module: Prawn::Graphics::Patterns

Included in:
Defined in:

Defined Under Namespace

Classes: Gradient, GradientStop

Stable API collapse

Instance Method Details

#fill_gradient(*args, **kwargs) ⇒ Object

Sets the fill gradient. old arguments:

from, to, color1, color2
from, r1, to, r2, color1, color2

new arguments:

from: [x, y]
to: [x, y]
r1: radius
r2: radius
stops: [color, color, ...] or
       { position => color, position => color, ... }
apply_transformations: true


# draws a horizontal axial gradient that starts at red on the left
# and ends at blue on the right
fill_gradient from: [0, 0], to: [100, 0], stops: ['red', 'blue']

# draws a horizontal radial gradient that starts at red, is green
# 80% of the way through, and finishes blue
fill_gradient from: [0, 0], r1: 0, to: [100, 0], r2: 180,
  stops: { 0 => 'red', 0.8 => 'green', 1 => 'blue' }

from and to specify the axis of where the gradient should be painted.

r1 and r2, if specified, make a radial gradient with the starting circle of radius r1 centered at from and ending at a circle of radius r2 centered at to. If r1 is not specified, a axial gradient will be drawn.

stops is an array or hash of stops. Each stop is either just a string indicating the color, in which case the stops will be evenly distributed across the gradient, or a hash where the key is a position between 0 and 1 indicating what distance through the gradient the color should change, and the value is a color string.

Option apply_transformations, if set true, will transform the gradient's co-ordinate space so it matches the current co-ordinate space of the document. This option will be the default from Prawn v3, and is default true if you use the new arguments format. The default for the old arguments format, false, will mean if you (for example) scale your document by 2 and put a gradient inside, you will have to manually multiply your co-ordinates by 2 so the gradient is correctly positioned.

# File 'lib/prawn/graphics/patterns.rb', line 69

def fill_gradient(*args, **kwargs)
  set_gradient(:fill, *args, **kwargs)

#stroke_gradient(*args, **kwargs) ⇒ Object

Sets the stroke gradient. See fill_gradient for a description of the arguments to this method.

# File 'lib/prawn/graphics/patterns.rb', line 75

def stroke_gradient(*args, **kwargs)
  set_gradient(:stroke, *args, **kwargs)