Module: Prawn::Graphics

Defined in:
lib/prawn_shapes/arc.rb,
lib/prawn_shapes/star.rb

Instance Method Summary collapse

Instance Method Details

#arc_around(center, options) ⇒ Object

options must include :radius, :start_angle, and :end_angle startAngle and endAngle are in degrees

0 degrees is directly right and 90 degrees is straight up arc will be drawn counterclockwise from startAngle to endAngle



79
80
81
# File 'lib/prawn_shapes/arc.rb', line 79

def arc_around(center, options)
  open_curve(arc_vertices(center, options))
end

#closed_curve(vertices) ⇒ Object

vertices is an array of hashes containing :vertex and optional :handle1 and :handle2 elements



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/prawn_shapes/arc.rb', line 101

def closed_curve(vertices)
  return if vertices.empty?
  vertices = vertices.dup
  origin = vertices.shift
  move_to(origin[:point])
  previous_handle2 = origin[:handle2]
  vertices.each do |vertex|
    curve_to(vertex[:point],
             :bounds => [previous_handle2 || vertex[:point],
                         vertex[:handle1] || vertex[:point]])
    previous_handle2 = vertex[:handle2]
  end
  curve_to(origin[:point],
           :bounds => [previous_handle2 || origin[:point],
                       origin[:handle1] || origin[:point]])
end

#half_circle(center, options) ⇒ Object

options must include :radius and :side side is either :left or :right see pie_slice for explanation of optional :stroke_both_sides option



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/prawn_shapes/arc.rb', line 8

def half_circle(center, options)
  case options[:side]
  when :left
    start_angle = 90
    end_angle = 270
  when :right
    start_angle = 270
    end_angle = 90
  end
  pie_slice(center,
            :radius => options[:radius],
            :start_angle => start_angle,
            :end_angle => end_angle,
            :stroke_both_sides => options[:stroke_both_sides])
end

#half_star(point, options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/prawn_shapes/star.rb', line 8

def half_star(point, options)
  points = star_points(point, options)
  case options[:side]
  when :left
    points.slice!(1..4)
  when :right
    points.slice!(6..9)
  end
  polygon(*points)
end

#open_curve(vertices) ⇒ Object

vertices is an array of hashes containing :vertex and optional :handle1 and :handle2 elements



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/prawn_shapes/arc.rb', line 85

def open_curve(vertices)
  return if vertices.empty?
  vertices = vertices.dup
  origin = vertices.shift
  move_to(origin[:point])
  previous_handle2 = origin[:handle2]
  vertices.each do |vertex|
    curve_to(vertex[:point],
             :bounds => [previous_handle2 || vertex[:point],
                         vertex[:handle1] || vertex[:point]])
    previous_handle2 = vertex[:handle2]
  end
end

#pie_slice(center, options) ⇒ Object

options must include :radius, :start_angle, and :end_angle startAngle and endAngle are in degrees if an optional :stroke_both_sides option is true, then both sides of the slice will be included for stroking. the default is to just stroke one side since this will tend to be used to build up an entire circle, and if both sides were stroked, then we would get double-stroked lines where two pie slices shared a (not usually noticeable, but would be if transparency were used)

0 degrees is directly right and 90 degrees is straight up arc will be drawn counterclockwise from startAngle to endAngle



63
64
65
66
67
68
69
70
71
# File 'lib/prawn_shapes/arc.rb', line 63

def pie_slice(center, options)
  vertices = arc_vertices(center, options)
  vertices.unshift(:point => center)
  if options[:stroke_both_sides]
    closed_curve(vertices)
  else
    open_curve(vertices)
  end
end

#quarter_circle(center, options) ⇒ Object

options must include :radius and :quadrant quadrant is 1, 2, 3, or 4 see pie_slice for explanation of optional :stroke_both_sides option



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/prawn_shapes/arc.rb', line 29

def quarter_circle(center, options)
  case options[:quadrant]
  when 1
    start_angle = 0
    end_angle = 90
  when 2
    start_angle = 90
    end_angle = 180
  when 3
    start_angle = 180
    end_angle = 270
  when 4
    start_angle = 270
    end_angle = 360
  end
  pie_slice(center,
            :radius => options[:radius],
            :start_angle => start_angle,
            :end_angle => end_angle,
            :stroke_both_sides => options[:stroke_both_sides])
end

#star(point, options) ⇒ Object



3
4
5
6
# File 'lib/prawn_shapes/star.rb', line 3

def star(point, options)
  x, y = point
  polygon(*star_points(point, options))
end