Module: Prawn::Graphics
- Includes:
- BlendMode, CapStyle, Color, Dash, JoinStyle, Patterns, Transformation, Transparency
- Included in:
- Document
- Defined in:
- lib/prawn/graphics.rb,
lib/prawn/graphics/dash.rb,
lib/prawn/graphics/color.rb,
lib/prawn/graphics/patterns.rb,
lib/prawn/graphics/cap_style.rb,
lib/prawn/graphics/blend_mode.rb,
lib/prawn/graphics/join_style.rb,
lib/prawn/graphics/transparency.rb,
lib/prawn/graphics/transformation.rb
Overview
Implements the drawing facilities for Document. Use this to draw the most beautiful imaginable things.
Defined Under Namespace
Modules: BlendMode, CapStyle, Color, Dash, JoinStyle, Patterns, Transformation, Transparency
Stable API collapse
- KAPPA =
This constant is used to approximate a symmetrical arc using a cubic Bezier curve.
4.0 * ((Math.sqrt(2) - 1.0) / 3.0)
Stable API collapse
-
#blend_mode(blend_mode = :Normal) { ... } ⇒ void
included
from BlendMode
Set blend mode.
-
#cap_style(style) ⇒ void
#cap_style ⇒ Symbol
(also: #cap_style=)
included
from CapStyle
Sets the cap style for stroked lines and curves.
-
#circle(center, radius) ⇒ void
Draws a circle of radius
radius
with the centre-point atpoint
as a complete subpath. -
#close_and_stroke { ... } ⇒ void
Closes and strokes the current path.
-
#close_path ⇒ Object
Closes the current path.
-
#curve(origin, dest, options = {}) ⇒ void
Draws a Bezier curve between two points, bounded by two additional points.
-
#curve_to(dest, options = {}) ⇒ void
Draws a Bezier curve from the current drawing position to the specified point, bounded by two additional points.
-
#dash ⇒ Hash{:dash => Number, Array<Number>, :space => Number, nil, :phase => Number}
#dash(length, options = {}) ⇒ void
(also: #dash=)
included
from Dash
Get or set stroke dash pattern.
-
#dashed? ⇒ Boolean
included
from Dash
Returns
true
when stroke is dashed,false
otherwise. -
#ellipse(point, radius1, radius2 = radius1) ⇒ void
Draws an ellipse of
x
radiusradius1
andy
radiusradius2
with the centre-point atpoint
as a complete subpath. -
#fill(options = {}) { ... } ⇒ void
Closes and fills the current path.
-
#fill_and_stroke(options = {}) { ... } ⇒ void
Closes, fills, and strokes the current path.
-
#fill_and_stroke_circle(center, radius) ⇒ void
Draws, strokes, and fills a circle of radius
radius
with the centre-point atpoint
. -
#fill_and_stroke_ellipse(point, radius1, radius2 = radius1) ⇒ void
Draws, strokes, and fills an ellipse of x radius
r1
and y radiusr2
with the centre-point atpoint
. -
#fill_and_stroke_polygon(*points) ⇒ void
Draws, strokes, and fills a polygon from the specified points.
-
#fill_and_stroke_rectangle(point, width, height) ⇒ void
Draws, fills, and strokes a rectangle given
point
,width
, andheight
. -
#fill_and_stroke_rounded_rectangle(point, width, height, radius) ⇒ void
Draws, fills, and strokes a rounded rectangle given
point
,width
, andheight
andradius
for the rounded corner. -
#fill_circle(center, radius) ⇒ void
Draws and fills a circle of radius
radius
with the centre-point atpoint
. -
#fill_color ⇒ String, Array<Number>
#fill_color(color) ⇒ void
(also: #fill_color=)
included
from Color
Sets or returns the fill color.
-
#fill_ellipse(point, radius1, radius2 = radius1) ⇒ void
Draws and fills an ellipse of x radius
r1
and y radiusr2
with the centre-point atpoint
. -
#fill_gradient(from, to, color1, color2, apply_margin_options: false) ⇒ void
#fill_gradient(from, r1, to, r2, color1, color2, apply_margin_options: false) ⇒ void
#fill_gradient(from: , to: , r1: nil, r2: nil, stops: , apply_margin_options: true) ⇒ void
included
from Patterns
Sets the fill gradient.
-
#fill_polygon(*points) ⇒ void
Draws and fills a polygon from the specified points.
-
#fill_rectangle(point, width, height) ⇒ void
Draws and fills a rectangle given
point
,width
, andheight
. -
#fill_rounded_polygon(radius, *points) ⇒ void
Draws and fills a rounded polygon from specified points, using
radius
to define Bezier curves. -
#fill_rounded_rectangle(point, width, height, radius) ⇒ void
Draws and fills a rounded rectangle given
point
,width
andheight
, andradius
for the rounded corner. -
#horizontal_line(x1, x2, options = {}) ⇒ void
Draws a horizontal line from
x1
tox2
at the current Document#y position, or the position specified by the:at
option. -
#horizontal_rule ⇒ void
Draws a horizontal line from the left border to the right border of the bounding box at the current Document#y position.
-
#join_style ⇒ :miter, ...
#join_style(style) ⇒ void
(also: #join_style=)
included
from JoinStyle
Get or set the join style for stroked lines and curves.
-
#line(point1, point2) ⇒ void
#line(x1, y1, x2, y2) ⇒ void
Draws a line from one point to another.
-
#line_to(point) ⇒ void
#line_to(x, y) ⇒ void
Draws a line from the current drawing position to the specified point.
-
#line_width ⇒ Number
#line_width(width) ⇒ void
When called without an argument, returns the current line thickness.
-
#line_width=(width) ⇒ void
Sets line thickness to the
width
specified. -
#move_to(point) ⇒ void
#move_to(x, y) ⇒ void
Moves the drawing position to a given point.
-
#polygon(*points) ⇒ void
Draws a polygon from the specified points.
-
#rectangle(point, width, height) ⇒ void
Draws a rectangle given
point
,width and
height`. -
#rotate(angle, options = {}) { ... } ⇒ void
included
from Transformation
Rotate the user space.
-
#rounded_polygon(radius, *points) ⇒ void
Draws a rounded polygon from specified points using the radius to define bezier curves.
-
#rounded_rectangle(point, width, height, radius) ⇒ void
Draws a rounded rectangle given
point
,width
,height
, andradius
for the rounded corner. -
#rounded_vertex(radius, *points) ⇒ void
Creates a rounded vertex for a line segment used for building a rounded polygon requires a radius to define bezier curve and three points.
-
#scale(factor, options = {}) { ... } ⇒ void
included
from Transformation
Scale the user space.
-
#stroke { ... } ⇒ void
Strokes the current path.
-
#stroke_axis(options = {}) ⇒ void
Draws and strokes X and Y axes rulers beginning at the current bounding box origin (or at a custom location).
-
#stroke_bounds ⇒ void
Draws and strokes a rectangle represented by the current bounding box.
-
#stroke_color ⇒ String, Array<Number>
#stroke_color(color) ⇒ void
(also: #stroke_color=)
included
from Color
Sets or returns the line stroking color.
-
#stroke_curve(origin, dest, options = {}) ⇒ void
Strokes a Bezier curve between two points, bounded by two additional points.
-
#stroke_ellipse(point, radius1, radius2 = radius1) ⇒ void
Draws and strokes an ellipse of x radius
r1
and y radiusr2
with the centre-point atpoint
. -
#fill_gradient(from, to, color1, color2, apply_margin_options: false) ⇒ void
#fill_gradient(from, r1, to, r2, color1, color2, apply_margin_options: false) ⇒ void
#fill_gradient(from: , to: , r1: nil, r2: nil, stops: , apply_margin_options: true) ⇒ void
included
from Patterns
Sets the stroke gradient.
-
#stroke_horizontal_line(x1, x2, options = {}) ⇒ void
Strokes a horizontal line from
x1
tox2
at the current y position, or the position specified by the :at option. -
#stroke_horizontal_rule ⇒ void
Strokes a horizontal line from the left border to the right border of the bounding box at the current y position.
-
#line(point1, point2) ⇒ void
#line(x1, y1, x2, y2) ⇒ void
Strokes a line from one point to another.
-
#stroke_polygon(*points) ⇒ Object
Draws and strokes a polygon from the specified points.
-
#stroke_rectangle(point, width, height) ⇒ void
Draws and strokes a rectangle given
point
,width
, andheight
. -
#stroke_rounded_polygon(radius, *points) ⇒ void
Draws and strokes a rounded polygon from specified points, using
radius
to define Bezier curves. -
#stroke_rounded_rectangle(point, width, height, radius) ⇒ void
Draws and strokes a rounded rectangle given
point
,width
andheight
, andradius
for the rounded corner. -
#stroke_vertical_line(y1, y2, params) ⇒ void
Strokes a vertical line at the x coordinate given by
:at
fromy1
toy2
. -
#transformation_matrix(*matrix) { ... } ⇒ void
included
from Transformation
Transform the user space (see notes for rotate regarding graphics state) Generally, one would use the Transformation#rotate, Transformation#scale, and Transformation#translate convenience methods instead of calling transformation_matrix directly.
-
#translate(x, y) { ... } ⇒ void
included
from Transformation
Translate the user space.
-
#transparent(opacity, stroke_opacity = opacity) { ... } ⇒ void
included
from Transparency
Set opacity.
-
#undash ⇒ void
included
from Dash
Stops dashing, restoring solid stroked lines and curves.
-
#vertical_line(y1, y2, params) ⇒ void
Draws a vertical line at the x coordinate given by
:at
fromy1
toy2
.
Instance Method Details
#blend_mode(blend_mode = :Normal) { ... } ⇒ void Originally defined in module BlendMode
This method returns an undefined value.
Set blend mode. If a block is passed blend mode is restored afterwards.
Passing an array of blend modes is allowed. PDF viewers should blend layers based on the first recognized blend mode.
Valid blend modes since PDF 1.4 include :Normal
, :Multiply
, :Screen
,
:Overlay
, :Darken
, :Lighten
, :ColorDodge
, :ColorBurn
,
:HardLight
, :SoftLight
, :Difference
, :Exclusion
, :Hue
,
:Saturation
, :Color
, and :Luminosity
.
#cap_style(style) ⇒ void #cap_style ⇒ Symbol Also known as: cap_style= Originally defined in module CapStyle
Sets the cap style for stroked lines and curves.
#circle(center, radius) ⇒ void
This method returns an undefined value.
Draws a circle of radius radius
with the centre-point at
point
as a complete subpath. The drawing point will be moved to
the centre-point upon completion of the drawing the circle.
Source Code
261 | def circle(center, radius) |
262 | ellipse(center, radius, radius) |
263 | end
|
#close_and_stroke { ... } ⇒ void
This method returns an undefined value.
Closes and strokes the current path. If a block is provided, yields to the block before closing the path. See Color for color details.
Source Code
389 | def close_and_stroke |
390 | yield if block_given? |
391 | renderer.add_content('s') |
392 | end
|
#close_path ⇒ Object
Closes the current path.
Source Code
510 | def close_path |
511 | renderer.add_content('h') |
512 | end
|
#curve(origin, dest, options = {}) ⇒ void
This method returns an undefined value.
Draws a Bezier curve between two points, bounded by two additional points
Source Code
242 | def curve(origin, dest, options = {}) |
243 | move_to(*origin) |
244 | curve_to(dest, options) |
245 | end
|
#curve_to(dest, options = {}) ⇒ void
This method returns an undefined value.
Draws a Bezier curve from the current drawing position to the specified point, bounded by two additional points.
Source Code
85 | def curve_to(dest, options = {}) |
86 | options[:bounds] || raise( |
87 | Prawn::Errors::InvalidGraphicsPath, |
88 | 'Bounding points for bezier curve must be specified as :bounds => [[x1,y1],[x2,y2]]', |
89 | )
|
90 | |
91 | curve_points = PDF::Core.real_params( |
92 | (options[:bounds] << dest).flat_map { |e| map_to_absolute(e) }, |
93 | )
|
94 | |
95 | renderer.add_content("#{curve_points} c") |
96 | end
|
#dash ⇒ Hash{:dash => Number, Array<Number>, :space => Number, nil, :phase => Number} #dash(length, options = {}) ⇒ void Also known as: dash= Originally defined in module Dash
Get or set stroke dash pattern.
#dashed? ⇒ Boolean Originally defined in module Dash
Returns true
when stroke is dashed, false
otherwise.
#ellipse(point, radius1, radius2 = radius1) ⇒ void
This method returns an undefined value.
Draws an ellipse of x
radius radius1
and y
radius radius2
with the
centre-point at point
as a complete subpath. The drawing point will be
moved to the centre-point upon completion of the drawing the ellipse.
Source Code
276 | def ellipse(point, radius1, radius2 = radius1) |
277 | x, y = point |
278 | l1 = radius1 * KAPPA |
279 | l2 = radius2 * KAPPA |
280 | |
281 | move_to(x + radius1, y) |
282 | |
283 | # Upper right hand corner
|
284 | curve_to( |
285 | [x, y + radius2], |
286 | bounds: [[x + radius1, y + l2], [x + l1, y + radius2]], |
287 | )
|
288 | |
289 | # Upper left hand corner
|
290 | curve_to( |
291 | [x - radius1, y], |
292 | bounds: [[x - l1, y + radius2], [x - radius1, y + l2]], |
293 | )
|
294 | |
295 | # Lower left hand corner
|
296 | curve_to( |
297 | [x, y - radius2], |
298 | bounds: [[x - radius1, y - l2], [x - l1, y - radius2]], |
299 | )
|
300 | |
301 | # Lower right hand corner
|
302 | curve_to( |
303 | [x + radius1, y], |
304 | bounds: [[x + l1, y - radius2], [x + radius1, y - l2]], |
305 | )
|
306 | |
307 | move_to(x, y) |
308 | end
|
#fill(options = {}) { ... } ⇒ void
This method returns an undefined value.
Closes and fills the current path. See Color for color details.
If the option fill_rule: :even_odd
is specified, Prawn will use the
even-odd rule to fill the path. Otherwise, the nonzero winding number rule
will be used. See the PDF reference, “Graphics -> Path Construction and
Painting -> Clipping Path Operators” for details on the difference.
Source Code
485 | def fill(options = {}) |
486 | yield if block_given? |
487 | renderer.add_content(options[:fill_rule] == :even_odd ? 'f*' : 'f') |
488 | end
|
#fill_and_stroke(options = {}) { ... } ⇒ void
This method returns an undefined value.
Closes, fills, and strokes the current path. If a block is provided, yields to the block before closing the path. See Color for color details.
If the option fill_rule: :even_odd
is specified, Prawn will use the
even-odd rule to fill the path. Otherwise, the nonzero winding number rule
will be used. See the PDF reference, “Graphics -> Path Construction and
Painting -> Clipping Path Operators” for details on the difference.
Source Code
503 | def fill_and_stroke(options = {}) |
504 | yield if block_given? |
505 | renderer.add_content(options[:fill_rule] == :even_odd ? 'b*' : 'b') |
506 | end
|
#fill_and_stroke_circle(center, radius) ⇒ void
This method returns an undefined value.
Draws, strokes, and fills a circle of radius radius
with the
centre-point at point
.
Source Code
#fill_and_stroke_ellipse(point, radius1, radius2 = radius1) ⇒ void
This method returns an undefined value.
Draws, strokes, and fills an ellipse of x radius r1
and y radius r2
with the centre-point at point
.
Source Code
#fill_and_stroke_polygon(*points) ⇒ void
This method returns an undefined value.
Draws, strokes, and fills a polygon from the specified points.
Source Code
#fill_and_stroke_rectangle(point, width, height) ⇒ void
This method returns an undefined value.
Draws, fills, and strokes a rectangle given point
, width
, and
height
. The rectangle is bounded by its upper-left corner.
Source Code
#fill_and_stroke_rounded_rectangle(point, width, height, radius) ⇒ void
This method returns an undefined value.
Draws, fills, and strokes a rounded rectangle given point
, width
,
and height
and radius
for the rounded corner. The rectangle is
bounded by its upper-left corner.
Source Code
#fill_circle(center, radius) ⇒ void
This method returns an undefined value.
Draws and fills a circle of radius radius
with the centre-point at
point
.
Source Code
#fill_color ⇒ String, Array<Number> #fill_color(color) ⇒ void Also known as: fill_color= Originally defined in module Color
Sets or returns the fill color.
#fill_ellipse(point, radius1, radius2 = radius1) ⇒ void
This method returns an undefined value.
Draws and fills an ellipse of x radius r1
and y radius r2
with the
centre-point at point
.
Source Code
#fill_gradient(from, to, color1, color2, apply_margin_options: false) ⇒ void #fill_gradient(from, r1, to, r2, color1, color2, apply_margin_options: false) ⇒ void #fill_gradient(from: , to: , r1: nil, r2: nil, stops: , apply_margin_options: true) ⇒ void Originally defined in module Patterns
Sets the fill gradient.
#fill_polygon(*points) ⇒ void
This method returns an undefined value.
Draws and fills a polygon from the specified points.
Source Code
#fill_rectangle(point, width, height) ⇒ void
This method returns an undefined value.
Draws and fills a rectangle given point
, width
, and height
. The
rectangle is bounded by its upper-left corner.
Source Code
#fill_rounded_polygon(radius, *points) ⇒ void
This method returns an undefined value.
Draws and fills a rounded polygon from specified points, using radius
to define Bezier curves.
Source Code
#fill_rounded_rectangle(point, width, height, radius) ⇒ void
This method returns an undefined value.
Draws and fills a rounded rectangle given point
, width
and height
,
and radius
for the rounded corner. The rectangle is bounded by its
upper-left corner.
Source Code
#horizontal_line(x1, x2, options = {}) ⇒ void
This method returns an undefined value.
Draws a horizontal line from x1
to x2
at the current Document#y
position, or the position specified by the :at
option.
Source Code
202 | def horizontal_line(x1, x2, options = {}) |
203 | y1 = options[:at] || (y - bounds.absolute_bottom) |
204 | |
205 | line(x1, y1, x2, y1) |
206 | end
|
#horizontal_rule ⇒ void
This method returns an undefined value.
Draws a horizontal line from the left border to the right border of the bounding box at the current Document#y position.
Source Code
212 | def horizontal_rule |
213 | horizontal_line(bounds.left, bounds.right) |
214 | end
|
#join_style ⇒ :miter, ... #join_style(style) ⇒ void Also known as: join_style= Originally defined in module JoinStyle
Get or set the join style for stroked lines and curves.
#line(point1, point2) ⇒ void #line(x1, y1, x2, y2) ⇒ void
Draws a line from one point to another. Points may be specified as tuples or flattened argument list.
Source Code
185 | def line(*points) |
186 | x0, y0, x1, y1 = points.flatten |
187 | move_to(x0, y0) |
188 | line_to(x1, y1) |
189 | end
|
#line_to(point) ⇒ void #line_to(x, y) ⇒ void
Draws a line from the current drawing position to the specified point. The destination may be described as a tuple or a flattened list:
Source Code
70 | def line_to(*point) |
71 | xy = PDF::Core.real_params(map_to_absolute(point)) |
72 | renderer.add_content("#{xy} l") |
73 | end
|
#line_width ⇒ Number #line_width(width) ⇒ void
When called without an argument, returns the current line thickness. When called with an argument, sets the line thickness to the specified value (in PDF points).
Source Code
160 | def line_width(width = nil) |
161 | if width |
162 | self.line_width = width |
163 | else
|
164 | current_line_width
|
165 | end
|
166 | end
|
#line_width=(width) ⇒ void
This method returns an undefined value.
Sets line thickness to the width
specified.
Source Code
141 | def line_width=(width) |
142 | self.current_line_width = width |
143 | write_line_width
|
144 | end
|
#move_to(point) ⇒ void #move_to(x, y) ⇒ void
Moves the drawing position to a given point. The point can be specified as a tuple or a flattened argument list.
Source Code
51 | def move_to(*point) |
52 | xy = PDF::Core.real_params(map_to_absolute(point)) |
53 | renderer.add_content("#{xy} m") |
54 | end
|
#polygon(*points) ⇒ void
This method returns an undefined value.
Draws a polygon from the specified points.
Source Code
317 | def polygon(*points) |
318 | move_to(points[0]) |
319 | (points[1..] << points[0]).each do |point| |
320 | line_to(*point) |
321 | end
|
322 | # close the path
|
323 | renderer.add_content('h') |
324 | end
|
#rectangle(point, width, height) ⇒ void
This method returns an undefined value.
Draws a rectangle given point
, width and
height`. The rectangle is
bounded by its upper-left corner.
Source Code
108 | def rectangle(point, width, height) |
109 | x, y = map_to_absolute(point) |
110 | box = PDF::Core.real_params([x, y - height, width, height]) |
111 | |
112 | renderer.add_content("#{box} re") |
113 | end
|
#rotate(angle, options = {}) { ... } ⇒ void Originally defined in module Transformation
This method returns an undefined value.
Rotate the user space. If a block is not provided, then you must save and restore the graphics state yourself.
#rounded_polygon(radius, *points) ⇒ void
This method returns an undefined value.
Draws a rounded polygon from specified points using the radius to define bezier curves.
Source Code
338 | def rounded_polygon(radius, *points) |
339 | move_to(point_on_line(radius, points[1], points[0])) |
340 | sides = points.size |
341 | points << points[0] << points[1] |
342 | sides.times do |i| |
343 | rounded_vertex(radius, points[i], points[i + 1], points[i + 2]) |
344 | end
|
345 | # close the path
|
346 | renderer.add_content('h') |
347 | end
|
#rounded_rectangle(point, width, height, radius) ⇒ void
This method returns an undefined value.
Draws a rounded rectangle given point
, width
, height
, and radius
for the rounded corner. The rectangle is bounded by its upper-left corner.
Source Code
126 | def rounded_rectangle(point, width, height, radius) |
127 | x, y = point |
128 | rounded_polygon( |
129 | radius, point, [x + width, y], [x + width, y - height], [x, y - height], |
130 | )
|
131 | end
|
#rounded_vertex(radius, *points) ⇒ void
This method returns an undefined value.
Creates a rounded vertex for a line segment used for building a rounded polygon requires a radius to define bezier curve and three points. The first two points define the line segment and the third point helps define the curve for the vertex.
Source Code
357 | def rounded_vertex(radius, *points) |
358 | radial_point1 = point_on_line(radius, points[0], points[1]) |
359 | bezier_point1 = point_on_line( |
360 | (radius - (radius * KAPPA)), |
361 | points[0], |
362 | points[1], |
363 | )
|
364 | radial_point2 = point_on_line(radius, points[2], points[1]) |
365 | bezier_point2 = point_on_line( |
366 | (radius - (radius * KAPPA)), |
367 | points[2], |
368 | points[1], |
369 | )
|
370 | line_to(radial_point1) |
371 | curve_to(radial_point2, bounds: [bezier_point1, bezier_point2]) |
372 | end
|
#scale(factor, options = {}) { ... } ⇒ void Originally defined in module Transformation
This method returns an undefined value.
Scale the user space. If a block is not provided, then you must save and restore the graphics state yourself.
#stroke { ... } ⇒ void
This method returns an undefined value.
Strokes the current path. If a block is provided, yields to the block before closing the path. See Color for color details.
Source Code
379 | def stroke |
380 | yield if block_given? |
381 | renderer.add_content('S') |
382 | end
|
#stroke_axis(options = {}) ⇒ void
This method returns an undefined value.
Draws and strokes X and Y axes rulers beginning at the current bounding box origin (or at a custom location).
Source Code
418 | def stroke_axis(options = {}) |
419 | options = { |
420 | at: [0, 0], |
421 | height: bounds.height - (options[:at] || [0, 0])[1], |
422 | width: bounds.width - (options[:at] || [0, 0])[0], |
423 | step_length: 100, |
424 | negative_axes_length: 20, |
425 | color: '000000', |
426 | }.merge(options) |
427 | |
428 | Prawn.verify_options( |
429 | %i[at width height step_length negative_axes_length color], |
430 | options, |
431 | )
|
432 | |
433 | save_graphics_state do |
434 | fill_color(options[:color]) |
435 | stroke_color(options[:color]) |
436 | |
437 | dash(1, space: 4) |
438 | stroke_horizontal_line( |
439 | options[:at][0] - options[:negative_axes_length], |
440 | options[:at][0] + options[:width], |
441 | at: options[:at][1], |
442 | )
|
443 | stroke_vertical_line( |
444 | options[:at][1] - options[:negative_axes_length], |
445 | options[:at][1] + options[:height], |
446 | at: options[:at][0], |
447 | )
|
448 | undash
|
449 | |
450 | fill_circle(options[:at], 1) |
451 | |
452 | (options[:step_length]..options[:width]) |
453 | .step(options[:step_length]) do |point| |
454 | fill_circle([options[:at][0] + point, options[:at][1]], 1) |
455 | draw_text( |
456 | point, |
457 | at: [options[:at][0] + point - 5, options[:at][1] - 10], |
458 | size: 7, |
459 | )
|
460 | end
|
461 | |
462 | (options[:step_length]..options[:height]) |
463 | .step(options[:step_length]) do |point| |
464 | fill_circle([options[:at][0], options[:at][1] + point], 1) |
465 | draw_text( |
466 | point, |
467 | at: [options[:at][0] - 17, options[:at][1] + point - 2], |
468 | size: 7, |
469 | )
|
470 | end
|
471 | end
|
472 | end
|
#stroke_bounds ⇒ void
This method returns an undefined value.
Draws and strokes a rectangle represented by the current bounding box.
Source Code
397 | def stroke_bounds |
398 | stroke_rectangle(bounds.top_left, bounds.width, bounds.height) |
399 | end
|
#stroke_color ⇒ String, Array<Number> #stroke_color(color) ⇒ void Also known as: stroke_color= Originally defined in module Color
Sets or returns the line stroking color.
#stroke_curve(origin, dest, options = {}) ⇒ void
This method returns an undefined value.
Strokes a Bezier curve between two points, bounded by two additional points.
Source Code
#stroke_ellipse(point, radius1, radius2 = radius1) ⇒ void
This method returns an undefined value.
Draws and strokes an ellipse of x radius r1
and y radius r2
with the
centre-point at point
.
Source Code
#fill_gradient(from, to, color1, color2, apply_margin_options: false) ⇒ void #fill_gradient(from, r1, to, r2, color1, color2, apply_margin_options: false) ⇒ void #fill_gradient(from: , to: , r1: nil, r2: nil, stops: , apply_margin_options: true) ⇒ void Originally defined in module Patterns
Sets the stroke gradient.
#stroke_horizontal_line(x1, x2, options = {}) ⇒ void
This method returns an undefined value.
Strokes a horizontal line from x1
to x2
at the current y position,
or the position specified by the :at option.
Source Code
#stroke_horizontal_rule ⇒ void
This method returns an undefined value.
Strokes a horizontal line from the left border to the right border of the bounding box at the current y position.
Source Code
#line(point1, point2) ⇒ void #line(x1, y1, x2, y2) ⇒ void
Strokes a line from one point to another. Points may be specified as tuples or flattened argument list.
Source Code
#stroke_polygon(*points) ⇒ Object
Draws and strokes a polygon from the specified points.
@param points [Array<Array(Number, Number)>] @return [void]
Source Code
#stroke_rectangle(point, width, height) ⇒ void
This method returns an undefined value.
Draws and strokes a rectangle given point
, width
, and height
. The
rectangle is bounded by its upper-left corner.
Source Code
#stroke_rounded_polygon(radius, *points) ⇒ void
This method returns an undefined value.
Draws and strokes a rounded polygon from specified points, using
radius
to define Bezier curves.
Source Code
#stroke_rounded_rectangle(point, width, height, radius) ⇒ void
This method returns an undefined value.
Draws and strokes a rounded rectangle given point
, width
and
height
, and radius
for the rounded corner. The rectangle is bounded
by its upper-left corner.
Source Code
#stroke_vertical_line(y1, y2, params) ⇒ void
This method returns an undefined value.
Strokes a vertical line at the x coordinate given by :at
from y1
to
y2
.
Source Code
#transformation_matrix(*matrix) { ... } ⇒ void Originally defined in module Transformation
This method returns an undefined value.
Transform the user space (see notes for rotate regarding graphics state) Generally, one would use the #rotate, #scale, and #translate convenience methods instead of calling transformation_matrix directly
#translate(x, y) { ... } ⇒ void Originally defined in module Transformation
This method returns an undefined value.
Translate the user space. If a block is not provided, then you must save and restore the graphics state yourself.
#transparent(opacity, stroke_opacity = opacity) { ... } ⇒ void Originally defined in module Transparency
This method returns an undefined value.
Set opacity.
#undash ⇒ void Originally defined in module Dash
This method returns an undefined value.
Stops dashing, restoring solid stroked lines and curves.
#vertical_line(y1, y2, params) ⇒ void
This method returns an undefined value.
Draws a vertical line at the x coordinate given by :at
from y1
to
y2
.
Source Code
227 | def vertical_line(y1, y2, params) |
228 | line(params[:at], y1, params[:at], y2) |
229 | end
|