Sha256: f4f4bfe67b9a2042c605bf41405b8bb775081149036ae7df2c8c60184bfc6fb0

Contents?: true

Size: 1.06 KB

Versions: 136

Compression:

Stored size: 1.06 KB

Contents

module Cairo
  class Context
    module Blur
      def pseudo_blur(radius=3, &block)
        raise ArgumentError, "should specify block" if block.nil?
        pattern = push_group(Cairo::CONTENT_COLOR_ALPHA, false, &block)

        save do
          set_source(pattern)
          paint(0.5)
        end

        1.step(radius, 1) do |i|
          opacity = 0.075 - 0.005 * i
          next if opacity <= 0
          5.downto(1) do |ratio|
            r = i / ratio.to_f
            r_13 = r / 3.0
            r_23 = 2 * r_13
            [
             [-r, 0],
             [-r_23, r_23],
             [-r_23, r_13],
             [0, r],
             [r_13, r_23],
             [r_23, r_23],
             [r, 0],
             [r_23, -r_13],
             [r_23, -r_23],
             [0, -r],
             [-r_13, -r_23],
             [-r_23, -r_23],
            ].each do |x, y|
              save do
                translate(x, y)
                set_source(pattern)
                paint(opacity)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

136 entries across 128 versions & 2 rubygems

Version Path
cairo-1.17.13 lib/cairo/context/blur.rb
cairo-1.17.12 lib/cairo/context/blur.rb
cairo-1.17.11 lib/cairo/context/blur.rb
cairo-1.17.10 lib/cairo/context/blur.rb
cairo-1.17.9 lib/cairo/context/blur.rb
cairo-1.17.8 lib/cairo/context/blur.rb
cairo-1.17.7 lib/cairo/context/blur.rb
cairo-1.17.6 lib/cairo/context/blur.rb
cairo-1.17.5 lib/cairo/context/blur.rb
cairo-1.17.4 lib/cairo/context/blur.rb
cairo-1.16.6 lib/cairo/context/blur.rb
cairo-1.16.5 lib/cairo/context/blur.rb
cairo-1.16.4 lib/cairo/context/blur.rb
cairo-1.16.3 lib/cairo/context/blur.rb
cairo-1.16.2 lib/cairo/context/blur.rb
cairo-1.16.1-x86-mingw32 lib/cairo/context/blur.rb
cairo-1.16.1-x64-mingw32 lib/cairo/context/blur.rb
cairo-1.16.1 lib/cairo/context/blur.rb
cairo-1.16.0-x86-mingw32 lib/cairo/context/blur.rb
cairo-1.16.0-x64-mingw32 lib/cairo/context/blur.rb