File: transparency.rb

package info (click to toggle)
ruby-prawn 1.0.0~rc1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,248 kB
  • sloc: ruby: 17,499; sh: 44; makefile: 17
file content (37 lines) | stat: -rw-r--r-- 1,027 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# encoding: utf-8
#
# Although the name of the method is <code>transparency</code>, what we are
# actually setting is the opacity for fill and stroke. So 0 means completely
# transparent and 1.0 means completely opaque
#
# You may call it providing one or two values. The first value sets fill opacity
# and the second value sets stroke opacity. If the second value is omitted fill
# and stroke will have the same opacity.
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::Example.generate(filename) do
  stroke_axis

  self.line_width = 5
  fill_color "ff0000"
  fill_rectangle [0, 100], 500, 100
  
  fill_color "000000"
  stroke_color "ffffff"
  
  base_x = 100
  [[0.5, 1], 0.5, [1, 0.5]].each do |args|
    
    transparent(*args) do
      fill_circle [base_x, 100], 50
      stroke_rectangle [base_x - 20, 100], 40, 80
    end
    
    base_x += 150
  end
  
  reset_drawing_settings
end